Martin Odersky: Scala with Style
Why Stack Overflow recommends it
Stack Overflow users link it when answering Scala style questions, especially to justify using local mutable state or imperative code for performance or readability instead of purely functional constructs.
Recommended by 2 people across 2 different months, 2013 to 2015.
What it is
Martin Odersky, the creator of Scala, gives a keynote-style talk at SF Scala (a repeat of his Scala Days 2013 keynote) on what good style means in the language. He argues programming is in a transition between imperative/OO and functional styles and predicts the two will fuse. Published by InfoQ.
What people said
Recommends Erik Kaplun · 2013-09 · Stack Overflow · on “Parsing matrix data with Scala”
Also, I would note that using a loop with simple `var`s instead of a `foldLeft` with immutable state types *might* be more practical; see Martin Odersky's "Scala with Style" @ [this video] for why it's not always a good idea to stick to purely functional constructs, or, conversely, why it might often be a good idea to use mutable/imperative idioms such as state, locally, for either performance or readability, or both.
Recommends Waldemar Wosiński · 2015-04 · Stack Overflow · on “Scala code style and conventions”
Using such imports for implicits is useful in many cases. For this usage, importing makes code safer and more readable. Second case would be ambiguous class and package names (can be solved via aliases). Showing explicite which one is using can be helpful. In Scala you can do many things in many ways, a little bit like with C++. You have more responsibility for your coding style. Watch this: [this video] Nested methods are great for recurrence and when such method should not be used even as private at class level. With nesting you can also reduce amount of passed arguments. If you can you then you should place you nested methods on the top of method body. Giving comments on where is constructor b
Cites Rüdiger Klaehn · 2014-01 · Stack Overflow · on “QuickSort Traditional vs Functional Style What Causes This Difference?”
It is completely acceptable in scala to use mutable state locally to make things quicker. Martin Odersky himself suggested this in his keynote of the 2013 scala days [this video] . So in the real world your sortFunctional method would create a copy of the array to be sorted and use normal in-place quicksort internally. As long as the mutable state remains confined to a local method it is pretty harmless.
Cites ya_pulser · 2014-07 · Stack Overflow · on “In Scala what is difference between val a = "Hello World" and val a = println("Hello World")”
In scala there are no procedures, only functions. The procedure is function with return type Unit. Please see slide #45 from Martin Odersky [LINK] / [this video] . Though when you write val a = println("Hi") it is expands internally into val a = { println("Hi") } it is like an anonymous version of def x() { println("Hi") } val a = x() The full version of the x() with all "sugar" removed is def x():Unit = { println("Hi") } And the Unit value is compacted into () in scala console. So when you write your "compact version" you have : val a = println("Hi") Hi <-- result of the call to the println in the stdout a:Unit = () <-- here a - name of variable, Unit = type of the a variable, and the () is the
Cites som-snytt · 2015-08 · Stack Overflow · on “Scala Iteratively build lists”
@Dici I only know what they tell me. I don't disagree w/u about prefer functional, but imperative with local mutables has its place & also easy for Java folks to grok. Until they know better. As a ref only, [this video]