{"id":110368,"date":"2024-10-14T07:00:00","date_gmt":"2024-10-14T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=110368"},"modified":"2024-10-14T12:54:41","modified_gmt":"2024-10-14T19:54:41","slug":"20241014-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20241014-00\/?p=110368","title":{"rendered":"On naming things: The tension between naming something for what it is, what it does, or how it is used"},"content":{"rendered":"<p>There is a tension in the problem of <a title=\"Naming things is hard (by David Karlton, Phil Karlton's son)\" href=\"https:\/\/www.karlton.org\/2017\/12\/naming-things-hard\/\"> naming things<\/a>: Do you name something for what it is? Do you name it for what it does? Or do you name it for how it is used?<\/p>\n<p>Previously, we saw <a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20240607-00\/?p=109865\"> <code>std::<wbr \/>type_identity<\/code><\/a>, which is named after what it is. One reaction was that the class should have been named something like <code>std::<wbr \/>non_<wbr \/>deduced<\/code>, which names it after how it is used: To prevent template type deduction.<\/p>\n<pre>template&lt;typename...Args&gt;\r\nvoid enqueue(\r\n    std::function&lt;void(std::<span style=\"border: solid 1px currentcolor;\">non_deduced_t<\/span>&lt;Args&gt;...)&gt; const&amp; work,\r\n    Args...args)\r\n{\r\n    enqueue([=] { work(args...); });\r\n}\r\n<\/pre>\n<p>We have the opposite problem with <a title=\"How can I explicitly specialize a templated C++ constructor?\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20241011-00\/?p=110365\"> <code>std::<wbr \/>in_<wbr \/>place<\/code><\/a>: The <code>in_place<\/code> types are named after how they are used, rather than what they are. They are tags that are used by some constructors of variant-like types to indicate what they should hold.<\/p>\n<ul>\n<li><code>in_place<\/code>: Hold the primary thing (as opposed to nothing, or the alternate thing)<\/li>\n<li><code>in_place_type&lt;T&gt;<\/code>: Hold the thing of type <code>T<\/code><\/li>\n<li><code>in_place_index&lt;I&gt;<\/code>: Hold the thing at index <code>I<\/code><\/li>\n<\/ul>\n<p>But <a title=\"How can I explicitly specialize a templated C++ constructor?\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20241011-00\/?p=110365\"> when we used it as a tag type in our example<\/a>, it was used not to indicate what the class itself should hold, but rather what the class should hold a reference to. Perhaps it could be named after what it is: <code>std::<wbr \/>type_tag&lt;T&gt;<\/code> and <code>std::<wbr \/>index_tag&lt;I&gt;<\/code>.<\/p>\n<p>Though what about <code>std::<wbr \/>in_place<\/code>? Maybe we leave that one alone?<\/p>\n<p>And then we have <a title=\"What's the point of std::monostate? You can't do anything with it!\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20240708-00\/?p=109959\"> <code>std::<wbr \/>monostate<\/code><\/a>, which is named after what it is, rather than how it is used. In other languages, this type goes by the name <code>unit<\/code>, which to me feels like a name chosen with category-theory-colored glasses. (Also, the name <code>unit<\/code> could be misinterpreted as having to do with <a href=\"https:\/\/wg21.link\/p1935r2\"> systems of measurement<\/a>.)<\/p>\n<p><b>Bonus chatter<\/b>: Note that none of the examples are named after what they do, because none of them do anything!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You are guaranteed to make someone upset.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-110368","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>You are guaranteed to make someone upset.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/110368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=110368"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/110368\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=110368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=110368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=110368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}