3 ms·
if (foo!=null && (a = foo.bar()) && a != null && ... a = foo.bar() will always evaluate to true as the assignment shouldn't ever fail. Of course, in compiled l
by alttab 17y ago
if (foo!=null && (a = foo.bar()) && a != null && ...
a = foo.bar() will always evaluate to true as the assignment shouldn't ever fail. Of course, in compiled languages I'm sure there will need to be a declaration of 'a' but if there is a possibility to reuse temp variables then could work.
However, if you are coding in C/C++ (and to a similar extent Java, there really is no way around it.
This could be an example of why hybrid functional, imperative, and object oriented languages are becoming popular because the programmer can pick the paradigm that most suits the problem.