Hacker News new | past | comments | ask | show | jobs | submit login

Why not have if/else be an expression in the first place, like Kotlin?

  n = if(expr) trueVal else falseVal
No need to learn a separate ternary operator.



Quite a few languages do if expressions, and IMO they’re great. Simple syntax, readable and powerful. It’s crazy to me that any new language wouldn’t have them.


The argument specified in the docs is "a language needs only one conditional flow construct" (in a language, of course, that has half a dozen conditional flow constructs ...)

The more palatable argument that people who try to cover for ... seems to be that when people nest if expressions, it becomes a mess. I'm glad these people exist.

The real reason is found here: http://dtrace.org/blogs/wesolows/2014/12/29/golang-is-trash/

(or if you prefer, in the compiler's source itself. It doesn't take a compiler expert to realize it's not very clean code. Even violates the go style, and the C one before that was just horrendous)

The TLDR is that Go's compiler is a "fisher-price my first compiler" and really shows that the authors simply barely knew how to get a compiler working in the first place. That they were not ready to go into a rational discussion on programming language and type theory ... is not something anyone should be surprised about.

That they avoid the arguments by dismissing the people making them in such a condescending way is ... well, there's not really anything good to say about that.


Ken Thompson has been writing compilers for over 50 years now. If you believe that Ken "barely knew how to get a compiler working in the first place", we have nothing to talk about, as you obviously made up your mind already.


Then read the source for the compiler yourself. Tell me I'm wrong.


Not only I have read it, I have written several compiler targets for it. You are wrong. It's by far the easiest compiler I have worked with.


Because the designers of Kotlin are more open to experimentation and new ideas.


  (setq n (cond
    (expr trueVal)
    (t falseVal)))
This particular idea dates back to at least 1965.


Er, yes, I should say “new ideas about which features are worth stealing from Lisp” :)




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: