this post was submitted on 17 Jun 2023
150 points (98.7% liked)

Programmer Humor

31260 readers
1055 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 4 years ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 21 points 1 year ago (4 children)

I use tabs because I prefer 4-space indents and others might prefer 2-space indentation or the gross and unacceptable 6-space indentation.

If more than one person is working on a code base, there will likely be more than one preference, and with tabs everyone gets to just set their own tab width.

Yes, even the 3-space savages.

[–] [email protected] 6 points 1 year ago (2 children)

Tabs work fine as long as you don't align stuff. If you do, you have to assume a tab size and mix tabs and spaces.

[–] [email protected] 13 points 1 year ago* (last edited 1 year ago)

Generally aligning stuff isn’t nice. But if you do, it’s tabs up to whatever level of indentation you’re at then spaces the rest of the way. So you wouldn’t have to assume a tab size. And the tabs and spaces have different semantic meaning (indent vs alignment) so mixing them makes sense. It's even built into Jetbrains IDEs, where it's called "Smart Tabs".

Although really just adding a level of indent is better than aligning.

[–] [email protected] 3 points 1 year ago

This is a legit observation. However, I would argue that spaces needs a set indentation width anyway, so if tabs had a set indentation width that coders are expected to maintain when aligning code, it wouldn't make a difference. Enforcing that in practice may be different, but in theory it works.

load more comments (3 replies)
[–] aaaantoine 21 points 1 year ago (1 children)

That's because these programmers are getting paid by the character.

This is also why Java dev pays so well.

[–] [email protected] 7 points 1 year ago (2 children)

System.out.println("Wow, so little amount of characters to print this!");

[–] [email protected] 7 points 1 year ago (1 children)

Or the slightly more readable brainfuck:

++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.

[–] [email protected] 2 points 1 year ago

Hey! Brainfuck is a fun puzzle language and nothing someone does at a job to do money per character. Would be funny if yes

[–] [email protected] 4 points 1 year ago (2 children)

std::cout << "Wow, so little amount of characters to print this!" << std::endl;

[–] [email protected] 5 points 1 year ago (1 children)
[–] [email protected] 6 points 1 year ago

p "Ruby FTW!"

[–] [email protected] 3 points 1 year ago

std::puts("Why do so many C++ programmers not use the right tool for the job?");

[–] [email protected] 17 points 1 year ago (1 children)

Seven semicolons are the correct way to do indentation (it even alliterates):

int main
(void) {
;;;;;;;printf("like this\n"); }
[–] [email protected] 7 points 1 year ago* (last edited 1 year ago)

the correct way is to never indent and never use whitespace. Saves memory.

Your goal should be 1LOC every month, no more.

[–] [email protected] 14 points 1 year ago (3 children)

Is this some kind of python meme I'm too C++ to understand?

Now, I'm completely willing to start a war about { going on the next line.

[–] [email protected] 9 points 1 year ago (1 children)

It goes on the line! If you put it below, you're wasting a line for no extra readability!

[–] [email protected] 7 points 1 year ago (2 children)

It goes on the next line, so you can have open and close brackets at the same indent depth for easy visual matching.

[–] [email protected] 4 points 1 year ago (1 children)

Your closing } goes on a new line below at the same indent depth as the line containing the open {!

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago)
fn main() {
    println!("WTF?");
          }

PS: I know what you meant

[–] [email protected] 2 points 1 year ago

This, as it also helps when using % to go to the matching open/close bracket when the cursos doesn't jump all around the place..

[–] [email protected] 3 points 1 year ago* (last edited 1 year ago) (3 children)

