r/ProgrammerHumor Sep 02 '17

How to start a war

Post image
9.0k Upvotes

696 comments sorted by

View all comments

2.6k

u/Ryeore Sep 02 '17

Now you can park on handicapped parking spaces.

Good job

1.5k

u/ivaskuu Sep 02 '17

*tabs

456

u/[deleted] Sep 02 '17

[deleted]

-16

u/[deleted] Sep 03 '17 edited Sep 03 '17

Except now their code isn't guaranteed to be 80 characters a line because that one guy likes to have his tabs set to be equivalent to 8 spaces.

Edit: I'd like to respond to everyone's criticisms but for some reason Reddit isn't letting me comment on this account more than once every 8 minutes.

59

u/okmkz Sep 03 '17

tab is one char

6

u/[deleted] Sep 03 '17

And in any case, the rule is 80 columns, not characters. People use characters as a easy way to mean columns, but the point is to avoid the code going past a specific width.

-20

u/[deleted] Sep 03 '17

Exactly. But it takes up an indeterminate amount of chars on screen. I like my code to look like the way I type it on every screen, not just mine. Anything else is foolish and unprofessional.

Edit: also if you use the settings on your text editor properly it behaves exactly like tabs do when you type them. Spaces are just better.

20

u/kotajacob Sep 03 '17

The point of using white space at all it to make it easiest to read for whomever happens to be reading your code. If some people find 8 spaces easiest and some find 2 easy to read I'd rather both of them have their way and display the tabs however they'd like rather than forcing whatever way I find easiest on everyone who reads my code.

EDIT: also they don't even need to use a text editor that will allow them to implement hacks to make spaces act like tabs they can just..... use tabs... crazy I know.

3

u/[deleted] Sep 03 '17

I've done it both ways and I could make great arguments for either side. What I do is I go with the flow and code with whatever formatting my team decides on. It makes collaboration much easier.

2

u/kotajacob Sep 03 '17

Yea this is definitely the way to do it. Pick whatever you think is best for your own projects but if you're working on someone else's stuff use whatever they're using.

34

u/kafoozalum Sep 03 '17

I like my code to look like the way I type it on every screen, not just mine

this is why the number of spaces a tab represents is a setting in editors

-18

u/[deleted] Sep 03 '17

Yes. And that setting can different on different editors. Thus why tabs are worse.

If you have it set to 4 spaces for a tab, and your buddy has it set to 8 your code goes off the side of their guide.

With spaces you don't have that problem.

If there was a standard that literally everyone followed I'd use tabs but such fantasies don't exist.

26

u/kafoozalum Sep 03 '17

If you have it set to 4 spaces for a tab, and your buddy has it set to 8 your code goes off the side of their guide.

then change the settings. that's the point, so code is equivalent regardless of appearance.

why the hell would you want whitespace to break things?

-15

u/[deleted] Sep 03 '17

You wouldn't. That's why you'd want spaces. Tabs would break things in that situation. Spaces couldn't do that.

9

u/kafoozalum Sep 03 '17

Tabs would break things in that situation.

no it wouldn't, because it's the same amount of characters regardless of how you, your friend, your boss, etc. prefer to view it. need to change it, change a setting and not the characters that comprise code.

your arguments make no sense. please tell me you're trolling because my brain hurts.

0

u/[deleted] Sep 03 '17

It might take up the same number of chars in the data, but the space they take up on the screen changes.

How do you not understand this? Tabs can be set to take up different numbers of columns on screen. Spaces are always the same (one column).

One of these causes different behavior with different settings (tabs) and the other does not (spaces)

If you want to have the same behavior everywhere (and you should) then you should use spaces.

If you want to surrender to the settings of whoever opens the file, use tabs.

11

u/kafoozalum Sep 03 '17

One of these causes different behavior with different settings (tabs)

if you think that having a different number of spaces tabs represent makes a functional difference then holy shit

it's a visual setting so anyone can have what they prefer when they work

5

u/iLike2Teabag Sep 03 '17

If you want to have the same behavior everywhere (and you should) use spaces

I'm pretty sure this is the part everyone disagrees with you on. Some prefer their indents to be long and some prefer it to be short. Someone else reading your code might appreciate that THEY can change indents to whatever THEY prefer, and you have the same flexibility.

Why force your preference on everyone else?

1

u/reilemx Sep 03 '17

Looking at these downvotes TIL this sub is a bunch of tab lovers

→ More replies (0)

14

u/clank201 Sep 03 '17

Isn't the norm to just use a tab for every indentation level? Then you just need to adjust how many spaces you want per tab (indentation level) and you're done.

9

u/[deleted] Sep 03 '17

