Tabs v(ersu)s Spaces from Silicon Valley S3E6

MilkmanDansays...

(**EDIT** hmm, code HTML tag doesn't seem to allow whitespace to show at the beginning of lines, so I'm replacing spaces with _underscores_ in the pseudocode below)

Code uses spaces or tabs to visually distinguish the flow of the program, what code belongs to what functions / loops / whatever.

Here's some C-style "pseudocode" that should get the idea across:

void function fizzbuzz {
__for (i = 1; i <= 100; i++) {
____set print_number to true;
____If i is divisible by 3
______print "Fizz";
______set print_number to false;
____If i is divisible by 5
______print "Buzz";
______set print_number to false;
____If print_number, print i;
____print a newline;
__}
}


The braces { } show the beginning and ending of a "function" (essentially one of potentially many self-contained algorithms in a program) and the beginning and ending of a "for loop" (that will repeat the code inside it some number of times). And the "if" statements will only perform the stuff after them IF the test they perform evaluates to true.

So in that pseudocode, there's sort of 4 tiers or things going on. First is the function (named "fizzbuzz"). Since functions are kind of the most basic structural unit of the code, they are on the far left -- not indented at all. Sorta like Roman Numerals in an outline.

Then, the actual content of that function (the code that makes up its algorithm) is set a consistent amount of space to the right to make it clear that it is contained inside the function. That can be done with *1* tab, or some consistent amount of spaces so that it lines up. The only thing in that tier is the "for loop" and the braces that show its beginning and end.

Then the content of the for loop is set a bit further to the right (with another space or another set number of spaces). All of the "if" statements are at that 3rd tier level, along with a bit more code at the beginning and end. Then, the actual content of the if statements is set one more tier to the right to help distinguish that it will only run IF the conditions are met.

That pseudocode uses spaces for all of the tiering -- 2 spaces per tier. I'm a tab person like the guy Richard in the video, because it seems easier to press tab once per tier than hitting the spacebar 2/3/4 times per tier. But it really is just a personal preference issue, because as he said in the video, by the time the code is compiled (turned into an executable file that the computer can run) the final result will be the same whether the programmer used spaces or tabs.

But like with many things, Silicon Valley really hits the nail on the head here. Programmers tend to be very set in their ways and anal about their style preferences for code. If we have to go through someone else's code that doesn't follow our style conventions exactly, it kinda tends to throw us out of whack. To make an analogy with something less nerdy, consider how annoying it can be when someone borrows your car and you have to adjust the seat / mirrors / radio stations etc. when you get back in.

eric3579said:

Don't think i've ever used a tab outside filling in a form or playing video games. Does the tab thing have more to do with writing code?

billybusseysays...

You would think I would be happy that there's a show about my town. But this show looks like shit. I couldn't get through one episode. WTF is wrong with you all? What a shame.

TheFreaksays...

I would be much more annoyed that you're trying to talk to me while I'm coding. "Pair Programming", that's different. But if you want to talk about the show you're binging on Netflix...fuck off, I'm in a groove here.

Buttlesays...

It does have to do with writing code.

I have to deal with a source code repository that's full of tabs at work every day. Indentation for code may be composed of spaces and tabs, or spaces only. If tabs are present, then everyone working with the code has to use the same tab width setting, otherwise the indentation will be fubar.

If two people save edits using a different tab width setting, then there really is no way of fixing it up beyond auto-indenting it all and saving with a consistent tab setting.

The advantage of tabs is saving a few bytes on file size, which is completely undetectable in today's world of html email and xml everything.

The film, however, makes no sense, because the only way you can find out about a fundamental disagreement on spaces v tabs is by opening someone else's file in your editor, and finding the indentation all messed up. It's not something you can tell by looking over a shoulder.

The difference between emacs and vi, by the way, is that emacs has several good vi emulations, but it would be laughable to think of an emacs emulation in vi.

