this post was submitted on 28 Feb 2024
636 points (97.2% liked)

Programmer Humor

20703 readers
632 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 2 years ago
MODERATORS
636
wait what (pawb.social)
submitted 11 months ago* (last edited 11 months ago) by [email protected] to c/[email protected]
 
(page 2) 50 comments
sorted by: hot top controversial new old
[–] [email protected] 8 points 11 months ago

Yay at least this comment section has majority tab lovers!

[–] [email protected] 32 points 11 months ago (2 children)

Tabs exist specifically for spacing out stops. They're viewer-configurable, avoiding holy wars about 4 or 8 or that one idiot suggesting 3.

I do not give a shit if your seventeen-argument function has the overflow variables line up exactly with the paren. Just put them one step further in.

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

I just remembered the dumbest argument I've ever suffered about this - someone insisting the "length" of one tab changed, depending on what's before it. As in, is it eight spaces, or seven? Or six! It only goes up to eight spaces! No. It goes one stop. The same way a newline goes one line, and cannot by measured by how many times you'd slap the spacebar to get text to wrap around to the next line.

load more comments (3 replies)
load more comments (1 replies)
[–] [email protected] 19 points 11 months ago (3 children)

Spaces are supiror because its easier to text boxes.

I mean where even is the tab on my phone?

[–] [email protected] 5 points 11 months ago* (last edited 11 months ago)
[–] [email protected] 20 points 11 months ago* (last edited 11 months ago)
Right  
	here

Edit: til tabs make code blocks in lemmy

[–] [email protected] 13 points 11 months ago (2 children)

Another person who codes on their phone.

I bow to your greatness.

[–] [email protected] 7 points 11 months ago

I actually does code a bit in phone(and only codes in phone) and still preffer tabs. Hate it when some editors auto spaceify it. Also you can have tabs on keyboard by installing abother keyboard app

load more comments (1 replies)
[–] [email protected] 73 points 11 months ago (4 children)

The sole purpose of the tab key is for instructing the editor to insert four spaces.

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

To insert a........ TAB. Not four or any n number of space but TAB

load more comments (3 replies)
[–] [email protected] 11 points 11 months ago (1 children)

Cycling through buttons, atl+tab, Ctrl+tab, some other fourth thing.

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

something something real linux users don't use gui and tab completion

load more comments (1 replies)
[–] [email protected] 18 points 11 months ago (2 children)

*three spaces.

Actually, let's make that two.

load more comments (2 replies)
load more comments (1 replies)
[–] [email protected] 44 points 11 months ago

Team Tab Supremacy Unite!

[–] [email protected] 43 points 11 months ago

Hell yeah tabs

[–] [email protected] 20 points 11 months ago

Feels relevant

Just make everything Shittier

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

Tabs are objectively the better choice as it allows each dev individually to decide tab width in their editors. Spaces in contrast don't allow this same flexibility as they are used for much more than simply indentation, for example you likely put a space after each argument or operator IE func(arg1, arg2) or 1 + 2.

[–] [email protected] 17 points 11 months ago (2 children)

Also, a lot of editors won't unindent on backspace of spaces indentation, so I end up messing up the indentation with a 3/4 indent

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

Autoformatter should fix that, unless you use python. (but even then they might fix it to the closest proper indentation level)

[–] [email protected] 6 points 11 months ago

Yeah you need an auto formatter, which is worse than not needing it. Also yes its terrible in python like languages

[–] [email protected] 9 points 11 months ago

Sometimes. I love auto formatting, I spam the shit out of it more than I spam save but it's definitely not perfect. It gets real confused with inconsistent indention like that. Especially with Python it'll fuckup

load more comments (1 replies)
load more comments (9 replies)
[–] [email protected] 6 points 11 months ago

The enlightened among us use spaces for indentation and tabs for alignment.

[–] [email protected] 214 points 11 months ago* (last edited 11 months ago) (3 children)

