Also, hi Russell!
Also, hi Russell!
Another important point: the idiomatic Scala version is one concise, purely functional line. The second version on the other hand is 6 lines and involves mutation. If you were to embed it in another part of the program in a purely functional way, you'd have to wrap it in curly braces and add an extra expression to return the final value of x, upping it to 9 lines. Claim what you want about readability, but lines of code impose a cognitive burden, both in reading them and scrolling through them. I'd much rather express an idea in one line of pure code if possible than with 6-9 lines of code that modifies state.
In general though, we find the code just kind of balloons if you use patterns like this everywhere.
I know the old saying about premature optimization, but avoiding premature optimization doesn't mean actively choosing slower code. It just seems like sloppy programming, IMO.
It isn't.
For me, Scala provides a happy middle ground between a scripting language like Python, and an "enterprise" language like Java. Scala is as nearly performant as Java--and sometimes it performs significantly better than Java due to having parallel collections, and the like--while having nearly the expressiveness of a scripting language like Python.
Also, Scala's performance issues are overblown. I program in Scala professionally every day and it performs great.