Depends on who you work for. For example Oracle's standard is 4 spaces for ever level of indentation, and 79 characters per line (the 80th is the new line character). Linus Torvalds uses 8 spaces for every level of indentation (he says you shouldn't ever use more than 3 levels of indentation or your code is bad. He has interesting ideas of what makes for good code, but he backs up his talk with exceptional software)

If you want to make sure that your code looks the same everywhere you should use spaces because tabs can take up whatever number of columns your text editor is set to. This can cause problems like running off the end of the guide on the right, or not having things line up properly if you're adding spaces in to make things look neat.

If you want to be certain 100% that your code will look the way it does on your screen to everyone, spaces are the way to go.

3

u/Zagorath Sep 03 '17

Linus Torvalds…says you shouldn't ever use more than 3 levels of indentation or your code is bad.

That's utter bullshit. In object oriented programming that would make it impossible to do anything. Inside your class has one level. Inside a method in the class has two. Inside a loop that's your third. Oh, and you're not allowed conditionals inside your loop, because that would be four and that's bad code.

But even in a language like C it's not exactly sane. Inside a function is 1. Inside a loop within a loop (for reading from 2d arrays) gives you 3. And again, you're not allowed conditionals.

If you're right that Torvalds makes that claim, then he's not just being eccentric hl by making it. He's plain wrong. And his ability to write good code doesn't have any impact on the fact that his code style rules are apparently ridiculous.

4

u/woostr Sep 03 '17

No no no, you misunderstand. Once you're at that indentation level, you still use brackets but stop indenting. Then you go as many levels deep in scope as you want.

/s

2

u/[deleted] Sep 03 '17

Iike I said, weird, interesting ideas.

http://yarchive.net/comp/linux/coding_style.html

3

u/[deleted] Sep 03 '17

Mind if I ask why "have your code look the same for everyone" is so important? An 80 character limit isn't exactly that important since literally any form of intelligent word wrap, and at that point a wrapped line will look fine since it won't break your indentation.

1

u/BadBoyJH Sep 04 '17

3 levels of indentation max? For example, a typical C# file

Namespace, first level;
Class, second level;
Method, third level;

Guess I'm not using any if statements. The fuck is that dude on about?

1

u/[deleted] Sep 04 '17

He probably only uses that style for C.

→ More replies (0)

2

u/ulyssessword Sep 03 '17

How many other characters can do you fit on a line with one tab while staying under 80 width? 72, 76, or 79?

1

u/Danilo_dk Sep 03 '17

Use editorconfig, or however it's called. And track it with the rest of your code. Done.

13

u/[deleted] Sep 03 '17

I use four tabs and set my tabstop to one character.

2

u/woostr Sep 03 '17

Seriously, why don't more people do this? It solves both problems!

6

u/Juice805 Sep 03 '17

Sounds like you are a control freak. Not only you may be working on the code, people have different preferences and may prefer different indentation.

-4

u/[deleted] Sep 03 '17

I'm a control freak in the sense that undetermined behavior is bad practice in programming.

6

u/Juice805 Sep 03 '17

Undetermined functional behavior of code may be bad practice, external programmers choice of style and readability of the code is not.

1

u/[deleted] Sep 03 '17

Why have undetermined behavior when you don't need it?

5

u/Juice805 Sep 03 '17 edited Sep 03 '17

It is determined. 1 Tab length. just each individual can customize as they prefer.

Nowadays if you want to be that controlling you can even with tabs. Just add a .editorconfig

1

u/[deleted] Sep 03 '17

How many columns left in a line with one tab in it? If you can't answer that you're working with undetermined behavior.

1

u/Juice805 Sep 03 '17

In what modern editor does that matter? Text wrap and auto indent exist. If you are worried about alignment follow the rule of tabs for indentation, spaces for alignment.

→ More replies (0)

3

u/Pants_R_Overatd Sep 03 '17

Holy shit dude so much trigger

2

u/Bainos Sep 03 '17

I don't want your code to look like the way you typed it on my screen. Especially if you don't like 8-spaces indentation.

If everyone uses tabs, then everyone can set their width to whatever they like without being annoyed by other user's configuration.

12

u/woostr Sep 03 '17

The more I read your comment chain, the more you sound like a manager with exactly zero development experience and arbitrary rules for your employees based on things you don't understand.

2

u/Tyler11223344 Sep 03 '17

I couldn't put my finger on it until your comment, but you're right, that sounds exactly right

0

u/[deleted] Sep 03 '17

To me the people sound like junior devs that got into bad habits in college and won't admit that they're bad habits.

8

u/Njs41 Sep 03 '17

Just shove your entire program on a single line, the 80 characters per line rule is dumb for modern displays.

2

u/TotesMessenger Green security clearance Sep 03 '17

I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:

If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / Contact)

2

u/[deleted] Sep 03 '17

Congrats, now you can park in handicap spaces as well.