3 ms·
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
by Razengan 1y ago
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`?
- tomaytotomato 1y agoThere 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;
- ratmeadow 1y agoWouldn'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.
- Razengan 1y agoThat'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.
- nvlled 1y agoKotlin 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 https://kotlinlang.org/docs/basic-syntax.html#variables
- ahoka 1y agoNot 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.
- dionian 1y agoThey're intuitively named. A value is a value. A variable is a variable.
- Razengan 1y agoA variable is also a value.
- deleted 1y ago[deleted]
- veltas 1y agoWhat is wrong with let?
- Razengan 1y agoNothing, it's just been done, just trying to think of some better/newer ways to say it :)
- teo_zero 1y agoWhy not "def"?
- Razengan 1y agoThat's fine. But couldn't that just mean "define" any value at all? There's nothing in it to say it's specifically for defining a value only ONCE.