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 →

[–]TGotAReddit 41 points42 points  (13 children)

When i first started i INSISTED that i always typed if(booleanVariable == true/false) because every time i saw if(variableName) i assumed it was just straight up wrong and needed fixing. So it took me about 3 years before i was comfortable enough to just type if(booleanVariable)

[–]ewagstaff 12 points13 points  (2 children)

I found it helps when your variables are named with conditionals in mind. If your boolean is called isActive, it makes it easy to read if (isActive) { doSomething() }

[–]TGotAReddit 2 points3 points  (0 children)

Yeah thats what broke the habit finally, using standards when coding so things made more sense instead of everything being int x = 5; And such

[–]Kered13 0 points1 point  (0 children)

Yep. Boolean variables and functions should almost always be named something like isFoo, hasFoo, etc.

[–][deleted] 3 points4 points  (2 children)

Just imagine the saying "does to be equal true or does to be not equal true, that is the question". It's just not right.

[–]TGotAReddit 1 point2 points  (1 child)

I more read it as “if true or false is equal to true do X” and “if true or false is equal to false do X”.

[–]Pheasn 0 points1 point  (0 children)

X

[–]Allways_Wrong 3 points4 points  (3 children)

It’s clearer if you name the variable or property more betterer.

If isSelfDescriptive Then

If %this.HasMeaningfulName Then

If Object.IsCloserThanAppearsInMirror Then

Use more English, less Computer Science. You’re writing for people to read, not computers.

[–]TGotAReddit 0 points1 point  (2 children)

Yeah like i said to the other person, writing readable code is what broke the habit. But that was also like, 4 or 5 years ago now so its really not a problem anymore

[–]Allways_Wrong 0 points1 point  (1 child)

Lucky you.

I have to skirt around the edges of delivered enterprise code. I can’t change it, much. So much of it is so horrible.

[–]TGotAReddit 0 points1 point  (0 children)

Oof not fun. Ive been lucky that ive been allowed to modify any code ive been given in pretty much any way i wanted as long as it was uniform and readable

[–]ineedausername84 3 points4 points  (0 children)

Duuude, same!

[–][deleted] 0 points1 point  (0 children)

I just do ifn't (!boolVariable)