• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Don't capitalize local variable names....

 
Saloon Keeper
Posts: 1277
38
Eclipse IDE Postgres Database C++ Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When playing around with auto-boxing and un-boxing, I will often find myself with an Integer variable and an int variable, etc., and, especially in JShell, will resort to calling the primitive variable i and the Wrapper Reference I or l and L for longs (less likely, l looks too much like 1 in too many different contexts).

Watching someone present tutorial information in this way, I have soured enough on it that I am going to try to just stop doing this.

As they show various new methods, my eyes keep seeing calls to a static method on a class named I or L, rather than instance method calls on a reference variable that thought it was clever and bucked capitalization conventions.

This is counter-productive to teaching and learning, and probably a good example of "Congratulations, you saved 3 seconds of typing and caused your viewers/readers to waste hours of their time re-reading those lines until they realized they didn't mean what you made them look like."

I am generally adherent to accepted conventions, it just felt like when you are showing wrapper vs. primitive demonstrations and wrapper methods that it was a cool shortcut, I have now re-considered it watching others do it, and don't feel it is a helpful exception to the rule.

Don't capitalize reference variable names, it is very likely to make your code much harder to read.

* * * follows own advice * * *
 
Saloon Keeper
Posts: 24295
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well. we discussed this sort of thing recently in another forum. Good practice in Java forbids beginning any name with an upper-case letter unless it's a class name or maybe a constant name.

But aside from that, long tradition has discouraged certain characters from casual use. The I and L are among the worst, but also O and 0 (obviously illegal as a variable name, though!). Then there were "S" and "5". You might find that last to be strange, but the practices came from Data Processing shops (it wasn't known as "IT", then) where programmers would often code unto pre-printed pads which were lined as grids for 80-column punched-card characters. Some people's "5"s were sufficiently rounded that the poor keypunch operators couldn't tell them from "S"s, and they weren't literate in programming languages enough to safely guess.

These days we mostly have to do the keying ourselves (as well as being LAN and database administrators, etc., etc., etc., but we're often using terminals with proportional sans-serif fonts, so the difference between upper-case I and lower-case L can be really hard to see!
 
Jesse Silverman
Saloon Keeper
Posts: 1277
38
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.  I considered this a separate issue since I had been stopped in using upper case module names by nasty-grams from Eclipse a long time ago, but if I remember I often used to pick upper-cased project names which then suddenly began to be used for inferred module names?  Yeah, I think that was it...

This was the last hold-out of a general rule I tried to follow, and an interesting case of "smelling your own <whatever>" when I was doing it, didn't seem so bad, I knew what I was typing.

Watching someone ELSE do it got me to stop.  I was doing double-takes to figure out what their lines of code meant.

Cheers!
 
Those are the largest trousers in the world! Especially when next to this ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic