3 ms·
To me, all these IIFE’s make a good case for adding a block-as-expression construct. Either take from Scala, where every block evaluates to the last expression
by jakear 8y ago
To me, all these IIFE’s make a good case for adding a block-as-expression construct. Either take from Scala, where every block evaluates to the last expression executed in that block (and every statement is an expression); or maybe introduce some new syntax (‘do { .... }’ maybe?) if the prior would be a breaking change.
- zmj 8y agoThere's a bytecode representation already - you can use it when compiling to IL: https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.blockexpression?view=netframework-4.7.2 https://docs.microsoft.com/en-us/dotnet/api/system.linq.expr... What's missing is a way to express an anonymous block expression in C#. I'm not sure that's a gap worth filling, though - if the logic is worth a block, isn't it worth a name?
- twhb 8y ago“If” statements and loops already make use of anonymous blocks, and I think serve as ample demonstration that, no, not all blocks are better off named. What’s missing is the ability to use those blocks wherever an expression is expected.