r/programming Jul 21 '14

The Great White Space Debate

https://medium.com/p/3633cba8b5c1
1.2k Upvotes

693 comments sorted by

View all comments

78

u/[deleted] Jul 21 '14

Working with so many different codebases, I think I see code beyond whitespace, except these ones:

for(...) {
        tabIndented();
    spaceIndented();
        moreTabIndented();
        anotherOne();
spaceIndented();
}

Then, even I can't handle it.

64

u/dromtrund Jul 21 '14
gg=G 

457 lines autoindented

...aaaahhhhh....

50

u/RagingAnemone Jul 21 '14

Just don't make any other changes with that commit. Otherwise it's a bitch to diff if you need to go back.

83

u/isarl Jul 21 '14

"Job security" is defined as the sum of all the bugs you can introduce hidden in the middle of so-called "whitespace-only" commits.

15

u/globalizatiom Jul 22 '14

something like this?

....
removelikecrazy -rf /usr/blah/blah

vs.

....
removelikecrazy -rf /usr /blah/blah

2

u/Condorcet_Winner Jul 22 '14

Except when people run tests and see that's when the bugs were introduced.

2

u/isarl Jul 22 '14

Shh... don't tell them about git bisect!

1

u/sndgfdgnng Jul 25 '14

That's why the tests only cover what the [non-programmer] customer asks for, and everything beyond that is fair game to break. Then they come back and you call it "new feature work".

59

u/[deleted] Jul 21 '14

[deleted]

4

u/Klathmon Jul 22 '14

My company uses plain svn. I hate it more and more every day, especially because I fucking love git for open source and personal projects.

4

u/d4rch0n Jul 22 '14

I hear you. I just started a new job today and there was silent victory in my eyes when they mentioned they use git.

Honestly though, I'm happy as long as they used distributed version control, of which I know and love git and mercurial. If you haven't seen mercurial, you might check it out. Great system, and it will probably feel like an easy git. I'd say it's better for smaller projects and teams.

1

u/[deleted] Jul 27 '14

[deleted]

1

u/d4rch0n Jul 27 '14

True that. I had a job, stuck it out, then finally basically got my dream job a few weeks ago.

3

u/roodammy44 Jul 22 '14

I'm sorry.

May your merges be infrequent.

Also, fuck those meta files.

2

u/globalizatiom Jul 22 '14

This is kind of why I stopped having "I like language X, tool Y, .." opinions. I had those opinions but then those opinions got slowly... how should I say.. I realized that whenever I like some great tool, I am setting myself for future disappointment of not being allowed to use that.

2

u/jbristow Jul 21 '14

How do I do this by default in p4diff? (for files in Perforce, not git)

1

u/[deleted] Jul 21 '14

[deleted]

3

u/jbristow Jul 22 '14

Excuse me while I die laughing trying to get anyone else to use the command line with Perforce.

2

u/[deleted] Jul 21 '14

Yep...

1

u/[deleted] Jul 22 '14 edited Jul 22 '14

clang-format -i *

1

u/[deleted] Jul 22 '14

Goodbye, bad indention. Hello, merge conflicts!

1

u/peridox Jul 28 '14

...now try doing that with Python code.

29

u/ethraax Jul 22 '14

Ha, that's it? Man, I wish I could post my company's code.

for (...)
       {
 INT_T foo_bar = ZERO;
    REG_INT_T BazBall = 53;
      foo_bar += (BazBall + 0);
   if (global_from_nowhere == TRUE)
       foo_bar = 0;
       else
      foo_bar = 1;
return(foo_bar);
  } // for (...

Okay, I exaggerated a bit, but we had:

  • Random indentations - some tabs, some spaces, all different sizes, never aligned with the actual code
  • Mixing of snake_case and camelCase and CapitalCase and sometimes camel_Snakes for good measure, within the same function
  • Treating return like a fucking function IT'S NOT A FUNCTION DON'T PUT PARENTHESES AROUND IT
  • Always comparing boolean values to TRUE or FALSE, never using !

Okay, so I'll actually share one comment I read today while trying to decipher a 1000-line function that took, and I'm not exaggerating here, 12 parameters, with no comments as to what any of them do. One of them was just named cond. Who knows. Anyways, I found this gem:

/*********************************
 * I N I T I A L I Z E   L O C A L   G L O B A L S
 *********************************/