I know it’s a joke but I prefer the tab option. It’s easy to convert tabs to any particular spacing or code point width. It can also vary, if wanted, based on terminal or editor type.

People with worse eyesight can have a wider indentation while those who choose can opt for something more compact

[–] [email protected] 11 points 11 months ago

I agree, tabs are better but I have been using spaces for so long I can't even imagine switching to tabs. also I'd have to reformat all my abandoned projects.

[–] [email protected] 55 points 11 months ago* (last edited 11 months ago) (2 children)

Honestly I always preferred tabs for indentation and spaces for aligning. It doesn't break anyone's experience. And if somebody wants ~~two spaces for~~ a two-space-tab-width for indentation and other people prefer four. That will work just fine.

I hate seeing 2 space indents. Unreadable AF ( to me ). At least this way I can easily work in the same codebase without somebody being annoyed ( except for the crying about the tabs )

[–] [email protected] 10 points 11 months ago (1 children)

Why not tabs for both indentation and alignment? (Actually, I see indentation as just a specific use of alignment.) Word processors have been doing it for decades (and typewriters for over a century!). Surely we can convince our code processors to use user-definable, fixed position tabs instead of relative position "tab = x spaces".

Keeping the [TAB] character in the file then allows everyone the layout they like.

Or has working solo for 40 years fried my brain?

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

