5 ms·
Reasons to reject "if/else and switch as expressions" looks very naive. Can't believe it's coming from Chris Lattner. A lot of languages like Python, Haskell an
by jaseemabid 11y ago
Reasons to reject "if/else and switch as expressions" looks very naive. Can't believe it's coming from Chris Lattner. A lot of languages like Python, Haskell and Rust got this right.
- AlphaSite 11y agoPython doesn't do or/else as an expression, does it?
- gsnedders 11y ago`"yes" if foo else "no"`
- rdw 11y agoThat's a ternary, not an if expression.
- emn13 11y agoThe difference being?
- kazagistar 11y agoYou can not have full blocks, only expressions.
- emn13 11y agoAnd in an if-expression, you similarly can have expressions. Some of those expressions might be blocks. Some languages restrict where block expressions can be placed, but that's not a meaningful difference between if expressions and ternaries, that's a difference how blocks are treated. More concretely: I know of no language that allows "if expressions" that aren't just ternaries (i.e. either the language allows blocks as expressions or it doesn't, but given that choice, no language then further distinguishes between if expressions and ternaries).
- yeukhon 11y agoI love and use Python every day, but I agree with Chris that in Swift's case, over using if and else as expression can hurt. In Swift's case, that line is extremely ugly. If I were to catch an exception, I rather catch it at a line level in a block. If you read through https://mail.python.org/pipermail/python-ideas/2015-September/036489.html https://mail.python.org/pipermail/python-ideas/2015-Septembe... (a freakin long debate) you will see that sometimes simplifying things can hurt, although in this very debate if/else expression is favor over the proposed new syntax in that PEP, which I am against.