(no title)
pmr_ | 11 years ago
if( masterList[z].list2 != NULL && masterList[z].list2.length() > 0 )
{
for( Integer y = 0; y < masterList[z].list2.length(); y++ )
The if-statement is a good summary of what is wrong with Java. The author doesn't even notice that the second argument of && is redundant and keeps it in the "refactored" version as well...
Alupis|11 years ago
That's false. A list object may be initialized but be empty (making it's length zero). Or it may not be initialized (making it null).
Both conditions may happen independently of one another. He checks for the null first so that checking the length does not throw a NPE.
> The if-statement is a good summary of what is wrong with Java.
Frankly, I see nothing wrong here.
pmr_|11 years ago
I know an even lower level language (C++, C) that doesn't have the problem of things which make no sense to be NULL (list elements). The problem is that Java did away completely with value types and made everything pointer only. That has been recognized by later languages (C#) and fixed.
The whole code consists of problems: the first is the language, the second is the programmer, the third is the missing for-each construct.
philbarr|11 years ago
zo1|11 years ago
Also, having an implied "conditional" that must be extracted by reading the head-portion of a loop is very very unreadable. I'd reject your submission on a code-review.
Instead, you should do something like below. I assume that your example is contrived, so for the sake of argument, assume I have all sorts of business cruft around mine. I.e. should_process exists because there are business rules for processing/not processing the master_list.
pmr_|11 years ago
I fully agree that the code in my post is very bad, I took it from the article.
BinaryIdiot|11 years ago
Doesn't it check if a list isn't null and then if the list has at least one item in it? Or are you simply saying the for loop takes care of the situation where there are 0 items in the list?
philbarr|11 years ago
pmr_|11 years ago