327
submitted 2 days ago* (last edited 2 days ago) by HiddenLayer555@lemmy.ml to c/programmer_humor@programming.dev

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

you are viewing a single comment's thread
view the rest of the comments
[-] marcos@lemmy.world 73 points 2 days ago

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 2 days ago

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 14 points 2 days ago

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.

[-] embed_me@programming.dev 3 points 2 days ago

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

[-] sushibowl@feddit.nl 16 points 2 days ago

The basic problem is that identifiers can be either types or variables, and without a keyword letting you know what kind of statement you're dealing with, there's no way of knowing without a complete identifier table. For example, what does this mean:

foo * bar;

If foo is a type, that is a pointer declaration. But if it's a variable, that's a multiplication expression. Here's another simple one:

foo(bar);

Depending on how foo is defined, that could be a function call or a declaration of a variable bar of type foo, with some meaningless parentheses thrown in.

When you mix things together it gets even more crazy. Check this example from this article:

foo(*bar)();

Is bar a pointer to a function returning foo, or is foo a function that takes a bar and returns a function pointer?

let and fn keywords solve a lot of these ambiguity problems because they let the parser know what kind of statement it's looking at, so it can know whether identifiers in certain positions refer to types or variables. That makes parsing easier to write and helps give nicer error messages.

[-] BehindTheBarrier@programming.dev 1 points 2 days ago* (last edited 2 days ago)

I feel this is related, and hightlight this even further, look at all the ways to initialize something in C++.

https://www.youtube.com/watch?v=7DTlWPgX6zs

If you are really lazy, have a look at making an int at around 7:20. It's not horrible that alone, but it does show how many meanings each thing has with very little difference, added on top of years of legacy compatability accumulation. Then it further goes into detail about the auto use, and how parantheses, bracket, squiggly bracket all can be used and help with the mess.

[-] voytrekk@sopuli.xyz 11 points 2 days ago* (last edited 2 days ago)

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

[-] ZILtoid1991@lemmy.world 4 points 2 days ago

Good, now invent a keyword for variables you don't want to declare the type.

auto. Also in D, you only need const if you don't want to specify a type for a constant, the compiler automatically inferres it to you.

Function declarations can be easily decyphered from context, no problem.

[-] ulterno@programming.dev 1 points 1 day ago

Maybe that's what the people developing spoken languages thought, while normalising conversations overdependent on context.

But hey, now we have another comedic tool in anime.

[-] piccolo@sh.itjust.works 8 points 2 days ago* (last edited 2 days ago)

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

String name = ""

var name = ""

[-] pipe01@programming.dev 22 points 2 days ago
[-] sus@programming.dev 18 points 2 days ago* (last edited 2 days ago)

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

[-] HiddenLayer555@lemmy.ml 1 points 1 day ago* (last edited 1 day ago)

any new keyword could break backwards compatibility

Wouldn't that happen anyway with variable and function names? Any type other than primitive/built in ones are usually camel case so lower case keywords are more likely to clash with single word variable and function names, unless you restrict the cases of those too or allow keyword overriding or something.

[-] sus@programming.dev 2 points 1 day ago* (last edited 1 day ago)

Yeah, it's in my edit I realized the same thing. I'm thinking it doesn't actually really make sense and the real reason is more "the specific way C does it causes a lot of problems so we're not poking syntax like that with a 10 foot pole" + "it makes writing the parser easier" + maybe a bit of "it makes grepping easier"

[-] HiddenLayer555@lemmy.ml 1 points 16 hours ago* (last edited 16 hours ago)

One thing that annoyed me about C# as a Java guy is that it really wants you to use camel case for function and property names, even private ones. I don't like it specifically because it's hard to differentiate between a function/property and a type.

But C# has quite a few keywords and seem to like adding them more than Java.

Maybe that's their way of ensuring keywords don't clash with stuff?

[-] AnotherPenguin@programming.dev 3 points 2 days ago

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.

[-] pivot_root@lemmy.world 3 points 2 days ago

Swift also uses backticks and Rust has a dumb one in the form of r#thekeyword. Still much better than introducing a async as a new keyword in a minor version of a language and breaking a bunch of libraries.

[-] fayaz@lemmy.world 4 points 2 days ago
[-] piccolo@sh.itjust.works 3 points 2 days 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.

this post was submitted on 19 Jun 2025
327 points (90.2% liked)

Programmer Humor

24374 readers
873 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