tag:blogger.com,1999:blog-32049549.comments2023-11-02T08:35:02.778-07:00A Nickel's WorthJacob Gabrielsonhttp://www.blogger.com/profile/13887274100244616103noreply@blogger.comBlogger134125tag:blogger.com,1999:blog-32049549.post-59924600847035444762020-04-28T10:57:04.365-07:002020-04-28T10:57:04.365-07:00Thanks for the comments - I've (hopefully) fix...Thanks for the comments - I've (hopefully) fixed those issues in the <a href="https://a-nickels-worth.dev/papers/varnaming/" rel="nofollow">new version</a> on my new blog.Jacob Gabrielsonhttps://www.blogger.com/profile/13887274100244616103noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-8473683032802742092020-04-27T10:47:17.383-07:002020-04-27T10:47:17.383-07:00Thank you for this eloquent essay. The article con...Thank you for this eloquent essay. The article contains a few typos, perhaps due to successive refactorings:<br />- <i>java.util.Collection</i> does not have a <i>get(int i)</i> method<br />- the signature of <i>printFirstNPositive(int n, Collection c)</i> is not consistent with the discussion below, which mentions the parameter <i>maxToPrint</i><br />- "even if by the letter of they law" ? Did you mean the law?<br />- the variable names in method 'updateJVMs' are not consistent with the comments (although I suppose it illustrates your point regarding comments;-)Wild Pottokhttps://www.blogger.com/profile/02272736267734752831noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-8864019801191653602020-04-18T16:40:22.651-07:002020-04-18T16:40:22.651-07:00Hi Marty - ok I have been meaning to set up a new ...Hi Marty - ok I have been meaning to set up a new blog anyway, so finally got around to it. It's still pretty bare bones (for now) but I have added a copy (only slightly edited) of the Modes paper you're referring to, if you'd like to check it out:<br /><br />https://a-nickels-worth.dev/posts/modesharm/Jacob Gabrielsonhttps://www.blogger.com/profile/13887274100244616103noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-13350979205254046392020-04-15T10:36:18.780-07:002020-04-15T10:36:18.780-07:00Thanks for the feedback, I'll see what I can d...Thanks for the feedback, I'll see what I can do :-)Jacob Gabrielsonhttps://www.blogger.com/profile/13887274100244616103noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-86115524502213236312020-04-09T22:56:09.437-07:002020-04-09T22:56:09.437-07:00Wonderful thank you.
I still consider and refer t...Wonderful thank you.<br /><br />I still consider and refer to original „Modes Considered Harmful„ years after being able to read it anymore :)<br /><br />Is there any chance to repost the original on your blog? Martyhttps://www.blogger.com/profile/11632299838624169949noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-22981459356446395312016-08-10T15:37:41.347-07:002016-08-10T15:37:41.347-07:00There is a typo in code
int doSomethingWithCollect...There is a typo in code<br />int doSomethingWithCollectionElements(int numberOfResults, Collection integerCollection)<br /><br />http://take.ms/fX8Ys<br /><br />You renamed "count" to "variableThatCountsUp"Павелhttps://www.blogger.com/profile/17033422402221495381noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-56050862195070528112016-06-24T08:36:10.178-07:002016-06-24T08:36:10.178-07:00I only have one difference of opinion, which is wh...I only have one difference of opinion, which is when CamelCasing acronyms and initialisms, only the first letter should be capitalized. It's not too bad if there's only one in the name, but when I see names such as AWSEC2HTTPClient, my head explodes.<br />Andrew Certainhttps://www.blogger.com/profile/16441639864096997561noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-47599187065383538202016-05-27T09:08:12.029-07:002016-05-27T09:08:12.029-07:00@Greg: thanks, I clearly need an editor :-)@Greg: thanks, I clearly need an editor :-)Jacob Gabrielsonhttps://www.blogger.com/profile/13887274100244616103noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-44346967182941243872016-05-26T22:18:26.744-07:002016-05-26T22:18:26.744-07:00The comment "maxToPrint" doesn't mat...The comment "maxToPrint" doesn't match the method's signature where 'n' is used...Greghttps://www.blogger.com/profile/08210921530524593112noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-72122442961667066942016-05-26T18:28:27.911-07:002016-05-26T18:28:27.911-07:00Thanks for all the comments and bug fixes - I made...Thanks for all the comments and bug fixes - I made a few minor updates attempting to address the more mechanical problems people pointed out. Regarding the use of the term <i>Teutonic</i>, I think it might be more accurate to say <i>Agglutinative</i>. I noticed this in a talk by Kevlin Henney (see slide 40 of http://www.slideshare.net/Kevlin/seven-ineffective-coding-habits-of-many-programmers-42301681 for example). Because he used it to refer to the common <i>anti-pattern</i> of gluing together low-information-content words (his example was "validateCustomerValue"), I'd be hesitant to use the term here, for fear of causing confusion.Jacob Gabrielsonhttps://www.blogger.com/profile/13887274100244616103noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-56545468982209389182016-05-22T17:32:58.779-07:002016-05-22T17:32:58.779-07:00Hey! Great post,
Just a small fix. You said and ...Hey! Great post, <br /><br />Just a small fix. You said and I agree that types shouldn't be on the variable name because it is already explained when declaring the variable. But this is exclusive to static typed languages. If you are working with a dynamic typed language, it would make more sense to put the type of the variable in the name, as you don't know what it is until you make a method call on that object.<br /><br />Also here is a small error:<br /><br />// BAD<br />int port; // TCP port number<br />// GOOD<br />int tcpPortNumber;<br /><br />With your explanation it would be better just to name it as tcpPort. You already know it is a number because it is declared as int.<br /><br />Regards<br />Anonymoushttps://www.blogger.com/profile/01040962958909892783noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-65913095163469482902016-05-21T09:04:18.600-07:002016-05-21T09:04:18.600-07:00Great post! You covered pretty much everything the...Great post! You covered pretty much everything there is to say about naming variables!<br /><br />Two remarks. <br /><br />Instead of the variable name 'c' in your rewritten example I would have written 'cs'. The idea is that you pluralize even one-letter names when they refer to a collection of elements. It becomes especially useful if your code mixes both variables that refer to a single element of a collection and variables that refer to the collections themselves (e.g. 'x' and 'xs'). I picked up this convention from the Haskell community and I'm fond of it since then.<br /><br />As other commenters have pointed out I find the "overused" variable names 'result' and 'tmp' (or sometimes just 't') useful sometimes. The canonical example for a valid use case for 'tmp' is the swap function where a variable 'tmp' is literally introduced to be a *temporary* reference. I tend to use the name 'result' in a function that returns a collection and imperatively builds up the resulting collection by feeding elements into 'result' (e.g. imperatively written 'filter' function). It's especially useful if this function has many variables or operates on several collections since you see at a glance which variable refers to the resulting collection even though you could have named it 'r' if only considering your "distance" argument.Eugenhttps://www.blogger.com/profile/06862919087845173596noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-65682864078764280342016-05-15T22:15:04.308-07:002016-05-15T22:15:04.308-07:00i want to read Code Complete 2 again ,after readin...i want to read Code Complete 2 again ,after reading this postsAnonymoushttps://www.blogger.com/profile/08950812733655177108noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-3219863573874804562016-05-15T20:49:01.993-07:002016-05-15T20:49:01.993-07:00Nice tips. Thanks! Nice tips. Thanks! Anonymoushttps://www.blogger.com/profile/11079487798535901992noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-70436355643669213552016-05-14T20:30:28.185-07:002016-05-14T20:30:28.185-07:00Nice naming tips, I will try to remove result, pro...Nice naming tips, I will try to remove <b>result</b>, <b>process</b> variables in my codeJiacai Liuhttps://www.blogger.com/profile/11123024099169317049noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-42734780681098531982016-05-14T09:00:05.456-07:002016-05-14T09:00:05.456-07:00I disagree with the *never use these variable name...I disagree with the *never use these variable names again* assertion. More fitting is the rule regarding short naming in obvious context; tmp is a favored name, just like i, j, k, ii, nn, t, tt, etc. This behavior derives from days gone by writing Fortran IV code. Hence, the use of such names has long been recognised to be as an index. I hold that no index deserves even a full name; three characters at best. tmp, val and str are such names.William R. Buckleyhttps://www.blogger.com/profile/10983983460228260349noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-78222899860265588202016-05-14T07:24:57.954-07:002016-05-14T07:24:57.954-07:00Some useful tips here. A few minor objections rega...Some useful tips here. A few minor objections regarding your "Teutonic" suggestion (although I agree with your basic intent): English is not a Romance language, it is Germanic. Also, "Teutonic" is antiquated and carries certain questionable overtones. A better way to express your intention here would be to point out how Germanic languages such as modern German create compound nouns that precisely describe a given thing: "Zahnarzt" is literally "tooth doctor," to use one of your examples. This is not a trait unique to Germanic languages, however. The thing about English is not that it is "elliptical," but rather that it has been strongly influenced by French, Latin, and other languages. If you do not speak French, then an English word of French origin may seem vague, but it's really just a word you don't understand as well as you might understand others.Anonymoushttps://www.blogger.com/profile/17991323683598444223noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-34900477071592798092016-05-14T00:16:23.598-07:002016-05-14T00:16:23.598-07:00You wrote:
"Most names should be Teutonic, fo...You wrote:<br />"Most names should be Teutonic, following the spirit of languages like Norwegian, rather than the elliptical vagueness of Romance languages like English."<br /><br />However, English is a Teutonic (or Germanic) language, like Norwegian, as can be seen at https://en.wikipedia.org/wiki/Germanic_languages <br /><br />English has been influenced by a Romance language, French, (https://en.wikipedia.org/wiki/Romance_languages) but is still considered to be Germanic.Allyhttps://www.blogger.com/profile/05971509982523220766noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-46079827253373413902016-05-13T13:43:25.142-07:002016-05-13T13:43:25.142-07:00Nice for strongly typed languages. I'd suggest...Nice for <b>strongly typed</b> languages. I'd suggest revising the article title to reflect that context. <br /><br />In dynamically typed languages the suggestion to avoid including some kind of type indicator in the name can be disastrous to the developers that follow.Anonymoushttps://www.blogger.com/profile/11199595789739403999noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-31584623170485751372016-05-13T10:13:02.066-07:002016-05-13T10:13:02.066-07:00I think you fail to follow own advice:
int prin...I think you fail to follow own advice:<br /><br /> int printFirstNPositive(int maxToPrint, Collection c)<br /><br />The method name uses "N", but the param for N is named "maxToPrint". Confusing and also violates his/her wasted space rule.<br /><br />Instead:<br /><br /> int printFirstNPositive(int n, Collection c)<br /><br />I think the short variable names "n" and "c" are fine since they are part of the method signature and have unambiguous meaning, and also because the implementation is so short (so no problem remembering that n and c are the inputs.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-32049549.post-4320124631386236532016-05-13T10:06:51.551-07:002016-05-13T10:06:51.551-07:00Two toughts here:
* Remove Thoughtless One-Time V...Two toughts here:<br /><br />* Remove Thoughtless One-Time Variables<br /><br />In java, i prefer to split them up if they can be null: A null pointer exception stack trace is much nicer iw you know what is null.<br /><br />*Avoid Over-used Cliches - result<br />I prefer to use result as a variable if i am mapping/filtering/... Much like i/j/k it is more an idiomnonehttps://www.blogger.com/profile/14799646140631984597noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-55326489723421949962016-05-13T09:45:40.029-07:002016-05-13T09:45:40.029-07:00Bug in your first listing:
int a6 = a2.get(i1);
...Bug in your first listing:<br /> int a6 = a2.get(i1);<br /><br />Should read:<br /> int a6 = a2.get(a3);Elliothttps://www.blogger.com/profile/05275457126301174493noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-29169043779341847812016-05-13T09:36:05.953-07:002016-05-13T09:36:05.953-07:00In about 1975, the BASIC language only allowed var...In about 1975, the BASIC language only allowed variables to have a single letter and a number (such as a1). DEC basic (digital equipment Corp) provided for a 3rd character signifying the data type. a1% was an integer, a1$ was a string, etc. The company I founded in 1972 developied some pretty sophisticated and commercialy successful software using these naming restrictions. Of course, they were hard to debug and we were all thankful when DEC enabled longer names some years later. Ken Rosshttps://www.blogger.com/profile/03220346918342573183noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-1134852822755813622016-05-13T09:23:55.271-07:002016-05-13T09:23:55.271-07:00Actually I read the first code and even found an e...Actually I read the first code and even found an error (but also used the second one to be sure): in line 5 it should be<br />"int a6 = a2.get(a3);"<br />not<br />"int a6 = a2.get(i1);"<br />(a3 in place of i1). So yes this kind of programs is not only difficult to debug, but also to write properly!<br /><br />Anonymoushttps://www.blogger.com/profile/06073018306318339221noreply@blogger.comtag:blogger.com,1999:blog-32049549.post-46572111362089817022016-05-13T08:52:41.498-07:002016-05-13T08:52:41.498-07:00Nice collection of tips. Thank you!Nice collection of tips. Thank you!David Lamblhttps://www.blogger.com/profile/14363234979723417436noreply@blogger.com