Non-standard coding style? - No Fluff Just Stuff

Non-standard coding style?

Posted by: Venkat Subramaniam on March 8, 2006

Last year I was mentioning to Neal that one of my pet peeves in coding is unnecessary,  and
dangerous, use of this, as in:

public void foo(int someVariable)
{
   this.someVariable = someVariable;

   ?
}

The reason I don?t like this is

  • the parameter someVariable hides the member variable within this method foo().
  • if later in this method, I update someVariable (thinking that it is the member) I am
    modifying the local variable/parameter and not the member.
  • once I see developers get into this habit, I see more and more superfluous-often noisy-use of
    this.someThing() and this.someThingElse().

It concerned me that tools often promoted this style of using this.

Neal mentioned a convention Thoughtworkers are using (most likely proposed and/or promoted by
Martin Fowler?). They use _ for member variables. At first thought that sounded strange. But, once
I tried it for a few months, I found it relatively easier to use that style.

public void foo(int someVariable)
{
   _someVariable = someVariable;

   ?
}


After a recent presentation I gave, a couple of people wrote ?using _ for member names is not an
industry standard.? When I mentioned this to Neal, he said, ?I mention this in my talks. Google for
Java Coding Style and you will see how many industry standards exist. Which one are you referring
to. So, if someone has a problem using _ send them to me.?

So, here you have it folks. You know where to find Neal! And if you are going to attend my talk today, be
ready for some interactive live coding and some more of those underscores! :)

Venkat Subramaniam

About Venkat Subramaniam

Dr. Venkat Subramaniam is an award-winning author, founder of Agile Developer, Inc., creator of agilelearner.com, and an instructional professor at the University of Houston.

He has trained and mentored thousands of software developers in the US, Canada, Europe, and Asia, and is a regularly-invited speaker at several international conferences. Venkat helps his clients effectively apply and succeed with sustainable agile practices on their software projects.

Venkat is a (co)author of multiple technical books, including the 2007 Jolt Productivity award winning book Practices of an Agile Developer. You can find a list of his books at agiledeveloper.com. You can reach him by email at venkats@agiledeveloper.com or on twitter at @venkat_s.

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »