r/badcode • • Jun 23 '20

java 'val' is a boolean value.

Post image
1.0k Upvotes

58 comments sorted by

View all comments

-2

u/F54280 Jun 23 '20 edited Jun 23 '20

This is not bad code. It is "slightly inelegant" but more readable code (because it is a only return from a function). If would be "inelegant" when used in a if, say in: if (val==true). It starts to be bad when reaching levels of if (val==true) return true; else return false;

But a simple comparison with true? Absolutely not worth of a post here. Here are 663000 occurrences using a simple google search

Edit: lol @downvoters that have no idea what actual badcode looks like

2

u/Mr2-1782Man Jun 23 '20

I think you don't understand what the problem with this code is. It isn't the comparison, rather its the fact that someone built an entire function around a builtin operator that uses said operator.

3

u/lachlanhunt Jun 24 '20

It's also the fact that the one variable they are relying on, val, is undefined (or defined in a different scope that's not shown).

1

u/F54280 Jun 24 '20

Sorry? This is not javascript, this is java. It means var is defined somewhere.

Or is the definition for being accepted by r/badcode so low that compiling isn't even a requirement anymore?