this post was submitted on 28 Jul 2024
1301 points (99.0% liked)

Programmer Humor

19623 readers
1 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] zalgotext@sh.itjust.works 10 points 3 months ago (1 children)

It does, but most style guides and autoformatters will use 4

[–] HK65@sopuli.xyz 11 points 3 months ago (1 children)

Python is one of the few languages with an official style guide, I think that guide says 4 spaces.

[–] northendtrooper@lemmy.ca 5 points 3 months ago (3 children)
[–] nexussapphire@lemm.ee 11 points 3 months ago (2 children)

I've set tabs to four spaces in vim because who the fuck defaults tab to eight spaces. That shit looks alien and pushes text off the screen fast.

[–] oscar@programming.dev 8 points 3 months ago* (last edited 3 months ago) (1 children)

Linux uses 8 spaces. Excerpt from the official style guide:

Tabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3.

Rationale: The whole idea behind indentation is to clearly define where a block of control starts and ends. Especially when you’ve been looking at your screen for 20 straight hours, you’ll find it a lot easier to see how the indentation works if you have large indentations.

Now, some people will claim that having 8-character indentations makes the code move too far to the right, and makes it hard to read on a 80-character terminal screen. The answer to that is that if you need more than 3 levels of indentation, you’re screwed anyway, and should fix your program.

In short, 8-char indents make things easier to read, and have the added benefit of warning you when you’re nesting your functions too deep. Heed that warning.

The reasoning seems sound, but I still prefer 4 personally.

[–] nexussapphire@lemm.ee 1 points 3 months ago

I don't develop kernel modules, I use python. That's pretty interesting though.

[–] ulterno@lemmy.kde.social 4 points 3 months ago

I set my clang-format to tabs only (actual tabs ASCII 0x9, no alignment and there is a continuation tab instead), then anyone can set their editor to whatever tab length they feel like and look at their code however they want.

But no spaces on the left of my code. This is for C, C++ and JSON.

[–] sukhmel@programming.dev 5 points 3 months ago

4 tabs is a bit overboard, don't you think?