Emacs used to seem a completely outsized pig of a program, but in our modern times it's actually tiny. Still, you would expect a vi-champion to want tabs instead of spaces, not vice versa.

Not a lot of understanding displayed here, I'm afraid.

eric3579said:

Don't think i've ever used a tab outside filling in a form or playing video games. Does the tab thing have more to do with writing code?

MilkmanDansays...

I thought it was pretty clear in the show that he knew she was using spaces instead of tabs because of the sound of her repeatedly hitting the spacebar at the beginning of each line (which depending in your editor/IDE might be done automatically).

They are in a small environment, (loosely?) collaborating on code. He's anal about tabs vs spaces, and can tell that she's using the "wrong" one because of the repetitive (and annoying from his perspective) sound.

Put programmers together in a confined space, and they'll grate on each other over style issues / noise levels / music / whatever. I find the show extremely accurate in portraying the general atmosphere or feel of software development, if occasionally accenting or misportraying some details in the interest of making it good TV.

Buttlesaid:

The film, however, makes no sense, because the only way you can find out about a fundamental disagreement on spaces v tabs is by opening someone else's file in your editor, and finding the indentation all messed up. It's not something you can tell by looking over a shoulder.

Buttlesays...

In my experience as a working programmer, tabs v spaces is a question of editor configuration, not typing. So, no, I don't believe he could hear it.

Conforming to the local convention on tabs v spaces isn't being anal, it's showing you want to keep your job. In particular, throwing in tabs where they are not expected results in unreadable hash.

MilkmanDansaid:

I thought it was pretty clear in the show that he knew she was using spaces instead of tabs because of the sound of her repeatedly hitting the spacebar at the beginning of each line (which depending in your editor/IDE might be done automatically).

They are in a small environment, (loosely?) collaborating on code. He's anal about tabs vs spaces, and can tell that she's using the "wrong" one because of the repetitive (and annoying from his perspective) sound.

Put programmers together in a confined space, and they'll grate on each other over style issues / noise levels / music / whatever. I find the show extremely accurate in portraying the general atmosphere or feel of software development, if occasionally accenting or misportraying some details in the interest of making it good TV.

lucky760says...

https://stackoverflow.blog/2017/06/15/developers-use-spaces-make-money-use-tabs/

Was just having this discussion the other day.

It's one of the very rare things where a Mike Judge product doesn't make much sense [unintentionally].

It's nonsensical argue for a smaller file size. But on the other side of the coin, it screws everyone else up if you use tabs because then whenever other developers open the file and they [rightly] use spaces, they're screwed.

Anyway, check out that link I included above. The comparison between income of US developer and India developer is shocking.

MilkmanDansays...

@lucky760 -
I still think Judge is actually presenting the situation pretty accurately. If you look up online forum posts about tabs vs spaces, the file size thing is brought up as a pro for tabs very regularly.

While it is technically true, you're right that it doesn't make much sense because the difference is *tiny*, so conforming to the standard of wherever you are working is vastly more important.

BUT, that doesn't stop individual programmers from being (irrationally) passionate in their preferences.

Another dynamic that is (correctly) displayed in the show in my opinion is the difference between a big corporate environment, working as an individual in a large team of programmers as compared with having a project that starts out as a the brainchild of one person and grows into a small team.

The show is about the latter. In that scenario, a programmer / software engineer ends up trying to also be a manager of a team, in spite of the fact that he isn't really built for it. In a big corporate environment, they are well aware that style issue conflicts can turn into big time wasters unless they set out guidelines clearly at the outset. But that sort of micro-managing is NOT what a pure engineer type is comfortable doing.

Basically, I think that tabs vs spaces is completely a personal preference issue if you're working alone OR on a small team that don't interact with each other's code much. And even on a large team, either choice is fine BUT it becomes important to conform to the standards of the team as a whole.

ChaosEnginesays...

Oh, it's on! If you don't indent your code, you are like Hitler multiplied by Trump.

