←back to thread

498 points azhenley | 7 comments | | HN request time: 0.842s | source | bottom
Show context
Razengan ◴[] No.45770236[source]
If designing your hypothetical ideal language, what are some intuitive/cute keywords you would choose for mutables/immutables?

`let` is so 2020. `const` is too long. `static` makes me fall asleep at the keyboard. `con` sounds bad. How about

`law`?

    law pi = 3.142 (heh typing on Mac autocompleted this)

    law c = 29979245

    law law = "Dredd"
or `set` or `once` or `make`?
replies(4): >>45770286 #>>45771270 #>>45771607 #>>45779782 #
1. tomaytotomato ◴[] No.45770286[source]
There was a proposal in Java a few years back to introduce "val".

I think it never gained traction but it would have been nice to have this in Java

    val firstName = "Bob";
    val lastName = "Tables";
    var fullName = "";

    fullName = firstName + " " + lastName;
replies(2): >>45770383 #>>45770702 #
2. mcdeltat ◴[] No.45770383[source]
Wouldn't this "val" be the same as "final"?

Also related, it annoys me that Java has final but otherwise poor/leaky support for immutability. You can mark something final but most Java code (and a lot of the standard library) uses mutable objects so the final does basically nothing... C++ "const" desparately needs to spread to other languages.

3. Razengan ◴[] No.45770702[source]
That's an aesthetically awkward and also bug-prone syntax: So just a difference of 1 single letter (that looks similar) to mean the completely opposite thing?? Nah you don't want that, and I don't either.
replies(2): >>45770891 #>>45772233 #
4. nvlled ◴[] No.45770891[source]
Kotlin uses var/val too[0] which is what Java is trying to copy. I have never written any kotlin code before, so I don't know if this would be a problem in practice. On the plus side, var and val both have the same length, so the variable declaractions are properly aligned. The names are also intuitive as far as I can tell.In theory, I'd probably be okay with it.

[0] https://kotlinlang.org/docs/basic-syntax.html#variables

replies(1): >>45771837 #
5. ahoka ◴[] No.45771837{3}[source]
Not a problem in practice as you use val 99.99% percent of the cases (which shows why immutability should be the default, because most often that is needed) and Idea underlines any mutable references, so the sticks out. It also suggests val when a var is not actually mutated.
6. dionian ◴[] No.45772233[source]
They're intuitively named. A value is a value. A variable is a variable.
replies(1): >>45772541 #
7. Razengan ◴[] No.45772541{3}[source]
A variable is also a value.