Java Virtal Machine.net

[ News ] rss

February 01, 2011

Mark Wielaard: New GPG key. Finally created a new GPG key using gnupg. The old one was a DSA/1024 bits one and 8 years old. The new one is a RSA/2048 bits one. I will use the new one in the future to sign any release tarballs I might create. pub 2048R/57816A6A 2011-01-29 Key f...

More »

February 01, 2011

Andrew Hughes: [SECURITY] IcedTea6 1.7.8, 1.8.5, 1.9.5 Released!. We are pleased to announce a new set of security releases, IcedTea6 1.7.8, IcedTea6 1.8.5 and IcedTea6 1.9.5. This update contains the following security updates: The IcedTea project provides a harness to build the source code from OpenJDK6 u...

More »

November/2024
SunMonTueWedThuFriSat
     12
3456789
10111213141516
17181920212223
24252627282930
       

[ Archives News
for 'Developers' ]

home > news > developers > code advice #10: place brackets with the declaration type, not the name

Code Advice #10: Place brackets with the declaration type, not the name

(See intro for a background and caveats on these coding advice blog entries.) The most important code style rule is that when you modify somebody else's code, you preserve the coding style in that file. Even when it hurts. The only thing worse than an "incorrectly" styled source file is an inconsistently styled one! One of my coworkers writes Java code in a very C-inspired way. One of the habits I have difficulty with is the bracket placement for arrays. I thought I would dedicate a blog entry to this, because it occurs in many other code bases. A quick scan revealed a couple thousand matches in the JDK source code (which, granted, is a tiny fraction of the overall codebase). Briefly stated, the correct way (as far as I'm concerned) to place brackets in an array declaration is with the type, not with the variable name. Therefore, this is okay: int[] scores; and this is not: int scores[]; Here's a real-world example, from String.java: @Deprecated public String(byte ascii[], int hibyte, int offset, int count) { checkBounds(ascii, offset, count); char value[] = new char[count]; ... As you can see, there are two violations here - both in the parameter usage, and in the declaration of local variable "value". Most of you will probably just nod at this and move on, since it's what you're already doing. But if ...


Date: July, 17 2006
Url: http://blogs.sun.com/tor/entry/code_advice_10_place_brackets


Others News

©2002-2019Java-Virtual-Machine.net pt | nl | website editor | icon font | css menu maker