this post was submitted on 28 Jul 2024
1294 points (99.1% liked)

Programmer Humor

19564 readers
1072 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
[–] victorz 13 points 3 months ago (10 children)

I thought python allowed whatever indentation you wanted as long as it's consistent?

[–] [email protected] 10 points 3 months ago (8 children)

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

[–] [email protected] 11 points 3 months ago (7 children)

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

[–] [email protected] 5 points 3 months ago (3 children)
[–] [email protected] 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.

[–] [email protected] 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.

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

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

[–] [email protected] 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.

[–] [email protected] 5 points 3 months ago

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

load more comments (3 replies)
load more comments (3 replies)
load more comments (4 replies)