this post was submitted on 19 Jun 2025
330 points (90.4% liked)

Programmer Humor

24648 readers
1041 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
 

Made with KolourPaint and screenshots from Kate (with the GitHub theme).

top 50 comments
sorted by: hot top controversial new old
[–] marcos@lemmy.world 76 points 1 week ago (5 children)

Good, now invent a keyword for variables you don't want to declare the type. And now that you have a mix of keywords and identifiers on the same place, you can never update your language again.

Also, make the function declarations not use a keyword too, so you get the full C-style madness of code that changes meaning depending on what libraries you import.

[–] stingpie@lemmy.world 18 points 1 week ago (1 children)

I don't understand how not using a keyword to define a function causes the meaning to change depending on imports. I've never run into an issue like that before. Can you give an example?

[–] marcos@lemmy.world 16 points 1 week ago (3 children)

Some declarations terminate on the name, other declarations go one requiring more tokens. In C, the only thing that differentiates them is the type.

Parenthesis in particular are completely ambiguous. But asterisks and square brackets also create problems.

load more comments (3 replies)
[–] voytrekk@sopuli.xyz 13 points 1 week ago* (last edited 1 week ago)

C++ has auto, which determines the type automatically.

[–] piccolo@sh.itjust.works 8 points 1 week ago* (last edited 1 week ago) (1 children)

In C#, you can use 'var' to have an impilict type variable.

String name = ""

var name = ""

[–] pipe01@programming.dev 24 points 1 week ago (1 children)
[–] sus@programming.dev 20 points 1 week ago* (last edited 1 week ago) (7 children)

So I think it's still probably unclear to people why "mix of keywords and identifiers" is bad: it means any new keyword could break backwards compatibility because someone could have already named a type the same thing as that new keyword.

This syntax puts type identifiers in the very prominent position of "generic fresh statement after semicolon or newline"

..though I've spent like 10 minutes thinking about this and now it's again not making sense to me. Isn't the very common plain "already_existing_variable = 5" also causing the same problem? We'd have to go back to cobol style "SET foo = 5" for everything to actually make it not an issue

load more comments (7 replies)
load more comments (2 replies)
[–] GreatRam@lemmy.world 47 points 1 week ago (5 children)

You're encoding more information in the typescript one. You're saying it's a string that will get updated.

[–] masterspace@lemmy.ca 34 points 1 week ago (1 children)

Yeah, it's explicitly distinct from const a: String which says it won't change, and var a: String, which means this is legacy code that needs fixing.

[–] Psaldorn@lemmy.world 10 points 1 week ago (2 children)

If there's only two options you only need one keyword

[–] Hotzilla@sopuli.xyz 5 points 1 week ago* (last edited 1 week ago)

True, but var and let are not same in js, so there is three.

if(true) {

var a = "dumdum"

}

console.log(a)

Is valid and functioning javascript. With let it is not.

load more comments (1 replies)
[–] Scoopta@programming.dev 17 points 1 week ago (1 children)

You aren't though. In most languages that use the latter declaration you would prefix the declaration with final or const or the like to specify it won't be updated.

load more comments (1 replies)
[–] malware@lemmy.zip 11 points 1 week ago (2 children)
[–] calcopiritus@lemmy.world 14 points 1 week ago (4 children)

It's also valid rust syntax.

But if it were rust, this meme would not make sense, since you would just type let a and type inference would do its thing. Which is much more ergonomic.

[–] nebeker@programming.dev 8 points 1 week ago (4 children)

let a = String::from(“Hello, world!”).into()

I’ll see myself out.

load more comments (4 replies)
load more comments (3 replies)
[–] WhyJiffie@sh.itjust.works 5 points 1 week ago (7 children)

I was thinking the same thing. who would write typescript if they could just do Rust?

load more comments (7 replies)
load more comments (2 replies)
[–] _stranger_@lemmy.world 44 points 1 week ago (3 children)
[–] BeigeAgenda@lemmy.ca 22 points 1 week ago (2 children)

And then assign an int to a string just to mess with the interpreter.

[–] sbv@sh.itjust.works 45 points 1 week ago

only the linter gives a hoot - the interpreter will happily leave that footgun for later

load more comments (2 replies)
[–] barsoap@lemm.ee 27 points 1 week ago* (last edited 1 week ago) (5 children)

The actual reason why let ... in syntax tends to not use C-style "type var" like syntax is because it's derived from the syntax type theory uses, and type theorists know about parameterised types. Generics, in C++ parlance, excuse my Haskell:

let foo :: Map Int String = mempty

We have an empty map, and it maps integers to Strings. We call it foo. Compare:

Map Int String foo = mempty

If nothing else, that's just awkward to read and while it may be grammatically unambiguous (a token is a name if it sits directly in front of =) parser error messages are going to suck. Map<Int,String> is also awkward but alas that's what we're stuck with in Rust because they reasoned that it would be cruel to put folks coming from C++ on angle bracket withdrawal. Also Rust has ML ancestry don't get me started on their type syntax.

