This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Code style generall

 
Gennadi Oreper
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

Have somebody try to check your code with CheckStyle?

Little questions:
- Is it to pay attention also in e.g. 'choises.txt' that maximum line width is 80?
- If I have any method 'public void doStuff(String value)' checkStyle says, that the parameter should be final declared? Is it needed by String or int?
- at javadoc comments i have a warning: 'line has trailing spaces' (at 2nd line)


What is really important of all it?

Thanks a lot...
 
Brian Kelly
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Why not? I did. Doesn't do any harm.
2) String...I don't really understand. There is no "int" there.
3) No idea...
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A tool like CheckStyle offers many different options for style checks. That's because there are amny different opinions about what is good coding style. You can enable and disable each option. If you enabled all options, you would get contradictory error messages. So you can't expect that all the options are really useful. And they certainly aren't all part of Sun's coding standards, which is what you really should be following here.

[Gennadi]: If I have any method 'public void doStuff(String value)' checkStyle says, that the parameter should be final declared? Is it needed by String or int?

Some people (including me) think it's a bad idea to change the value of a parameter within a method. It may confuse newbies who think that this has some effect outside the method (i.e. people who don't understand the difference between pass by value and pass by reference). So some people recommend that method parameters always be declared final. Sun does not however, and for SCJD, I wouldn't do it.

As for the trailing spaces: I don't think it's very important either way. Sun also does not have a recommendation here. However I do think trailing spaces look a little sloppy (for those who use an editor that shows whitespace). And one reason for many coding standard rules is to cut down on the amount of meaningless variation that can appear when studying changes in version control. This is a good example of that.
 
Gennadi Oreper
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello and thank you!
I have some experience at few big projects, but there is often any own style guides defined...
Now it is interesting and important for me to know, that is relevant for SCJD, and sometimes are any things not allways "unambiguous":-)

Thank's again!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic