News for hackers. Stuff that matters.
Re:My most common code review suggestions by struppi on Thursday December 07, 2017 @07:26AM (#15869450)
Absolutely. So, what I started to do in my java code: Before dereferncing anything for the first time, i add

    assert foo != null : "foo must not be null - remember to wrap optional data in Optional<T>"
Just make sure to run your program (or at least the tests) with the JVM flag "-ea"
Re:My most common code review suggestions by qznc on Thursday December 07, 2017 @08:46AM (#15869891)
What is the point? How is an assert better than a NullPointerException?

If asserts are disabled, then the null pointer checks are still inserted by the JVM.

Re:My most common code review suggestions by cpburns2009 on Thursday December 07, 2017 @11:38AM (#15871506)
The benefit of using an assert is that it makes the error condition known immediately to the caller and the reason. Otherwise, whose to say when the NPE will occur. It could be raised just a couple lines down, or it could be a couple methods or a classes away which increases the complexity of diagnosing the actual cause of the error.
Re:My most common code review suggestions by ojhughes on Thursday December 07, 2017 @05:49PM (#15875128)
A more idiomatic approach would be Objects.notNull(foo)