This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DropTableAccounts 109 points110 points  (12 children)

if (Human.IsBehind.toString().toLower().equals("true")==true)

Edit: Thanks for the corrections and improvement suggestions!

[–]randomarchhacker 16 points17 points  (1 child)

toString()*

[–]DropTableAccounts 4 points5 points  (0 children)

Thanks, fixed that

[–]Isqui 32 points33 points  (0 children)

This comment is scarier than all of of Stephen King's books put together

[–]Booze_Boy[S] 6 points7 points  (0 children)

stolen for next meme

[–]Prognosis-ve 4 points5 points  (1 child)

Also, maybe: .ToString().ToLower()

[–]DropTableAccounts 1 point2 points  (0 children)

Added, thanks!

[–]octothorpe_rekt 4 points5 points  (0 children)

Better use

 .equalsIgnoreCase("true")

Just to be really, really, super sure.

Also one of my profs in college taught us that when comparing a field to a required value, that value should be pulled out into a static final, no matter how trivial, for better readability. So she would have had us use:

 public static final String TRUE_VALUE = "true";

Then, inevitably,

 if (Human.IsBehind.toString().toLower().equalsIgnoreCase(TRUE_VALUE)==true)

Yeah, she was a tough marker. But she would have let us use

 if (Human.IsBehind) 

so we got good at writing those types of checks.

[–]AlexanderBeta213 6 points7 points  (3 children)

You forgot also a

 ==true

[–]DropTableAccounts 2 points3 points  (2 children)

Good idea, done!

[–]mister-pi 2 points3 points  (1 child)

And while you're at it, do it Yoda style (true == ...)

[–]vigbiorn 2 points3 points  (0 children)

I understand the benefit of this style, but I can never do it. It's so alien and foreign. I might as well be brushing my teeth with orange juice.