The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Opinions

Posted by Matt Gerrans on November 20, 2001 at 5:50 PM

Well, I was going to keep my mouth shut, but since you've solicited opions, I'll give one: it is poor (if not uncommon) coding style to put so many operations in a single line. It doesn't create more optimized code, it is harder to read(especially for beginners) and it is harder to debug. If you try to keep one operation per line, then the exceptions you get are very helpful and specific. If you separated the contents your while() test into a few lines, your problem would immediately reveal itself.

- mfg


> Hiran,

> probably u should change the code to be like this :

>


> BufferedReader fileIn = new BufferedReader(new FileReader("c:\\test.txt"));
> String taskNumber;
> while(!((taskNumber = fileIn.readLine())==null)) {
> //some code}
>

> yup, BufferedReader.readLine() will return null if it reaches end of file, but, when it returns null, u can't call the method equals() because null has no such method ;)

> probably it ends the application completely because of NullPointerException.

> any differing opinions?





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us