Anyway, to clear up any remaining confusion:

1. In theory, use whatever the code base is already using. Having a tabs vs spaces fight is a pointless waste of time. In practice, anyone who uses tabs should be fired immediately.

2. No-one actually types out 4 spaces. You press the tab key and it inserts spaces for you. Either that or you are so incompetent at using your tools that you should be fired immediately.

There you go. The complete and definitive guide to tabs (you're fired) vs spaces (correct).

Not that I'm biased.

Jinxsaid:

I don't indent at all.

Fight me.

Buttlesays...

I have to disagree with this. If you're working with even a team of two, you have to edit someone else's source code, and tabs v spaces has to be agreed upon. There are a lot of other, more entertaining questions of formatting that have to be settled upon, not to mention how to name things: CamelCase versus under_scores.

Any halfway competent programmer figures out the local standards by observation and follows them. Anything else is an indication that she just doesn't give a shit about getting along with co-developers.

MilkmanDansaid:

Basically, I think that tabs vs spaces is completely a personal preference issue if you're working alone OR on a small team that don't interact with each other's code much. And even on a large team, either choice is fine BUT it becomes important to conform to the standards of the team as a whole.

gwiz665says...

In a closed environment you should use what you agree on and stick to it. Whether it's tabs or spaces doesn't really matter, depending on what language/editors are in play. VIM vs Emacs is a waste of time, as professionals have to use something like Visual Studio anyway.

We use tabs.

ChaosEnginejokingly says...

Yeah, but let's be honest. If they use tabs, do you really WANT to get along with them?

You should view this as an opportunity to enlighten the heathen bastards so they will see the error of their ways.... by fire if necessary.


Buttlesaid:

Any halfway competent programmer figures out the local standards by observation and follows them. Anything else is an indication that she just doesn't give a shit about getting along with co-developers.

MilkmanDansays...

I understand where you're coming from, but I stand by my previous posts.

Full disclosure, I never got professionally employed as a programmer / coder / software engineer. However, my Bachelors Degree was in CS, and I have many friends working in the field.

In the show Silicon Valley, Richard Hendriks is working for a large corporate entity but has an idea / personal project that he ends up spinning into a new company. He is trained as a software engineer (CS), NOT with any business or management background (MIS), yet he becomes sort of the de-facto boss / CEO (at least early in the show). He hires a small team to help him develop his product.

Given that scenario, I think the show portrays things very accurately or at least completely plausibly. He's a coder, not a manager. Programmers may understand the importance of formatting and style standards, but at least tend to not have the correct personality type to be comfortable with formally dictating those standards to a team (an activity which would generally be more in line with an MIS background).

Also, his company is small -- just a few other programmers. They are all specializing on different components of the product. So they generally aren't working on each other's code. Standards for function arguments / helper functions / etc. would have to be agreed upon to get their individual components to interact, but that is a separate issue from tabs vs spaces. It would be wise to set a style and naming convention standard and have everyone conform to it, I agree completely. But Richard isn't built for the manager / CEO position, so he either fails to recognize that or doesn't feel comfortable dictating standards to his team.

One more thing to consider is that he (Richard) essentially is the product. He's the keystone piece, the central figure. He's John Carmack, Linus Torvalds, or Steve Wozniak. Even in a very large team / corporate environment, I'd wager that more often than not the style standards that end up getting set tend to fall in line with whatever those key guys want them to be. Don't touch an id Software graphics engine without conforming to Carmack's way, or the Linux kernel without conforming to Torvald's standards. Especially if they are building something new from scratch -- which is again true in the Silicon Valley show scenario.

The show isn't a documentary on how to properly run a startup company in the real Silicon Valley, but it is generally accurate enough that it has a lot of nuances that people with a programming background can pick up on and be entertained by (even people that don't actually work professionally in the field like me). And more important, the general feel of the show can be entertaining even for people that know absolutely nothing about programming.

Buttlesaid:

