> > try {
> > line = br.readLine();
[quoted text clipped - 8 lines]
> Two readLine's will never convince me as being a better
> solution than one.
Agreed entirely. Some people may find the assign-in-the-test idiom not quite
to their taste, but that /is/ a matter of taste, and it is at worst an
established idiom. But duplication is more than unconventional, it is more
than ugly -- it is /wrong/.
-- chris
Gordon Beaton - 04 Apr 2007 09:03 GMT
>> Two readLine's will never convince me as being a better
>> solution than one.
[quoted text clipped - 3 lines]
> at worst an established idiom. But duplication is more than
> unconventional, it is more than ugly -- it is /wrong/.
Just to be clear - I'm with both of you on this. My comment was
directed at the *other* bad smell in the earlier post:
while (true) {
if (something) break;
// other stuff
}
/gordon
--
Daniel Gee - 04 Apr 2007 09:26 GMT
> Agreed entirely. Some people may find the assign-in-the-test idiom not quite
> to their taste, but that /is/ a matter of taste, and it is at worst an
> established idiom. But duplication is more than unconventional, it is more
> than ugly -- it is /wrong/.
Ah, well, you see, it's not always a matter of taste. In python you
are strictly not allowed to make an assignment when a boolean test is
being made, such as for the while loop. It's even in the FAQ:
http://www.python.org/doc/faq/general/#why-can-t-i-use-an-assignment-in-an-expression
Anyways, it's just a habit to do it however you do it I guess. All the
options are fairly obvious about what they're doing, so even if others
are reading your code they're very unlikely to be lost in it.