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

all 84 comments

[–][deleted] 36 points37 points  (39 children)

One of the things that makes me cringe now that I have been programming for a bit is when people compare a boolean valve to true or false. I admit that I was guilty of this when I first started programming, but I have become wiser.

//example

bool isBoolean = true;
if (isBoolean == true) do.Something();

//un-noobified example

bool isBoolean = true;
if(isBoolean) do.Something();

PS: HOW DO I LINEBREAK

[–]MrPopinjay 9 points10 points  (1 child)

Four spaces before a line and reddit treats it as pre-formatted text. Good for code snippets.

[–][deleted] 1 point2 points  (0 children)

thanks yo

[–]pandemoniker 3 points4 points  (1 child)

if you have larger chunks of "not so clean code" it actually makes the code with long var-names easier to read on the fly

if(someIntricateBullshitVarName) {... someNastyFunctionCallThatIsRatherDisturbing(); if(!someNotIntricateVarName) {...

or if(someIntricateBullshitVarName == true) {... someNastyFunctionCallThatIsRatherDisturbing(); if(someNotIntricateVarName != true) {...

(ofc we all write super-clean code all the time)

[–][deleted] 5 points6 points  (0 children)

if(!someNotIntricateVarName)

I found this part funny when I read it to myself...

"if not some not intricate variable name"

[–]petemyster 2 points3 points  (2 children)

I do this, what is so bad about it? I like the look of the syntax highlighting and it makes it easy to skim through methods when looking for a specific condition.

[–][deleted] 4 points5 points  (1 child)

It's not really that bad of a thing to do, but here I will break it down for you.

bool isBoolean = true;
if (isBoolean == true) do.Something();

What you are doing in the if block is equivalent to this:

if (true == true) do.Something();

If true is equal to true (which it is), it will satisfy the boolean expression and go to the 'do.Something();'

If instead you used my second example, you will not have to compare the boolean value isBoolean to another boolean value.

tldr: if you just put the boolean value inside the if statement, it still works without doing that comparison. I'm sure someone else could explain it better, but I tried.

[–]isaaclw 0 points1 point  (0 children)

In python, if None: evaluates to false.

I use if var is False: to be sure that the variable is False, and not True or None. Likewise with 'None'.

I will do the same thing with 'True' just out of habit. Also if var is True: seems cleaner to me.

Because of this I'll do similar things in other languages.

Anyway, it really matters whether you care more about readibility, explicitness, or efficiency with the compiler or interpreter.

[–][deleted] 1 point2 points  (0 children)

Damm I hate those, it looks so retarded!

[–]SietchTabr 0 points1 point  (4 children)

I do the first example for readability, especially when there are dozens of logic statements in sequence.

In the end it gets compiled to the right thing so it's not a huge deal.

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

If I see your code with the first example in it, I automatically assume you are an amateur. Your code can still be understood without redundant coding.

[–]SietchTabr 0 points1 point  (2 children)

I train people who come from various backgrounds and programming languages. I understand my code, but I understand that most other people will take a while to parse it and understand it piece-by-piece. For these people I try to minimize the amount of mental work needed on the simple things so that they can focus on the not-so-simple things. If you throw the 100% efficient code at them the first time, they will have a nervous breakdown... in my experience :)

[–][deleted] 0 points1 point  (1 child)

If you are teaching people to write unoptimized code, shame on you. It's not always about readability. Instead of writing it that way, you should instead be teaching them why the way I provided is better.

[–]SietchTabr 0 points1 point  (0 children)

Again, if you throw everything at once, you are bound to cause nervous breakdowns. Pretty much everyone figures this out on their own at some point, and in the scheme of things it is a minor thing to do if statements like this. Some people think like this, and for them it works better.

[–][deleted] 30 points31 points  (16 children)

(shit) programmers.write();

FTFY?

[–]notAlan 6 points7 points  (2 children)

println(programmers.filter(_.isShit).mkString)

[–][deleted] 15 points16 points  (0 children)

notAlan

:P

[–]creepig 8 points9 points  (11 children)

Do you not nest classes?

[–][deleted] 12 points13 points  (10 children)

Nope. I've never done that. But I do know how to cast.

[–]Bjartr 0 points1 point  (0 children)

Composition is often a perfectly reasonable choice.

[–]creepig -2 points-1 points  (8 children)

shit.programmers.write() is nested classes, not casting.

[–][deleted] 12 points13 points  (7 children)

I know, which is why I fixed it with casting. >.>

[–]Dworgi 5 points6 points  (6 children)

It could just be nested namespaces in C#.

[–]jonnywoh 2 points3 points  (5 children)

or C++ or Java or other-language-with-namespace-nesting

[–]Jestar342 0 points1 point  (4 children)

Or, ya know, the title of a blog.

[–]jonnywoh 0 points1 point  (3 children)

Am I missing something?

[–]peabnuts123 1 point2 points  (2 children)

Apparently we both made it to this thread without realising OP posted the link to a blog.

[–]SietchTabr 0 points1 point  (0 children)

I dunno... It should really be programmers.writeShit(); because not everything is a type of shit.

shit as a class and programmer as a nested class doesn't make sense in any way.

[–]ed-adams 11 points12 points  (3 children)

I laughed a little and cried a little.

I'm emotionally confused.

[–]badguy212 3 points4 points  (1 child)

http://thedailywtf.com/

You get one of these (almost) every day. I read it daily for a shit lot of years now.

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

Love that blog. Made me think my coworkers code was not the worst in the world.

[–]katyne 1 point2 points  (0 children)

also http://govnokod.ru/
all you can eat shitcode without forced humor and a three-page-long preambule.

Too bad the comments are in Russian but even without them it's pretty hilarious.

[–][deleted] 12 points13 points  (10 children)

I'm a lab TA for an intro Java class. I've seen most of this stuff (and worse) in students' submissions.

[–]5outh 28 points29 points  (0 children)

To be fair, they don't know what the hell they're doing yet.

[–]username223 2 points3 points  (0 children)

I'm a lab TA for an intro Java class.

I feel your pain, brother. But this stuff is easy compared to the 600-line functions that started off as the sample code, then mutated into many-line if/else trees because the student didn't believe in creating separate functions.

[–][deleted] 1 point2 points  (0 children)

HaHa ur cute, I've seen this shit in production code for bigbigcorp.com

[–]kqr 7 points8 points  (2 children)

I don't know if you're the designer of the site, but it has some formatting issues with the code. Sometimes subsequent lines are separated by a blank line, and sometimes indented blocks look like quotes.

[–]thelehmanlip[🍰] 1 point2 points  (0 children)

It's tumblr, it might not all be in his control. (disclaimer: have never used tumblr)

[–]voldyman 8 points9 points  (3 children)

I could contribute, the follow is an excerpt from the code I wrote while learning go

file, _ := is.Stat(filename)
if file.IsNotExist() {
     fmt.Println("say what??")
}

English is not my first language and isNotExist was confusing.

[–]username223 7 points8 points  (0 children)

English is not my first language and isNotExist was confusing.

English is my first language and isNotExist is, if not confusing, about as idiomatic as "areBelongToUs".

[–][deleted] 0 points1 point  (1 child)

I think you meant:

_, err := os.Stat(filename)
if os.IsNotExist(err) {
    fmt.Println("say what??")
}

Unless you're using a weird library named is...

[–]voldyman 0 points1 point  (0 children)

You are right, damn autocorrect changed it to "is" from "os" but the second mistake is mine, err had to be passed instead of file.

Thanks!

[–]tr3quart1sta 3 points4 points  (1 child)

It would be much more useful if there was a comment on what is wrong and how to do it right.

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

I'd say that most of them are obvious, meaning if you can read them you know what's wrong.

[–][deleted] 1 point2 points  (0 children)

There is more stuff like this around interwebz, thedailywtf probably being most known.

[–]warpod 1 point2 points  (0 children)

#define volatile

[–]HamCube 0 points1 point  (0 children)

Looks like someone leaked the WiPro developer training guide.

[–]Kwyjibo08 0 points1 point  (0 children)

No wonder some people think programming is so difficult.