Author Topic: Java with Style  (Read 84 times)

Walter Mitty

  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 1025
    • View Profile
Java with Style
« on: September 07, 2011, 07:44:15 am »
I did a search, and came up with this article by Thornton Rose.

For background, I once read a book entitled Pascal with Style and it taught me a lot of useful stuff about writing better code in Pascal.

I'm interested in your reactions to Thornton's comments.  Do you agree with with him that good style is of value in source code?  Do you agree with his recommendations regarding style?  Is there a more compreghensive style guide somewhere?


Richardk

  • Global Moderator
  • Wise Sage
  • *****
  • Posts: 3820
    • View Profile
Re: Java with Style
« Reply #1 on: September 07, 2011, 09:27:14 am »
It goes without saying that good style in source code is useful. Briefly skimming his recommendations, they seem as good as any plus he states if you don't like one style then pick another. His examples and suggestions are classic programming 101 but I've also noticed many shops have their own style requirements. So in the end it comes down to do something that makes the code readable and be consistent.

Peter Gibbons

  • Guest
Re: Java with Style
« Reply #2 on: September 08, 2011, 07:21:04 am »
I believe style is very important.

However the style that the author is using seens too old fashioned to me:

// Increment the counter value
-- empty line? --
counter = counter + 1;

Give me a break.

He is also not taking any real stand on the tabs vs spaces issue.

Religious issue ... Blah, blah.

USE ONLY SPACES.

Everybody opening the file will see the exact same formatting.

His code is still better than the "bad style" examples he shows.

I also like how he is naming the variables with nice descriptive names.

You wanted to see "Java with Style"?

Check this site:

http://scala-lang.org

;)

Not only is everything an object (like in Smalltalk) but you will recognize some functional aspects that came from Lisp.

( You used to be a Lisp user IIRC ? )

I D Shukhov

  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 3362
    • View Profile
Re: Java with Style
« Reply #3 on: September 08, 2011, 07:38:19 am »
I can't bring myself to exceed 80 characters on a line -- the standard terminal window size. 

Is this being a slave to custom -- or a bad habit?  Just because I'm used to seeing code that way doesn't mean that it makes sense.

Monitors are much bigger than virtual terminal windows and it's a lot clearer, and therefore easier to understand the code, to see the whole line than to continue it.

Anything that won't sell, I don't want to invent.  Its sale is proof of utility, and utility is success. – Edison

Walter Mitty

  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 1025
    • View Profile
Re: Java with Style
« Reply #4 on: September 08, 2011, 07:46:14 am »
Useful feedback so far.  Thanks folks.

Yeah x = x + 1 is archaic style.  Much as it appeals to the FORTAN luddite lurking in me, it has to be called bad style.

I also regards comments such as "increment the counter" as bad style, regardless of the format.  The code should tell a story.  The comments should clarify the story when the code doesn't make it clear.  People who read code should know when the counter is being incremented. 

This is like the warning in the instruction manual for a TV sets that alerts me to the danger of sticking my fingers into a live outlet.  It just makes me less likely to read on.



Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf