Busy with SortedNames TextFileIn suggests * TextFileIn in = new TextFileIn("file.txt"); * boolean done = false ; * while ( ! done ) etc. If you do not like this (as you do ) change done into boolean goOn = true ; while ( goOn ) {... Reason to think about avoiding negative booleans again?
I agree. But the consequence is what should a greenhorn or ranchhand do if he likes a 'negative' way of expressing himself? Ok, here we are kindly requested to follow the nitpickers meaning aren't we ?
pete hesse
Ranch Hand
Joined: Aug 29, 2000
Posts: 44
posted
0
How about this? boolean done = false; while ( done = false ) { ... } It preserves positive logic, is easy to read and gets around the naming problem. This is how I was taught back in my mainframe days, and IMHO is still useful. Hope this helps.
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
pete hesse
Ranch Hand
Joined: Aug 29, 2000
Posts: 44
posted
0
Right Marilyn. That's one of those mistakes I make all the time. Fortunately the compiler bails me out!
Matthew Phillips
Ranch Hand
Joined: Mar 09, 2001
Posts: 2676
posted
0
IMHO, the positive version is easier to read and keep track of in a long program. Matthew Phillips
Matthew Phillips
Pete Pan
Ranch Hand
Joined: Mar 14, 2001
Posts: 44
posted
0
never executes since in the while loop you are ASSIGNING false to done, not COMPARING it. Java doesn't warn you about that one like a good C++/C compiler would.
Originally posted by pete hesse: How about this? boolean done = false; while ( done = false ) { ... } It preserves positive logic, is easy to read and gets around the naming problem. This is how I was taught back in my mainframe days, and IMHO is still useful. Hope this helps.
Peter Gragert
Ranch Hand
Joined: Jan 16, 2001
Posts: 421
posted
0
No, only if you reverse! while (false = done ) ... Now a C-compiler would catch the error! So in C it maybe wise to catch typing errors to create a habbit to take constants in comparison first ??
Johannes de Jong
tumbleweed
Bartender
Joined: Jan 27, 2001
Posts: 5089
posted
0
Originally posted by Gareth Leachman: Those mainframe dudes
Whats wrong with us ???
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.