Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'd never seen this style until I joined my current employer. The first time I saw it I thought "this idiot has no idea and Java/OO languages generally are not his strong suit", but it turns out that it's a regularly-occurring affliction here and is mandatory style on a couple of projects, although these projects also use the</p> <pre><code>if (0 == someValue) { .... } </code></pre> <p>approach to doing conditionals, i.e. placing the constant first in the test so that you don't run the risk of writing </p> <pre><code>if (someValue = 0) </code></pre> <p>by accident - a common problem for C coders who ignore their compiler warnings. Thing is, in Java the above is simply invalid code and will be chucked out by the compiler, so they're actually making their code less intuitive for no benefit whatsoever.</p> <p>For me, therefore, far from showing "the author is coding with a dedicated thought process", these things strike me as more likely to come from the kind of person who just sticks to the rules someone else told them once without questioning them or knowing the reasons for the rules in the first place (and therefore where the rules shouldn't apply). </p> <p>The reasons I've heard mainly boil down to "it's best practice" usually citing Josh Bloch's <strong><em>Effective Java</em></strong> which has a huge influence here. In fact, however, Bloch doesn't even use it where even I think he probably should have to aid readability! Once again, it seems to be more the kind of thing being done by people who are told to do it and don't know why!</p> <p>Personally, I'm inclined to agree more with what Bruce Eckel says in Thinking in Java (3rd and 4th editions): </p> <hr> <p>'Some people will obsessively put <strong>this</strong> in front of every method call and field reference, arguing that it makes it "clearer and more explicit." Don't do it. There's a reason that we use high-level languages: They do things for us. If you put <strong>this</strong> in when it's not necessary, you will confuse and annoy everyone who reads your code, since all the rest of the code they've read <em>won't</em> use <strong>this</strong> everywhere. People expect <strong>this</strong> to be used only when it is necessary. Following a consistent and straightforward coding style saves time and money.'</p> <hr> <p><em>footnote, p169, Thinking in Java, 4th edition</em></p> <p>Quite. Less is more, people.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload