He then proceeds to iterate over the list using zero based indexing. The loop would not execute once if the list had length zero, making this check just plain wrong.
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.
My word, something can be redundant (not conceding that point) and not "just plain wrong."
Your language hate and insistence that the programmer himself is one of the "problems" is why people don't do code reviews, and why people get overly defensive if you offer constructive criticism of code. Your criticism is not constructive.
If you are in a position of power or mentorship I suggest you take a moment to think how your words and actions influence those around you, particularly those less experienced who may look up to you.
> My word, something can be redundant (not conceding that point) and not "just plain wrong."
I think we can agree to disagree. I'm strictly against redundancy if it doesn't serve a well-defined purpose.
> Your language hate and insistence that the programmer himself is one of the "problems" is why people don't do code reviews, and why people get overly defensive if you offer constructive criticism of code. Your criticism is not constructive.
I would phrase my criticism entirely different if the recipient was someone who asked for my commentary and not someone who felt confident enough to write a blogpost on how to start refactoring code.
> I'm strictly against redundancy if it doesn't serve a well-defined purpose.
Well, a good optimizing compiler might factor redundant checks out. The JVM has one of the best optimizing compilers around... Sometimes source code clarity is better than "absolute correctness", especially when we're discussing something trivial.
> I would phrase my criticism entirely different if the recipient was someone who asked for my commentary and not someone who felt confident enough to write a blogpost on how to start refactoring code.
Right, because we should seek out excuses to be nasty to others. How about we just try to be constructive as much as possible?
> 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)
You must null check a lot of things in C, especially since there is no graceful error handling (try/catch blocks)... C certainly allows things to be null (or garbage) values.
> The problem is that Java did away completely with value types and made everything pointer only.
I'm not sure what you are saying here -- the very notion of pointers do not exist in Java. This decision was made while creating the language, and avoids an entire class of programming errors. Java is strictly pass by value.
> the third is the missing for-each construct.
I completely agree with you here. Java does have a for-each construct, and it's recommended to use whenever possible. It avoids an entire class of programming errors.
> I'm not sure what you are saying here -- the very notion of pointers do not exist in Java. This decision was made while creating the language, and avoids an entire class of programming errors. Java is strictly pass by value.
To clarify: the GP is probably referring to boxed and unboxed data types. IIRC, Java has some unboxed data types ("primitive" types?), but mostly everything is boxed behind a pointer.
> but mostly everything is boxed behind a pointer.
Behind a Reference would be more accurate. It's just a reference to a spot in the heap. Other than similarly "pointing" to a place in memory, the comparison between Java References and C Pointers stops there. One cannot pass a "pointer" in Java, nor can the pointer be free-form manipulated like in pointer-arithmetic.
My statement is perfectly accurate in the context, which is discussing the representation of Java types.
Java doesn't hold a monopoly on the word "pointer." For example, Go has pointers but doesn't allow pointer arithmetic in safe code. Similarly for Rust.
> You must null check a lot of things in C, especially since there is no graceful error handling (try/catch blocks)... C certainly allows things to be null (or garbage) values.
You are correct that adding C as an example language was wrong. C++ on the other hand still stands.
> I'm not sure what you are saying here -- the very notion of pointers do not exist in Java
Java references are just C pointers without pointer arithmetic.
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.