3 ms·
> To highlight the problem, take Scala. A language I absolutely love, by the way. But it’s got this one big issue. There’s no idiomatic Scala. It’s way too flex
by paulddraper 3y ago
> To highlight the problem, take Scala. A language I absolutely love, by the way. But it’s got this one big issue. There’s no idiomatic Scala. It’s way too flexible.
> I can write a single file, calculator class and start with a Java style:
// Returns, braces and semi-colons
def getResult(): Double = {
return result;
}
def multiply(number: Double): Calculator = {
if (number == 0) {
println("Multiplication skipped: number is 0");
} else {
result = result * abs(number);
}
return this;
}
Scala has this problem, but this is a terrible example. Because literally no one writes like this.
More plausible is:
def getResult: Double = result
def multiply(number: Double): this = {
if (number == 0) {
println("Multiplication skipped: number is 0");
} else {
result *= abs(number);
}
this
}
And even that's a bad example.
Because still no one writes Scala like this, with mutable chaining. (Java yes, Scala no.) It's either mutable, or immutable chaining.
- adamgordonbell 3y agoI do state that nobody writes code like that. The point was the language supports all these ways of coding and never states an opinion on what should be prefered. Maybe there is a style implied by Odersky's Scala course, but I'm not sure even that style is considered the in fashion style these days. Somebody needs to write these things down. People can ignore them, but at least deviation would be explicit. See my diagram with the arrows.