{"id":111415,"date":"2025-07-28T07:00:00","date_gmt":"2025-07-28T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=111415"},"modified":"2025-07-28T10:11:31","modified_gmt":"2025-07-28T17:11:31","slug":"20250728-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20250728-00\/?p=111415","title":{"rendered":"API design note: Don&#8217;t make up multiple names for the same thing"},"content":{"rendered":"<p>A recurring problem I encounter when reviewing API proposals is that teams tend not to be precise in their use of terminology. This casualness is inevitable when you work with a feature for a long time and develop notational shortcuts, but the people who are learning your API don&#8217;t have the same level of familiarity that you do, and shifting terminology tends to create confusion.<\/p>\n<p>For example, there was an API proposal that included two methods.<\/p>\n<pre>runtimeclass Widget\r\n{\r\n    void EnableFilter(WidgetFilter filter);\r\n    Boolean AreAnyFiltersApplied();\r\n}\r\n<\/pre>\n<p>The first method talks about &#8220;enabling&#8221; but the second talks about &#8220;applying&#8221;.<\/p>\n<p>For somebody encountering this API for the first time, the existence of two different terms raises questions. Is enabling a filter the same as applying it? Or are there two steps to making a filter active, first you enable it, then you apply it? (Or do you apply it first, and then enable it?)<\/p>\n<p>When I asked the team, they said that enabling and applying are two names for the same thing. They internally use both terms to refer to adding filters to a widget.<\/p>\n<p>I recommended that they not use multiple names for the same concept. This makes it harder to see that the two methods are counterparts to each other. Pick a name and stick with it.<\/p>\n<p>They chose to use &#8220;Enable&#8221; throughout, so the second method was renamed to <code>Are\u00adAny\u00adFilters\u00adEnabled()<\/code>.<\/p>\n<p>This consistency extends beyond method names. If there is a parameter that corresponds to a property, use the same name for both the parameter and the property in order to make the connection clear.<\/p>\n<pre>runtimeclass Widget\r\n{\r\n    Widget(String id);\r\n\r\n    String Name { get; }\r\n}\r\n<\/pre>\n<p>In this case, the intention is that the <code>id<\/code> parameter passed to the constructor can be read back by reading the <code>Name<\/code> property. In that case, the parameter and property should either both be called <code>Id<\/code> or both called <code>Name<\/code>.<\/p>\n<pre>\/\/ Option 1\r\nruntimeclass Widget\r\n{\r\n    Widget(String <span style=\"border: solid 1px currentcolor;\">id<\/span>);\r\n\r\n    String <span style=\"border: solid 1px currentcolor;\">Id<\/span> { get; }\r\n}\r\n\r\n\/\/ Option 2\r\nruntimeclass Widget\r\n{\r\n    Widget(String <span style=\"border: solid 1px currentcolor;\">name<\/span>);\r\n\r\n    String <span style=\"border: solid 1px currentcolor;\">Name<\/span> { get; }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>It may be obvious to you, but that&#8217;s because you wrote it.<\/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-111415","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>It may be obvious to you, but that&#8217;s because you wrote it.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111415","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=111415"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111415\/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=111415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=111415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=111415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}