Writing "proper" Java

AFB

Lifer
Jan 10, 2004
10,718
3
0
Anyone have any books that would help on learning how to "refine" code to make it more acceptable and professional looking and the correct way to do things in Java. Not quite a how to book, just more of de facto standards of how to do things.
 

duragezic

Lifer
Oct 11, 1999
11,234
4
81
Nice. That's cool actually, my prof for Intro to Java 1 & 2 sort of makes you code to the same rules as that page describes.
 

tfinch2

Lifer
Feb 3, 2004
22,114
1
0
Yeah my "Intermediate Java" professor makes us follow all conventions for labs or it's points off, and we must have javadoc compatible comments.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Holy freakin' old guide! They stated that they use make to build

I agree with most of it but here are my few beefs:
-4 spaces to indent is too much. 3 is a very common standard but I've got nothing against 2.
-80 character lines is too small (I think 100 is a reasonable goal). Multiline statements are extremely difficult to read so this point and the last should be tailored towards keeping things on one line
-a loop with no body should absolutely not be termintated with a semi-colon (chapter 7). No one will see the semi-colon and they are bound to assume that the next statement is actually part of the loop. This is just begging for infinite loops and other oddities. Loops with no body should have a {} after the clause.
-you should never use one letter variable names (not a strict rule, but I strongly prefer it that way) (chapter 8, "throwaway" variables)

I'd like to see them update this for generics and enums. Enums in particular, I've found, can get a little messy if you're doing more than just enumerating (like adding methods and properties).
 

jlarsson

Golden Member
Jul 31, 2001
1,050
0
76
Effective Javarogramming Language Guide by Joshua Block

This book may be what you are looking for...
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: Zugzwang152
Holy freakin' old guide!
don't blame me, blame Google!
Not faulting the guide (or you) because it's old
Syntactically, java hasn't changed much (with the exception of 1.5) so the rules set out are still very relevant. I was just surprised to hear the words "make" and "java" and "build" all in the same sentence
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
I like elses on the same line as the closing brace. It keeps things compact and reminds you that the else belongs with that if statement. Technically you're starting a new block, but logically you're not. The only time I find that gets messy is if you want to document the else case (or any else ifs). You can't very well put comments above the block, as is normal for most blocks.
 

boran

Golden Member
Jun 17, 2001
1,526
0
76
In general I use:
if()
{
content
}
else
{
}

this is offcourse very lengthy, but imho makes it very easy to see which brackets belong together, I also do this for anonymous inner classes:
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
:laugh: Sorry for laughing boran, but it looks funny when people code in a non-english language
 

boran

Golden Member
Jun 17, 2001
1,526
0
76
I prefer English myself, but this is a school project, code had to be dutch (for most part, you dont see me translating if structures )
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
"SluitVenster" I'm gonna guess that that means "Close Window". Am I close?

Is "btn" dutch for "button"?
 

boran

Golden Member
Jun 17, 2001
1,526
0
76
nah, btn is short for button, we get tought to use general prefixes for gui elements, btn, lbl, txa, txf, etc.

SluitVenster is CloseWindow yes.
 

Zugzwang152

Lifer
Oct 30, 2001
12,134
1
0
Originally posted by: boran
nah, btn is short for button, we get tought to use general prefixes for gui elements, btn, lbl, txa, txf, etc.

SluitVenster is CloseWindow yes.

I'm so glad programming languages were invented by an English speaker. :thumbsup:
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
I don't think it's that all programming languages were invented by english speakers. I think it's that they knew for the language to have a chance it would have to be accessible to english speaking people

The guy who invented python is Dutch (yay for Holland!)
<-- Dutch Canadian...
 

Bacardi151

Senior member
Dec 15, 2003
540
0
0
i always do

if (condition) {
code
}
else {
code
}

the only time i do what's described in the page is the :

try {
code
} catch (....) {
code
}

i guess that makes it a bit inconsistent

other than that i always put an open bracket next to a function/condition
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |