r/badcode • u/sausage-x-donut • May 12 '23
java Code written by project lead. A comment was added by my team member that the entire method can be replaced with a single line: getErrorsList().contains(message). Project lead responded that we should focus on readability and performance and not on such code review comments.
796
Upvotes
View all comments
Show parent comment
-104
u/Agilitis May 12 '23
I did not say it IS broken. I said it CAN BE broken easily. Put a `!` mark in front of the if and it is broken. Switch the return statements and it is broken. Change the type of the variable that you created and it might not even support contains.
These examples might sound strange but these happen from time to time. If you can write this code simpler, you need to do it simpler. Not everything needs to be dumbed down, but this is not more readable than the one liner.