<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 04:59:32 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[SERVER-42081] Map helpers for strict use</title>
                <link>https://jira.mongodb.org/browse/SERVER-42081</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;I recently ended up &lt;a href=&quot;https://github.com/mongodb/mongo/blob/master/src/mongo/executor/connection_pool.cpp#L64&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;creating translation unit-static functions&lt;/a&gt; for more strict access patterns with stdx::unordered_map/_set. I suspect that a set of helpers with invariants might be more useful to the codebase at large:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;getOrInvariant() which invariants that the key already exists (roughly equivalent to at()).&lt;/li&gt;
	&lt;li&gt;emplaceOrInvariant() which invariants that the key did not already exist.&lt;/li&gt;
	&lt;li&gt;eraseOrInvariant() which invariants that the key existed and will no longer.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;This set of operations allows a developer to confidently use a map or set to contain a unique set of initialized objects.&lt;/p&gt;</description>
                <environment></environment>
        <key id="834982">SERVER-42081</key>
            <summary>Map helpers for strict use</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="12300">Won&apos;t Do</resolution>
                                        <assignee username="billy.donahue@mongodb.com">Billy Donahue</assignee>
                                    <reporter username="ben.caimano@mongodb.com">Benjamin Caimano</reporter>
                        <labels>
                    </labels>
                <created>Wed, 3 Jul 2019 20:41:01 +0000</created>
                <updated>Tue, 10 Sep 2019 05:02:28 +0000</updated>
                            <resolved>Tue, 10 Sep 2019 05:02:28 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="2413894" author="billy.donahue" created="Tue, 10 Sep 2019 05:01:40 +0000"  >&lt;p&gt;My feeling on functions like this is that you&apos;re better off writing the code out where it&apos;s needed.&lt;/p&gt;

&lt;p&gt;I overhauled Google&apos;s util/gtl &quot;helpers&quot; collection and it was like this huge pile of fiddly little functions all with slightly different behaviors. In the end, C+&lt;ins&gt;11, particularly `unique_ptr`, `auto`, and `rvalue references`, left most of the helpers as being far more trouble than they were worth. They had caveats that caused a few bugs (like FindWithDefault&apos;s dangling reference on the `default` argument), and developers relied on them too much, and didn&apos;t develop their skills working with C&lt;/ins&gt;+ containers as well as they should have.&lt;/p&gt;

&lt;p&gt;There are issues here like:&lt;/p&gt;

&lt;p&gt;What should be the exact signature of getOrInvariant? Is the key a `const Map::key_type&amp;amp;`? That ignores heterogeneous lookup, or hinted find. Pretty soon they might want countOrInvariant, equalRangeOrInvariant....&lt;/p&gt;

&lt;p&gt;emplaceOrInvariant has more problems, the argument list is easier (M&amp;amp;, const_iterator, Args&amp;amp;&amp;amp;...). Does it take a hint? But then will we soon want emplaceHintOrInvariant(M&amp;amp;, K&amp;amp;, Args&amp;amp;&amp;amp;...), tryEmplaceOrInvariant(M&amp;amp;, const_iterator, Args&amp;amp;&amp;amp;...), insertOrInvariant(M&amp;amp;, const value_type&amp;amp;), and insertOrInvariant(M&amp;amp;, value_type&amp;amp;&amp;amp;) ?  What happens if an exception is thrown while emplacing? Is that allowed to propagate out or is Invariant the only possibility if the emplace doesn&apos;t succeed. It gets to be a mouthful.&lt;/p&gt;

&lt;p&gt;When I&apos;m reading code and encounter helper function, I have to think about the signature, return type, and possible caveats of the helper function. Whereas if I read straight container-manipulating code I just have to know the container API and a few idioms. In practice I think the manipulator functions are only saving about 2 or 3 lines of code, and you can&apos;t really be sure they were the only functions used to manipulate an arbitrary container. It will have back doors unless you encapsulate it and make the invariant enforcement part of the capsule, so then the capsule is the thing we&apos;d need to design, and IMO it&apos;s very hard to do it in a way that anticipates the diversity in user requirements.&lt;/p&gt;

&lt;p&gt;Like, what&apos;s so special about `invariant`? Why isn&apos;t the &quot;or&quot; action customizable to other things? Okay how do we specify those other actions? You start to get into this maze of twisty little passages.&lt;/p&gt;

&lt;p&gt;I don&apos;t want to be down on this idea, but I have seen a very similar collection of algorithms at Google, and worked on an assignment for several months on paring it down (some things had 50k+ callers) and getting rid of it, and I just don&apos;t think anyone who looked at the problems up close was really convinced that the convenience of those helpers was worthwhile post-C++11.&lt;/p&gt;

&lt;p&gt;When I have a special map that needs special restrictions, I like to make a little class or derived type containing that map, and have it expose only those operations I want to allow. But making it a public type in a util/ directory is tough because you can&apos;t really account for all the variations the users will want and perhaps even expect it to have. My feeling is that this ticket should probably be closed.&lt;/p&gt;</comment>
                            <comment id="2339102" author="ben.caimano" created="Tue, 23 Jul 2019 15:40:35 +0000"  >&lt;p&gt;Yeah, that would be fine by me. I&apos;ve already caught one runtime bug with these helpers in the last week.&lt;/p&gt;</comment>
                            <comment id="2337879" author="billy.donahue" created="Mon, 22 Jul 2019 23:11:40 +0000"  >&lt;p&gt;Maybe you need a facade type around the map to enforce this discipline for&lt;br/&gt;
you rather than a collection of functions?&lt;/p&gt;

&lt;p&gt;On Mon, Jul 22, 2019 at 2:42 PM Andrew Morrow (Jira) &amp;lt;jira@mongodb.org&amp;gt;&lt;/p&gt;
</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>3.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18555" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname># of Sprints</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>3.0</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Mon, 22 Jul 2019 23:11:40 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        4 years, 22 weeks, 1 day ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></customfieldvalue>


                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>billy.donahue@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            4 years, 22 weeks, 1 day ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>ben.caimano@mongodb.com</customfieldvalue>
            <customfieldvalue>billy.donahue@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hvan2f:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hv8fpb:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_23361" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Requested By</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="3114">Dev Tools 2019-09-09</customfieldvalue>
    <customfieldvalue id="3246">Dev Tools 2019-09-09</customfieldvalue>
    <customfieldvalue id="3280">Dev Tools 2019-09-23</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hva9br:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                    </customfields>
    </item>
</channel>
</rss>