On Wed, Dec 19, 2018 at 12:09 PM Viktor Kojouharov <vkojouha...@gmail.com> wrote: > > I've tried and failed at finding any previous discussion on this topic, so do > point me to one if it exists. > > I'm interested to know whether it was considered (I can't imagine that it > wasn't) for if and switch statements to be expressions instead, and if so, > why were they ultimately left as statements. It seems to me that having them > as expressions will not cause a significant change in how they are ultimately > used, mostly because other languages that do support such expressions do not > exhibit this behaviour either. Nor is such a change strictly backwards > incompatible, since any expression is also technically a statement as well, > via the ExpressionStmt grammar rule. Such expressions also cover a simple > feature which a lot of people new to the language are looking for, and most > of us have abused in other languages - ternary operators. The Go FAQ states > that if-elses are clearer, if longer, which I definitely agree with. Yet it > seems that an if expression would retain its readability, if not outright > increase it, while allowing for terser assignments. The reason being that a > chunk of repeatable code (for example assigning to the same variable in every > logical branch) would be moved out of the whole block, thus highlighting the > value. > > What if the spec defines that if all if-else blocks / all switch case clauses > contain only single expression, they would be expressions rather than > statements. How would that negatively impact the language, in a way that > can't already be reproduced?
I think this is more or less covered by https://golang.org/doc/faq#Does_Go_have_a_ternary_form . Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.