Totally agree, all my { end up on the next line, 1st spot when starting a function, last character of the keyword when starting an if/for/... section. I even put the closing one on the same line when it's single line, else either at the end of the closing line (when changing really old code) or same indent.

So indenting varies a lot, which makes most 'new' programmers go mental.

while (my code)
    { I'll do it my way }

if (! liked)
 { toughen-up }
else
 { get used to it
   multi-line can go both ways...
 }

That is, unless the font used messes it up. ;)

[–] [email protected] 2 points 1 year ago

That’s horrible.

load more comments (2 replies)
[–] [email protected] 2 points 1 year ago

Wonder what the x-axis is? Survey year? Years of experience? Caffeine intake?

Anyway, I can hardly join a holy war -- I code in assembly most comfortably, which I'm pretty sure is heresy these days.

[–] [email protected] 13 points 1 year ago* (last edited 1 year ago) (6 children)

Tabs make more sense because that’s exactly what they’re for, indents. Ignoring how it looks, which makes more semantic sense for an indent, or ? You wouldn’t use a bunch of spaces to indent a paragraph, so why would you use it to indent code?

[–] [email protected] 8 points 1 year ago (1 children)

And by using tabs the IDE can customise whether it's displayed as two character or four character deep indentation. It just makes so much more sense.

It's insane that anyone considered spaces to be a sensible default. Yet I primarily develop in C# where four spaces are the standard so that's what I use. However the reality is the IDE handles all the formatting automatically so I'm never actually typing four spaces

[–] [email protected] 2 points 1 year ago

Just don't use IDE

load more comments (5 replies)
[–] [email protected] 13 points 1 year ago (2 children)
[–] yads 14 points 1 year ago* (last edited 1 year ago)

That's cause they pay us by the byte the suckers.

[–] [email protected] 6 points 1 year ago (1 children)

Imagine not using a minifier

load more comments (1 replies)
[–] ZachAR3 13 points 1 year ago (1 children)

Is there any actual advantage to using spaces? I have seen similar posts for a while and as a tab user I don't understand why they are any better than just a tab

[–] [email protected] 15 points 1 year ago* (last edited 1 year ago)

The indentation always looks the way you wrote it even in raw text viewers, is generally the argument.

[–] [email protected] 13 points 1 year ago (1 children)

I'd imagine it's because people who use spaces are either further in their career in average (because the modern programming ecosystem in general uses tabs so new devs are more likely to only know that) or they're just more serious about software development because the kind of person to die on that hill is also the kind of person who is very obsessive about other things as well.

[–] [email protected] 8 points 1 year ago (1 children)

Wait. Are tabs used more often in modern stuff? Almost everything I use does spaces and I'm not that new to programming. Been doing it for maybe 5 years. I use spaces in everything but Go.

[–] [email protected] 6 points 1 year ago (2 children)

Most text editors people use (like VSCode) generally automatically adjust tabs to be whatever the standard indent is for the project (and convert to spaces if it's necessary). As a result, indenting with tabs usually just works, and so most people just learn to do it that way. Also people are used to using tabs for indent from things like Word which they used before learning to write code. As a result, I've noticed most people use the tab key (even if their not technically "using tabs" every time they do it).

[–] [email protected] 5 points 1 year ago (1 children)

I think the deeper generational thing is in the idea that anything "just works". Like I'm a programmer, right, so I know shortcuts. Ctrl+S saves the file, simple right?

Me when I want to save a file: Ctrl+SSSS. Why? Because I don't trust it "just works". Same reason I don't trust auto save. Same reason I am stunned every time I tell windows to diagnose and fix the network problem and then it actually does.

I grew up in a time where you couldn't trust any of that shit.

[–] [email protected] 4 points 1 year ago

I generally trust things that "just work" so long as I know why and under what conditions.

[–] [email protected] 3 points 1 year ago (1 children)

Yeah, I have my tab key set up to insert spaces. I meant the characters being used, not the key used to write them.

load more comments (1 replies)
[–] [email protected] 11 points 1 year ago

[ ] tabs [ ] spaces [x] why would I even care, I press tab and the editor puts either a tab or a number of spaces, couldn't care less...

[–] Korne127 6 points 1 year ago (3 children)

Someone here made a longer explanation in a blog post why it's that way and what this corresponds to: https://evelinag.com/blog/2017/06-20-stackoverflow-tabs-spaces-and-salary/index.html

load more comments (3 replies)
[–] [email protected] 6 points 1 year ago

I'd assume this is a product of space users being older and thus earning more, but that is wild speculation.

[–] Crackhappy 5 points 1 year ago
[–] [email protected] 4 points 1 year ago

So the two camps are:

spaces: who want to be able to have accidental fractional indentation and so they can force anyone who may read their code in the future to see the indentation at the size that they intended.

tabs: who want consistent bug-resistant and logical formatting, and for any future reader to decided for themselves thier own personal best indentation size.

A possible explanation: people who want it their way at the expense of others are more likely to choose spaces, and are more likely to feel at home at a company that does exactly that in order to extract more profit from thier victi... customers.

[–] le_saucisson_masque 3 points 1 year ago* (last edited 1 year ago) (1 children)

Casualty / coincidence

Edit: causality/coincidence

[–] [email protected] 2 points 1 year ago (2 children)

Did you mean "causality" ?

load more comments (2 replies)
[–] Crackhappy 2 points 1 year ago (1 children)
[–] [email protected] 3 points 1 year ago

Down to fuckness? I suppose a greater score on this metric might help career in certain specific circumstances.

load more comments
view more: next ›