I have to disagree with this. If you're working with even a team of two, you have to edit someone else's source code, and tabs v spaces has to be agreed upon. There are a lot of other, more entertaining questions of formatting that have to be settled upon, not to mention how to name things: CamelCase versus under_scores.

Any halfway competent programmer figures out the local standards by observation and follows them. Anything else is an indication that she just doesn't give a shit about getting along with co-developers.

MilkmanDansays...

I guess you wouldn't be amused by "one liner" programs like this one:

main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return*t-42?*s?63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}



(no way in hell I could figure out what that is doing without the description on Wikipedia, and even then...)

ChaosEnginesaid:

Oh, it's on! If you don't indent your code, you are like Hitler multiplied by Trump.

eric3579jokingly says...

Anyway, what good is any of this unless you can figure out mean jerk time...just sayin


ChaosEnginesays...

That scene cracks me up every time.

@MilkmanDan nah, those are awesome. My favourites are the insane 99 bottles competitions:

#include <stdio.h>
main(){_=100;while(--_)printf("%i bottle%s of beer in the wall,\n%i bottle%"
"s of beer.\nTake one down, pass it round,\n%s%s\n\n",_,_-1?"s":"",_,_-1?"s"
:"",_-1?(char[]){(_-1)/10?(_-1)/10+48:(_-1)%10+48,(_-1)/10?(_-1)%10+48:2+30,
(_-1)/10?32:0,0}:"",_-1?"bottles of beer in the wall":"No more beers");}

eric3579said:

Anyway, what good is any of this unless you can figure out mean jerk time...just sayin

bcglorfsays...

Brings to mind one of my favourite quotes:

Arguing over vi versus emacs is like arguing about whether it's better to start a fire by banging rocks or rubbing sticks.

L0ckysays...

Number 1 line in my coding standards docs:

Don't play golf.

Number 2:

Don't care about the conventions, only care about sticking to them.

MilkmanDansaid:

I guess you wouldn't be amused by "one liner" programs like this one:

main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return*t-42?*s?63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}



(no way in hell I could figure out what that is doing without the description on Wikipedia, and even then...)

Buttlesays...

I have to ask myself that at work, and the answer is: if I'm going to get fired for something, spaces v tabs is just too silly.

ChaosEnginesaid:

Yeah, but let's be honest. If they use tabs, do you really WANT to get along with them?

You should view this as an opportunity to enlighten the heathen bastards so they will see the error of their ways.... by fire if necessary.

ChaosEnginesays...

Just in case anyone actually thinks I was being serious, I'm not.

Tabs, spaces, line feed, em... I could not care less as long as the code is readable.

But seriously..... spaces.

Kidding.

(or am I?)

Buttlesaid:

I have to ask myself that at work, and the answer is: if I'm going to get fired for something, spaces v tabs is just too silly.

Buttlesays...

I can't speak to the quality of the show, although it's hard to go wrong with Mike Judge.

Spaces v tabs seems like a fine thing to joke about. I just couldn't suspend disbelief about how it came up. Here's the sort of thing that really happens:

Bob opens one of Shiela's files, just to read it so he can figure out how something works. He sees gibberish for indentation, and says, "Hey, Shiela, what happened to lose_harder.cc?
The indentation is all wrong."

She doesn't know what he's talking about, and takes offense that lasts for most of the rest of the episode. Eventually she figures out what he's complaining about, and says "What's your tab width? I used 3, to optimize file size with our typical indents". Bob says "How should I know what my tab width is? Why should I care? Are you mental? Three?"

MilkmanDansaid:

I understand where you're coming from, but I stand by my previous posts.

Send this Article to a Friend



Separate multiple emails with a comma (,); limit 5 recipients






Your email has been sent successfully!

Manage this Video in Your Playlists




notify when someone comments
X

This website uses cookies.

This website uses cookies to improve user experience. By using this website you consent to all cookies in accordance with our Privacy Policy.

I agree
  
Learn More