News for hackers. Stuff that matters.
Re:What is the most intrusive wart on your favourite program... by windsurfer on Sunday December 07, 2008 @10:18PM (#389434)
About your last point: You can get around it by typing return (a);
Re:What is the most intrusive wart on your favourite program... by mdasen on Monday December 08, 2008 @12:46AM (#389537)
I should have used a better example, but there are a good number of cases where the Java compiler complains about missing return statements that just don't need to be there. It's a wart in the language.
Re:What is the most intrusive wart on your favourite program... by dcminter on Monday December 08, 2008 @07:05AM (#389774)
Can you cite a specific example where the condition is NOT ambiguous and the Java compiler WILL produce an error? The example you cite is incorrect (see my post later) - you can compile code of this form just fine.

I'm not aware of unambiguous situations where the compiler will complain; if you see an error it's usually pebkac!

Re:What is the most intrusive wart on your favourite program... by zain on Monday December 08, 2008 @01:36AM (#389583)
It isn't always that straightforward. For example:

  if (a)
    return (some && complicated || boolean && calculation);
  else
    return (some || other && boolean || calculation);
edit: I suppose you can get rid of the "else", but you shouldn't have to sacrifice readability for a compiler shortcoming. I'm with mdasen; the compiler should figure it out.
Re:What is the most intrusive wart on your favourite program... by ralph on Monday December 08, 2008 @08:55AM (#389828)
Readability is improved by not having the else clause. It makes it clear that the return in the then-block is there and the code won't continue after the end-if.
Re:What is the most intrusive wart on your favourite program... by ars on Monday December 08, 2008 @02:14AM (#389610)
You (and some posters below you) missed the point. It's just an example. Think of the more general case.
Re:What is the most intrusive wart on your favourite program... by jaxn on Sunday December 07, 2008 @10:58PM (#389465)
or...

if (a) { return true; } return false;

Re:What is the most intrusive wart on your favourite program... by RWilson on Sunday December 07, 2008 @11:58PM (#389504)
agreed, if (a) then just return a;

if (a) { return true; } is just as redundant as an if (a == true) statement.

Re:What is the most intrusive wart on your favourite program... by RWilson on Thursday February 05, 2009 @11:31PM (#469349)
Hmm... not sure what justified the -1 on this. Perhaps that in some languages if (a) can be used as a shortcut for if (a != null), where a is an object and not a boolean. So, as a correction to my previous comment. If (typeof a == "Boolean" || a instanceof boolean), I still stand by reducing redundancy, but if a is an object, then fine, if (a) return true;