this post was submitted on 09 May 2024
458 points (92.4% liked)

Programmer Humor

32448 readers
944 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 12 points 6 months ago

You get one level at the get go because everything is in a function. So just two levels of indentation? A pretty basic if.. for..if nesting has to be refactored? Into what? Goto? Should I sprinkle return statements all over the place?

Y’all gotta understand that Linus is often kind of an ass.

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

rules aren't there to be enforced, they're there so that when you break them you take a second to think about why.

[–] [email protected] 26 points 6 months ago (4 children)

One nit: whatever IDE is displaying single-character surrogates for == and != needs to stop. In a world where one could literally type those Unicode symbols in, and break a build, I think everyone is better off seeing the actual syntax.

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

In a world where your IDE and maybe also compiler should warn you about using unicode literals in source code, that's not much of a concern.

VSCode (and I'm sure other modern IDEs, but haven't tested) will call out if you're using a Unicode char that could be confused with a source code symbol (e.g. i and ℹ️, which renders in some fonts as a styled lowercase i without color). I'm sure it does the same on the long equals sign.

Any compiler will complain (usually these days with a decent error message) if someone somehow accidentally inserts an invalid Unicode character instead of typing ==.

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

If your build fails because you can't track down the literal in the code I would recommend just looking at the compiler error. I understand the concerns about == vs = more but the vast majority of LSPs (and some compilers) will catch that too.

I have also yet to see any IDE enable ligatures by default, at least VS Code and the JetBrains suite both require opting into them even though their default fonts support them.

[–] [email protected] 21 points 6 months ago (1 children)

I think it's a lineature. FiraCide does that for example, and I like it very much. My compiler and lsp will tell me if there is a bad char there. Besides, the linea tires take the same space as two regular characters, so you can tell the difference.

It's not the 90s anymore. My editor can look nice.

[–] [email protected] 3 points 6 months ago (1 children)
[–] [email protected] 1 points 6 months ago

Oops, good to know.

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

I love ligatures but much prefer the ones that preserve the proper width of all the characters for this exact reason

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

are there ligatures for monospace fonts that don't preserve the width of the characters?

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

Broad generalizations aren't for the people who make them, they're for the suckers who consistently fall for them

[–] [email protected] 20 points 6 months ago (3 children)

My personal code readability axe to grind is nested complex ternary operators.

Every now and then I'll see something like this

return (checkFormatType(currentObject.type==TYPES.static||currentObject type==TYPES.dynamic?TYPES.mutable:TYPES.immutable)?create format("MUTABLE"):getFormat(currentObject));

And I have a fucking conniption because just move that shit into a variable before the return. I get it when sometimes you just need to resolve something inline, but a huge amount of the time that ternary can be extracted to a variable before the ternary, or just rewrite the function to take multiple types and resolve it in the function.

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

no but bro, the code complexity tool says that this scope has 14 complexity instead of 13, we gotta cram it in a single ternary for code legibility

[–] [email protected] 7 points 6 months ago* (last edited 6 months ago) (1 children)

In a one-liner competition, sure.

In my codebase? I'd pull a "let's linger after standup about your PR" and have the coder sweat through a 10 minute soapbox about nothing before laying down the law.

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

Yeah, the annoying thing is the people who I generally have found to be the worst about stuff like this are old school Senior C developers, who still program like it's 1987 and we have to fit everything into 4K of RAM.

Fortunately there's nothing like that in my code base, I just run into stuff like that periodically when I'm digging around in other team's server code looking for something.

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

That example looks like the PowerShell equivalent of piping complex things around 20 times before actually doing something with the results.

load more comments
view more: next ›