The footgun of 'break' in switch statements has always bothered me, I strongly prefer the kotlin/swift way of doing this.
The footgun of 'break' in switch statements has always bothered me, I strongly prefer the kotlin/swift way of doing this.
Lisp introduced 'cond' when? Also, pattern matching in it's slightly more advanced form is as old as ML.
It's good to see languages finally admitting that expressions > statements. Still waiting for them to implement proper tail recursion though so I can replace statement based loops with expression based ones.
Pascal, and presumably Algol, had no break - following the guard condition was “a statement” (either just a single one, or an explicitly bounded block / compound statement)
Nice to see plans to act something like Lisp’s “(COND ...)” or Ruby’s case statement (et al).
And in rare cases where you do want fallthrough, they added the ability to "goto case" from the body of one case label to another. Which is kinda nice, because it follows the original C design in treating case labels as, well, labels.
Thankfully this is changing now, with Pascal and ML syntax becoming again fashionable.
Anyway, Lambda expressions have been around in, like, Lisp for at least 40 years and in mathematics for, what, 80? So everyone's slow by that account.
C# is much faster and has much more features, but because of that it's also a bit of a mess sometimes. For example regarding closures/anonymous functions it has delegates, lambdas and anonymous (inner) classes which all have overlap but aren't fully the same.
Java only has anonymous inner classes, and a convenient syntax and good support for anonymous inner classes with only 1 method (which they call lamdbas)
The only variant of Java that desugars lambas into anonymous inner classes is Android, because Google.
Java has had closures since 1997 hasn’t it? Don’t anonymous classes close over local state? Just the syntax was verbose.
Do you mean the lambda syntax? Well that isn’t thue only thing in Java that forms a closure.
‘Closure’ and ‘anonymous function syntax’ are orthogonal.
I think that's reasonable though, capturing mutable state is a recipe for disaster, and if you really want/need to you can wrap it in a properly synchronized container (e.g. AtomicReference in Java)
Apart from effective finality and implementation, the semantics of anonymous classes and lambdas is the same!
The kotlin/swift way of declaring this flow does not let you do this mistake.
It might take quite a lot of work to fix (or bypass) all the reported problems in a large codebase but it is worth it.