{"id":20283,"date":"2008-11-07T10:00:00","date_gmt":"2008-11-07T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2008\/11\/07\/self-esteem-gone-overboard-the-perils-of-a-global-namespace\/"},"modified":"2008-11-07T10:00:00","modified_gmt":"2008-11-07T10:00:00","slug":"self-esteem-gone-overboard-the-perils-of-a-global-namespace","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20081107-00\/?p=20283","title":{"rendered":"Self-esteem gone overboard: The perils of a global namespace"},"content":{"rendered":"<p>There are items with overly generic names. <code>HANDLE<\/code>, <code>CloseHandle<\/code>, <code>GetObject<\/code>, <code>DIFFERENCE<\/code>, <code>query.exe<\/code>. But their functionality doesn&#8217;t live up to their name. <code>HANDLE<\/code> refers only to kernel handles, <code>CloseHandle<\/code> can only close kernel handles, <code>GetObject<\/code> only gets information about GDI objects, <code>DIFFERENCE<\/code> applies only to the numerical difference between group resources and standalone resources, and <code>query.exe<\/code> only queries information about <strike>Terminal Services<\/strike> <a href=\"http:\/\/blogs.msdn.com\/ts\/archive\/2008\/11\/03\/terminal-services-renamed-remote-desktop-services-at-teched-emea.aspx\"> Remote Desktop Services<\/a>.<\/p>\n<p> Why do functions that operate only inside a specific realm have names that suggest a broader scope? <\/p>\n<p> Self-esteem gone bad. <\/p>\n<p> You&#8217;re on the kernel team. You have a handle manager. What should you call your handles? Well, since they&#8217;re handles, just call them <code>HANDLE<\/code>. Because that&#8217;s what they are, right? And naturally the function that closes <code>HANDLE<\/code>s should be called <code>CloseHandle<\/code>. Sure, there are other types of handles out there, but they don&#8217;t exist in your world. Your world is the kernel, and in the kernel world, you can call them <code>HANDLE<\/code>s and everybody will know that you&#8217;re talking about kernel handles because that&#8217;s why you&#8217;re in the kernel in the first place! Why would somebody pass a handle to a non-kernel object to a kernel function? That makes no sense! <\/p>\n<p> Similarly, the GDI folks came up with their own object system, and naturally the way you get information about an object is to call <code>GetObject<\/code>. There&#8217;s no confusion here, right? I mean, this is GDI, after all. What other types of objects are there? <\/p>\n<p> The <strike>Terminal Services<\/strike> Remote Desktop Services folks thought the same thing when they created their <code>query.exe<\/code> program. Hey, this is a computer set up to run Remote Desktop Services; of course you want to query information about Remote Desktop Services. <\/p>\n<p> Of course, when your symbol exists in a shared namespace, the context of your naming decision becomes lost, and your generic-sounding function name (which worked just great for generic operations <i>in the world in which it was created<\/i>) ends up carrying more meaning than you originally intended. <\/p>\n<p> Commenter <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/05\/01\/587528.aspx#587944\"> Sean W.<\/a> tries to explains that Unix doesn&#8217;t have this problem. &#8220;A Unix-flavored close() system call can close any file descriptor.&#8221; This explanation ends up being its own counter-argument. When you say that it can close any file descriptor, you&#8217;re admitting that it can&#8217;t close <i>anything<\/i>. You can&#8217;t use <code>close()<\/code> to close the objects opened by <code>opendir()<\/code> or <code>dbm_open()<\/code> or <code>XtOpenDisplay<\/code>. <\/p>\n<p> &#8220;Well, yeah, but it can close any file descriptor regardless of where it came from.&#8221; And <code>CloseHandle<\/code> works the same way: It can close any kernel handle regardless of where it came from. <\/p>\n<p> Sean W. later clarified that &#8220;<a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/05\/01\/587528.aspx#588022\">the scope of <code>close()<\/code> is the system kernel, so it&#8217;s reasonable to expect that it applies to kernel data and no other data, whereas the scope of <code>CloseHandle<\/code> is all of Win32, including at least KERNEL\/USER\/GDI\/ADVAPI<\/a>.&#8221; Um, actually, the scope of <code>CloseHandle<\/code> is also the kernel. <\/p>\n<p> And in the category of &#8220;suggesting things that are already done&#8221; goes this comment from Daniel, who suggests that <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/05\/01\/587528.aspx#589287\"> the documentation explain which <code>HANDLE<\/code>s can be closed by <code>CloseHandle<\/code><\/a>. Actually, if you look at each function that creates a handle, it also tells you the function to use to close it. Not quite the same thing, but since you have to open something in order to close it, you&#8217;ll find the information even sooner. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are items with overly generic names. HANDLE, CloseHandle, GetObject, DIFFERENCE, query.exe. But their functionality doesn&#8217;t live up to their name. HANDLE refers only to kernel handles, CloseHandle can only close kernel handles, GetObject only gets information about GDI objects, DIFFERENCE applies only to the numerical difference between group resources and standalone resources, and query.exe [&hellip;]<\/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":[26],"class_list":["post-20283","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>There are items with overly generic names. HANDLE, CloseHandle, GetObject, DIFFERENCE, query.exe. But their functionality doesn&#8217;t live up to their name. HANDLE refers only to kernel handles, CloseHandle can only close kernel handles, GetObject only gets information about GDI objects, DIFFERENCE applies only to the numerical difference between group resources and standalone resources, and query.exe [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/20283","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=20283"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/20283\/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=20283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=20283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=20283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}