iam an ex newbie vb6 programmer.. and i become a newbie Java Programmer today..
in vb6 i often use "Exit Sub" Method which would exit from a procedure..
how can i do like that in Java?..
i use that to avoid using Nested if..
Thanks in advance..
Try to organise your control statements so they are controlled by a boolean flag; when that flag becomes "false" the control statement will terminate and then the method will terminate. And, as Rob says, return any values required as the last line of the method.
Don't use == true or == false ever.
. . . if (b == true) . . .
Only write . . . if (b) . . .
. . . if (b == false) . . .
Only write . . . if (!b) . . .
Never write an empty catch; that will hide any Exceptions, so you can conceal errors and not know they have happened.
You are calling a doSave method which calls doMyTransaction so you seem to have confusing method names.
What you actually want isIf you have a String.equals method, putting a literal first prevents possible null pointer problems.
If you are a beginner in Swing, don't get NetBeans to write your code; write it yourself by hand.
Campbell Ritchie wrote:Try not to do that. See our style guide particularly about avoiding return break and continue, for an explanation.
That's a whole discussion on its own, probably as old as the VI vs Emacs discussion*. I personally return in the middle of a method quite often. Agreed, refactoring is a bit harder, but most of my methods are so good they simply don't need refactoring
(In other words: I'll tackle that problem when it arises)
* VI of course!
Why is this style given as wrong and the following right
The only difference I can see is the position of the opening curly brace and I don't think the first style would be considered wrong. Maybe it is a mistake or I'm missing something...
Anyway, we have had enough digressions on this thread already.
Campbell Ritchie wrote:Whoever wrote it was quite definite that braces should match vertically, which I personally find much easier to read.
Sorry for continuing on this topic but I couldn't stop myself. I also like the BSD-Allman indentation but I adapted myself to K&R indentation because the K&B book used that indentation so I thought that it was the standard. But now I feel relaxed that I'm not the only one who likes BSD-Allman indentation ...