What I mean with tab = x spaces is only visually and not actually ( there will ( obviously) still be a tab character in my preference. Not sure if that was clear.

Because alignment are fixed characters compared to indentation. For indentation the only question is how many characters the next indentation needs to be.

For alignment it is not fixed. As an example of PHP code:

function test(&obj) {
$obj->doSomething()
....->doSomethingElse()
}

The dots would be spaces because in IDEs people generally use a font where every character is equally wide.

If I would tab again instead of spaces it could work out if my tab length display is ( for one or more ) adds up to the width of the variable $obj. If somebody else has a tab width of 2 rather than somebody who has 3. It would only align for one of the two people.

Does make sense? I typed it out after a gym session on my phone.

Additionally. The whole problem is resolved by using spaces for both alignment and indentation. But in the cursor would still jump one space at a time rather than the whole tab ( although there are keyboard shortcuts for jumping words which would jump all of em.

I don't know. Call me old fashioned. I like what I like :/

[–] [email protected] 4 points 11 months ago (2 children)

If I correctly understand what you are saying, you are describing "relative" tabbing, where /t moves a constant distance from the current position. I prefer "stopped" tabs where /t moves to the next tab stop. If my /t doesn't create the spacing/alignment I'm after, I just tab to the next position.

Thus, I would set mine with the first tab position (for indenting) at 1.5 cm and subsequent tab stops at 3, 4, 5, ... cm. That way I'd get perfect alignment with both fixed and proportional fonts.

I'd also set line-wrap or line-continuation to use a hanging indent based on the start position of the line being wrapped or continued.

I'd also set a boundary between code and comments so that lines always wrapped before the boundary and using the comment character at the end of a line would jump to the other side of the boundary with optional leaders (the characters, usually periods that connect the end/beginning of a gap). In an ideal world, I would be able to "hide code", pulling all the inline comments into a "hanging indent" structure with their "parent" comments.

Yes, before the advent of IDE editors and all the fancy intellisense stuff, I used word-processing software for coding. 😀

[–] [email protected] 2 points 11 months ago* (last edited 11 months ago) (1 children)

Correct. The way I'm used to it ( and how I thought the world worked ) is that the IDE gives tab a fixed length or characters. If you set it to 4 it would be the equivalent of 4 spaces or 4 letters or whatever.

If my tab is set to 4 it would take up the width of 4 characters. If I need two indentations I would press tab twice.

If bob then checks out my code and calls me a maniac and sociopath for using indentation and swears by "2", the code would just look more condensed. The alignment would still work out because that's done through spaces.

var user_name = "Bob"
var user_age[tab]= "Bob"

This would align the = for Bob, because it needs two characters to align and that's what his tab width is. It wouldn't align for me because my tab width is 4. So I would.pur two spaces instead of the . That way it is aligned for everybody regardless of their tab width settings.

The way you explain it sounds like how tabs works in MS Word ( or other word processors ).

I don't think I could work like that. I've only ever used IDEs to code ( regardless of how primitive they were back when I started). Interesting take though :D

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

The way you explain it sounds like how tabs works in MS Word ( or other word processors ).

That is exactly how they work, and after 40 years, I still struggle with the whole "tab as a shortcut for spaces" thing. It's not that I started with word processors, either, just that as soon I started working with them, everything got so much easier for me.

There are some code-specific things that keep me from just going back to a word processor, but I think our code editors are missing some useful features that are found in word processors.

[–] [email protected] 2 points 11 months ago

Generally I'm not very preoccupied with it as the IDE just formats it the way I like it on save :D.

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

If I correctly understand what you are saying

You did not, but he also picked an example that could be conflated with the 4-spaces issue.

They're talking about situations where you might want to align text by a number of spaces that isn't divisible by your tab size. I'll expand on their example:

function test(&obj, &obj2, &a) {
$obj->doSomething()
....->doSomethingElse()

$obj2->doSomething()
.....->doSomethingElse()

$a->doSomething()
..->doSomethingElse()
}

Again, dots are "visible spaces" in this example, and being used to align chained methods with the length of the object name.

[–] [email protected] 4 points 11 months ago* (last edited 11 months ago)

Edit: Bear with me while I sort out the difference between my display and the resulting code block. Ok, close enough.

Ok, thanks. I would instead (and prefer to ) do something like this:

function test(&obj, &obj2, &a) {
$obj---->doSomething()
---->--->doSomethingElse()

$obj2--->doSomething()
---->--->doSomethingElse()

$a-->--->doSomething()
---->--->doSomethingElse()
}

In this case, the ">" are showing the tab stops and the "-" the resulting white space. Note how all the calls are lined up. (My preferred alignment style, not necessarily anyone else's.)

Yet another edit: I see that I missed addressing alignment on other than tab boundaries. To me, that's just sinful! 😀

load more comments (1 replies)
load more comments (1 replies)
[–] [email protected] 39 points 11 months ago (5 children)

I can't imagine it would be difficult for an IDE to scale the width of spaces found at the start of a line, to emulate this same customization while still preserving my sanity as a fervent space-indenter. I've never seen an IDE that does this, but it'd be an interesting compromise.

[–] [email protected] 26 points 11 months ago (1 children)

It's not difficult at all, and many editors and IDEs already support this, making the entire point moot. Just do whatever the style guide says. I'm into PHP and Python so for me it's spaces all the way.

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

How can it tell the difference between spaces used for indentation and spaces used for alignment, if you use the same character for both?

[–] [email protected] 2 points 11 months ago

All parsers ignore a shitload of whitespace already. Just compare unformatted code, COMPLETELY unformatted code, code without character returns, and it'll become obvious how any given language is interpreted around whitespace.

Also fun to see just how infrequent a semicolon is 'actually' needed to tell when the end of a statement is here.

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

Maybe alignment more for the righthand side of assignments. If you have a block of variables with different name lengths, or within a constructor / function call.

[–] [email protected] 8 points 11 months ago

I guess the indention sizer thing knows how the formater works and adjusts accordingly. I can't imagine it would be too much of a problem.

Iirc Jetbrain IDEs has a feature called dynamic tabs/space (or something like that) which uses exclusively tabs until it needs to align something and a tab doesn't fit, so it uses a few spaces instead.

load more comments (4 replies)
[–] [email protected] 17 points 11 months ago* (last edited 11 months ago)

Man how are we gonna write all of our Whitespace programs now?

load more comments
view more: ‹ prev next ›