Python has some interesting shortcuts too, like being able to do `if 1 <= number <= 10:` to do chained comparisons but I much prefer the longer hand syntax. I have a solid amount of Python experience but no formal math background beyond HS Algebra. I often don't see this shorthand method to compare a range but when I do I always have to stop and decipher it.
I know this thread isn't about Python but I think it falls in line with this conversation. A language that sticks to slightly more verbose syntax for the sake of crystal clear clarity is very appealing.
I think we should respect language creators to keep a clear vision on their language, this way the audience who uses it can either strongly love it or hate it. If you try to do everything and cater to everyone then you'll end up with a worse result IMO.
It's the same way with music. You wouldn't expect a deathcore band to release a country album because a small portion of folks were interested in that, it would alienate their true fans and would likely leave the band internally not liking that decision. If you want to listen to a different style of music then you can pick a different band or genre.
edit: Wrong, see below
x := val ? foo() : bar()
Versus var x Type // now this is default initialized, which may or may not be a valid state for your program
if val {
x = foo()
} else {
x = bar()
}
Honestly, I'd be fine with it being for initialization only (like the walrus operator)The go alternatives are too horrible to even contemplate, but here goes:
if a {
f(b, d, e)
} else {
f(c, d, e)
}
or var tmp WhatFuckingTypeIsThisAgain
if a {
tmp = b
} else {
tmp = c
}
f(tmp, d, e)
It's hard to say which one is worse, but there is no doubt that the C version is "unquestionably easier to read."Re; your example, what about
tmp := a ? b : c
f(tmp, d, e)
Even in C++ that's likely how I'd write it.Go core are very smart people so I’m sure they have their reasons, but my Lisp-addled brain can’t understand why you’d ever want statements instead of expressions with potentially discarded values.
I sadly don’t see it getting added to Go.
v := if foo() {
7
} else {
11
}
But this means {} blocks now have values, which is weird in a C derivative. Of course, one could do v := func() int {
if foo() {
return 7
} else {
return 11
}
}()
but... that's kind of awful. x = bar()
if val {
x = foo()
}
Is both shorter and functionally more equivalent with the ternary example.I'd still rather a ternary over any of the above options though!
x := func() Type {
if val {
return foo()
}
return bar()
}()