[–] weird@sub.wetshaving.social 7 points 1 week ago

There is also the thing where the compiler might mistake your c++ style variable declaration for a function, e.g.

String myfunction():

String myvariable();

load more comments (4 replies)
[–] tdawg@lemmy.world 24 points 1 week ago* (last edited 1 week ago) (5 children)

Because sometimes that let can be replaced by other things like const. Which can be managed statically by the machine and not by my (imperfect) ability to know if it's mutated or not

[–] lobut@lemmy.ca 5 points 1 week ago (1 children)

I think you can do const thing = ... as constto lock down the mutation?

load more comments (1 replies)
load more comments (4 replies)
[–] glorkon@lemmy.world 20 points 1 week ago
IT'S SHOWTIME
  I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE a
  GET TO THE CHOPPER a
    HERE IS MY INVITATION "ArnoldC is the best."
  ENOUGH TALK
  TALK TO THE HAND a
YOU HAVE BEEN TERMINATED
[–] jlh@lemmy.jlh.name 17 points 1 week ago (1 children)
[–] pivot_root@lemmy.world 18 points 1 week ago* (last edited 1 week ago) (9 children)

Rust is verbose, but C++ might still take the cake with its standard library templates. Especially when using fully-qualified type names...

auto a = ::std::make_shared<::std::basic_string<char, ::std::char_traits<char>, MyAllocator<char>>>();

A reference-counted shared pointer to a string of unspecified character encoding and using a non-default memory allocator.

load more comments (9 replies)
[–] tisktisk@piefed.social 15 points 1 week ago (2 children)

I've always wondered where all this 'let' business started

[–] HiddenLayer555@lemmy.ml 30 points 1 week ago* (last edited 1 week ago) (2 children)

It's commonly used in math to declare variables so I assume programming languages borrowed it from there.

[–] chaos@beehaw.org 7 points 1 week ago (1 children)

More specifically, they're borrowing the more mathematical meaning of variables, where if you say x equals 5, you can't later say x is 6, and where a statement like "x = x + 1" is nonsense. Using "let" means you're setting the value once and that's what it's going to remain as long as it exists, while "var" variables can be changed later. Functional languages, which are usually made by very math-y people, will often protest the way programmers use operators by saying that = is strictly for equality and variable assignment is := instead of == and = in most C-style languages.

load more comments (1 replies)
[–] bandwidthcrisis@lemmy.world 6 points 1 week ago (1 children)

BASIC uses (used?) it to declare variables. (I don't know if earlier languages did.)

Not that that's a reason for other languages to copy it.

[–] HiddenLayer555@lemmy.ml 8 points 1 week ago* (last edited 1 week ago) (1 children)

Doesn't Basic use Dim a As String?

[–] dan@upvote.au 10 points 1 week ago* (last edited 1 week ago) (4 children)

Older variants used DIM for arrays and LET for other variables. DIM was originally called that because it was setting the dimensions of the array.

In modern BASIC variants, DIM has become a backronym: "declare in memory".

[–] sbv@sh.itjust.works 5 points 1 week ago

In modern BASIC variants, DIM has become a backronym: “declare in memory”.

TIL. I always thought it was a backronym for declare in (yo) momma.

load more comments (3 replies)
[–] normalexit@lemmy.world 18 points 1 week ago (1 children)
[–] tisktisk@piefed.social 6 points 1 week ago

I doubted you until I got about halfway through this whole page. I concede tho--you are most correct lol Still a decent read and for that I thank you

[–] nintendiator@feddit.cl 14 points 1 week ago (1 children)
[–] JakenVeina@midwest.social 12 points 1 week ago* (last edited 1 week ago) (4 children)

Not to short-circuit the joke, but in this case, it's because the valid JavaScript version is...

let a

...and one of TypeScript's main design goals is to be a superset of JavaScript, that only adds syntax, and doesn't re-write it.

Beyond that, it's probably a case of some new language just using what the designer is familiar with.

load more comments (4 replies)
[–] dan@upvote.au 7 points 1 week ago (4 children)

Can we talk about PHP functions with typehints too?

public static function foo(): string {

Practically every other language with similar syntax does this instead:

public static string foo() {
[–] sbv@sh.itjust.works 15 points 1 week ago (6 children)

Rust and TypeScript use the return-type-at-the-end convention as well.

load more comments (6 replies)
[–] HiddenLayer555@lemmy.ml 6 points 1 week ago (2 children)

TIL PHP has statics.

Also, does PHP actually enforce the type declarations? I'd assume it would but knowing PHP...

load more comments (2 replies)
load more comments (2 replies)
[–] Lemminary@lemmy.world 6 points 1 week ago

STRING A WHAT, MOTHERFUCKER

load more comments
view more: next ›