this post was submitted on 19 Jun 2025
92 points (84.3% liked)

Programmer Humor

24540 readers
1708 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).

(page 2) 50 comments
sorted by: hot top controversial new old
[–] [email protected] 2 points 1 week ago (6 children)
load more comments (6 replies)
[–] [email protected] 0 points 1 week ago (1 children)
[–] [email protected] 1 points 1 week ago (3 children)

Javascript gonna Javascript

load more comments (3 replies)
[–] [email protected] 3 points 1 week ago* (last edited 1 week ago) (2 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.

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

Who says this is JS? Might be Rust.

[–] [email protected] 0 points 1 week ago (1 children)

Then the second part of my statement applies.

load more comments (1 replies)
load more comments (1 replies)
[–] [email protected] 5 points 1 week ago* (last edited 1 week ago) (2 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

[–] [email protected] 1 points 1 week ago (1 children)

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

load more comments (1 replies)
[–] [email protected] 0 points 1 week ago (1 children)

Ok but, in the second example you typically just put final or const in front of the type to denote immutability. I still don't see the advantage to the first declaration.

[–] [email protected] 0 points 1 week ago (1 children)

oh for sure, but I think that's the rarer case for language implementions. Having a consistent structure with alternative keywords in static positions is just easier to develop an AST for. Personally my favorite language doesn't even allow for const values (except by convention) so it's really just a matter of preference

[–] [email protected] 0 points 1 week ago

Is it rarer? I think a lot of modern languages go for the first option but pretty much all C style languages use the latter. It's probably a wash for which is more popular I'd think.

[–] [email protected] 27 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.

[–] [email protected] 6 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?

[–] [email protected] 12 points 1 week ago (1 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.

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

I have never heard of this problem for C. Can you elaborate or point to some articles?

load more comments (2 replies)
[–] [email protected] 6 points 1 week ago* (last edited 1 week ago)

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

[–] [email protected] 0 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 = ""

[–] [email protected] 8 points 1 week ago (1 children)
[–] [email protected] 7 points 1 week ago* (last edited 1 week ago) (5 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

[–] [email protected] 0 points 1 week ago (2 children)

At least in C#, you can define variables with keyword names like this:

var @struct = "abc"

I think in Kotlin you can do the same, and even include spaces with backticks like val abstract class = "abc"

I'm not sure if other languages allow that, regardless it should be rarely used.

load more comments (2 replies)
[–] [email protected] 1 points 1 week ago

Ah I was misunderstanding the problem. And learned something new about C#, seems in order to avoid breaking existing code they introduce "contextual keywords" var being added later, it is a contextual. You can create a class 'var' and the compiler will prefer it.

load more comments (3 replies)
load more comments (2 replies)
[–] [email protected] 0 points 1 week ago

First time i used let it was to inline variable declaration with assignment . Can’t remember the language.

[–] [email protected] 0 points 1 week ago (3 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() {
[–] [email protected] 0 points 1 week ago (1 children)

JavaScript (Typescript for the type part) and python, the most popular scripting languages, use the same order as PHP.

It's usually compiled languages that do the other one.

[–] [email protected] 0 points 1 week ago

TypeScript doesn't need the "function" keyword for a method in an object or on a class though.

const foo = {
  bar(): string {
   ... 
  } 
}

which I assume is doable because the syntax is unambiguous.

In PHP's case, the method syntax should also be unambiguous.

[–] [email protected] 4 points 1 week ago (2 children)

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

[–] [email protected] 0 points 1 week ago* (last edited 1 week ago) (1 children)

TypeScript doesn't need the "function" keyword for a method in an object or on a class though.

const foo = {
  bar(): string {
   ... 
  } 
}

which I assume is doable because the syntax is unambiguous.

PHP's object orientation is similar to languages like Java and C#, which is what I was comparing to.

[–] [email protected] 0 points 1 week ago

Your example didn't mention the use of the function keyword. Instead, it seemed to be questioning the placement of the return type - placing it after the argument list seems pretty common in newer languages.

[–] [email protected] 0 points 1 week ago (1 children)
[–] [email protected] 2 points 1 week ago (1 children)
[–] [email protected] 3 points 1 week ago

AND MY AXE!

[–] [email protected] 0 points 1 week ago (1 children)

TIL PHP has statics.

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

[–] [email protected] 0 points 1 week ago

It enforces scalar types (string, int, etc) at runtime if you enable strict mode. There's also static analysis tools like PHPStan and Psalm that will flag issues at build time.

load more comments
view more: ‹ prev next ›