• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

variable declaration code convention

 
Marcos Motta
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the "Code Conventions for the JavaTM Programming Language":

Put declarations only at the beginning of blocks. (A block is any code surrounded by curly braces "{" and "}".) Don't wait to declare variables until their first use; it can confuse the unwary programmer and hamper code portability within the scope.

Are you guys following this rule?
I have my doubts if it leads to clearer code...
What is the problem code like this:

[ May 26, 2003: Message edited by: Marcos Motta ]
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marcos,
I also disagree with it - I can live with the idea of having variables declared at the start ot the function as in the C language, or with declaring the variables close to their first use, but not a mixture of these two concepts.
However, as professionals we have to meet the coding requirements of the people we work for, and if we cannot convince them otherwise, then they have the last word.
So I have coded my application to the Sun standards, even though I dont necessarily agree with it.
Regards, Andrew
 
Bob Reeves
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All:
On the topic of code conventions, JLint is an example of a free/shareware program that flags noncompliance issues. I think it is on Download.com. After all, one should never lose a free rating point!
Thx
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic