[Disclaimer] This review does not address algorithmic issues. Indeed it dismisses them as inappropriate. To avoid confusion, it should be considered a partial review.
Two Conflicting Goals
At the level of abstraction where the choice to use Scala makes sense and discussions about idiomatic Scala make sense, the idea of implementing a bubble sort does not. The decision to use or not use Scala is typically based on programmer efficiency. Decisions over sorting algorithms are typically based on computational resource efficiency and raw execution speed of critical sections.
Idiomatic Scala is a State of Mind
Trust in the JVM and faith in the sound engineering practice of profiling code before worrying about tuning performance is part and parcel of a wise decision to use Scala or similar languages. We've given up micromanaging memory for a garbage collector and high level abstractions.
Despite the Curly Braces
Scala is not C. Applying "Fortran in any language" with C in Scala will not produce idiomatic Scala. Applying it with Scheme won't either. Writing Ruby in Scala is closer to the mark.
Only Write Code that Matters
The idiomatic Scala would look something like:
res42: List[Int] = List(1, 2, 3, 4, 5)
Because less code is often easier to understand and might contain fewer bugs...at least those tend to be reasons given for using high level languages since the days when assembly was considered high level and compared to raw machine code it was.
Trust and Verify(maybe)
Idiomatic Scala will rely on library routines such as
sorted rather than reinventing them. Mainly because the odds of a random Scala programmer writing a better implementation are approximately zero. Even those who possibly could will not unless there is a verified performance issue and the bottleneck is in the sort. And then it's probably time to look at JVM Bytecode instead of trying to get more efficiency through the Scala compiler.
- Don't write Scala modelled on C or Java.
- Take advantage of Scala's high level features.
- Don't optimize what doesn't need to be optimized.
- Implement procedural code in languages where it is idiomatic.