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

Programmer Humor

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

[โ€“] [email protected] 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! ๐Ÿ˜€

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