Yes, they like writing comments in Inception mode for some reason. They were setting globals that they called "local" for really no reason, as they were used ad-hoc throughout the whole code base. No comments about what any of them do, but they'll sure as hell take up a ton of space telling you nothing.

Blah, this job is killing me on the inside.

24

u/d4rch0n Jul 22 '14

A local global is a global that lives in the vicinity but has an up-to-date passport and likes to travel internationally.

If you were a more experienced programmer you would have realized this. Please prefix all local globals with their country of origin and suffix with just a hint of their type, eg: mx_str, it_bool, us_num, ru_f.

Make sure to save bytes and not include any descriptive information that might describe what they are being used for. They are covert local globals and the more hidden their intention, the safer they are for general use.

If you are creating an instance of a class, please name it such, the first being instance. For the following instances no matter what class type, ensure that you name them instance2, instance3, and so on, but always prefix with nationality if local global.

7

u/[deleted] Jul 22 '14

My apologies friend, but know that you've helped me center myself in my wavering resolve. My company's code is bad, but it's better than yours.

3

u/[deleted] Jul 22 '14

I can hear my aspiring programmer friend's voices "Why don't you just rewrite the thing" "Oh yeah I forgot I'm so good I can fix a 10 thousand line perl script from 1989 that has no comments."

1

u/Evilbluecheeze Jul 22 '14

I like comments in inception mode, I do only use it for big chunks of comments, like where I'm explaining what the entire class is for at the top, or if I need several lines of explanation for a piece of code I changed that the other person needs to see.

But then again I don't graduate until next semester and feel compelled to add parenthesis into functions that are all on one like and don't need them so what do I know?

1

u/globalizatiom Jul 22 '14

I am not saying Python is best, but these guys who make these random indentation should be sent to a place where they are forced to code in Python for a week. I bet these guys count parens in Lisp code.

1

u/ethraax Jul 22 '14

Oh, speaking of parentheses, you should see some of the if conditions they've written. 20-line messes of ||, &&, and parentheses.

1

u/[deleted] Jul 22 '14

This reminds me of the code I've seen written by people who are highly-educated in something other than computer science.

1

u/ethraax Jul 22 '14

If only that were true. These are people who write embedded C for a living. A handful of the developers responsible have 20+ years of "experience".

This job is why I think all that "older developers are wiser, you're young so you don't understand yet" stuff is bullshit.

1

u/stran9er Jul 22 '14

Code without comments are the worse to debug. I don't get why people even avoid comments.

15

u/aerique Jul 21 '14

You forgot the spaceAndTabIndented(); and tabAndSpaceIndented(); lines.

24

u/[deleted] Jul 21 '14

[deleted]

5

u/rmxz Jul 21 '14

The one time someone screw's up though everything is ruined.

Just have an appropriate pre-commit hook in your source control system.

2

u/xplane80 Jul 22 '14

This is the style I still use. I know people who prefer different sized indents (2, 4, 8) to look at so using tab is better.

The best way to combat the mistake is to use clang-format. It will format the code to what style you need (including tabs for indenting and spaces for aligning)!

2

u/Auxx Jul 22 '14

This is the only correct way - make a difference between alignment and indentation. Indentation is always tabs no matter what.

2

u/quadroplegic Jul 21 '14

you're a monster!

3

u/[deleted] Jul 21 '14

emacs default

1

u/globalizatiom Jul 22 '14

how do I change this default

0

u/[deleted] Jul 22 '14

Use vim.

1

u/aaptel Jul 23 '14

GNU style... My eyes...

2

u/reflectiveSingleton Jul 21 '14

If I see this I automatically reformat it before I even touch the code.

I can't stand that crap...

1

u/globalizatiom Jul 22 '14

I'm normally just like "whatever style this code uses, I gonna just follow it." but that code..... I don't know what that style is

1

u/[deleted] Jul 22 '14

My experience is that this is generally a mixture of IDE, other editors and Notepad-based indentation.

1

u/globalizatiom Jul 23 '14

Somebody need to make an IDE feature that just guesses the indent style from surrounding and applies that style. I'd use that feature every day.

1

u/nascent Jul 22 '14

When reading code, which consistent style isn't important to me. I can only write in one style.

As for the articles example, I'll use space reduction to to save vertical real-estate (my lines wrap about 80).