3 ms·
That example is quite unfair. You could just write println(is_me ? "me" : "you") which has exactly the same amount of symbols.
by jdrek1 4y ago
That example is quite unfair. You could just write
println(is_me ? "me" : "you")
which has exactly the same amount of symbols.
- camdez 4y agoI specifically called out the tertiary operator in my text so as to be fair, but tried to keep things simple in my example. Perhaps too simple. Of course you can do that simple case with a tertiary operator but: 1. It's a construct that really has no reason to exist (I argue) as distinct from `if`. 2. It doesn't compose with statements. This duality is primarily what I'm arguing against. A better example would have been a case statement inside of the `println`: (println "Log in by" (case user-id 0 "root" 1 "local admin" (format "regular user (id: %d)" user-id))) In C, you have to introduce a variable for no good reason (or do some non-idiomatic, ugly, nested tertiary operators that get uglier the more cases we have). And even then, you can't just say user_name = switch { ... } Because switch is an statement.
- jdrek1 4y agoI mean sure, more things being expressions instead of statements is pretty nice (e.g. in Rust you can do that). But you don't need to introduce different syntax for that.