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

Programmer Humor

19670 readers
212 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
637
wait what (pawb.social)
submitted 8 months ago* (last edited 8 months ago) by [email protected] to c/programmer_humor
 
you are viewing a single comment's thread
view the rest of the comments
[โ€“] jadero 4 points 8 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] 5 points 8 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.

[โ€“] jadero 4 points 8 months ago* (last edited 8 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! ๐Ÿ˜€

[โ€“] [email protected] 2 points 8 months ago* (last edited 8 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

[โ€“] jadero 4 points 8 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 8 months ago

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