News for hackers. Stuff that matters.
Re:Another Scala rant on HN by octo_t on Tuesday December 03, 2013 @04:59AM (#6839458)
To people who say Scala has too many features, which ones would you remove?

(Please don't say + to concatenate strings, because everyone knows its terrible, its there for Java compatibility)

Re:Another Scala rant on HN by kasey_junk on Tuesday December 03, 2013 @08:58AM (#6840226)
It's not so much about what I would remove, it's more about gaining guidance/acceptance/standardization around the "right" way to do various things.

When creating a library should my functionality exist explicitly on the types? As extension methods on an implicit? As type classes?

When should I use infix/prefix notation? When should I use . syntax vs no .? What does _ mean in this particular line of code? Is an allocation happening for this lambda or not?

Why are map/flatmap/filter magical? Why are for comprehensions part of the language for those but not for type classes?

All of these kinds of questions are really hard to answer and I've been programming Scala in production for years.

Other complaints I have are about the mess that is the collections library, the push for actors when they are generally a bad solution, an emphasis on algebraic types without providing Union types, and all the opportunity costs represented in sbt (which is finally passable but no better) and Scala IDE.

Don't get me wrong, if you are targeting the JVM & want strong typing (I do), Scala is the best language for the job, but even for someone who uses it every day and is pretty expert there are some confusing corners & no 2 developers seem to write code the same way, so there is a price to be paid for that.

Re:Another Scala rant on HN by scotth on Tuesday December 03, 2013 @09:32AM (#6840443)
Wow, I have never heard anyone talk about actors that way, but have often thought it myself. What makes you say this?
Re:Another Scala rant on HN by kasey_junk on Tuesday December 03, 2013 @10:41AM (#6840881)
I have 3 major complaints about actors (specifically Scala/Akka actors, but most of the models I've encountered have similar problems).

1) In general, I think that going parallel should be an architectural decision. On current commodity architectures it doesn't buy people as much as they think it does, and can in many cases over complicate code. Actors hide this complexity, but don't actually remove it. People think actors give them free license to add tons of threads when they shouldn't.

2) Actor code tends to mix business logic with threading logic, precisely what we should be trying to avoid.

3) The actor model subtly conflates publisher/consumer models which tend to decompose and perform better in parallel situations.

Normally, for calculation style parallelism I prefer future/promises and for event style parallelism I prefer single writer/multiple consumer based shared memory.

Re:Another Scala rant on HN by weak on Tuesday December 03, 2013 @07:40AM (#6839884)
If you asked me 6 months ago I would say the features that confused me the most:

- Covariance / Contravariance - Implicit Parameters - Implicit Conversions - and also mentioned here, Structural typing.

However now that i've spent time with the language, seen these in action and used them myself I see the reason why they exist and embrace them. I can see why this would be a common complaint against Scala and can be a barrier for a lot, but I think the language is worth investing time in learning, at least for me.

Re:Another Scala rant on HN by pkolaczk on Tuesday December 03, 2013 @08:14AM (#6840001)
Covariance / Contravariance - Noooooooo! I admit - this might be hard to grasp at first, but in reality it is very simple concept that simplifies a lot of code. It is enough to get variance right once for a class, instead of fighting with ? in Java everywhere.

BTW: Kotlin has copied it and noone complains it is too complex :D

As of implicit parameters / implicit objects - ok, but what do you suggest as a replacement so that map/filter/reduce preserve types correctly? Or how do you do type-classes then?

Re:Another Scala rant on HN by jerf on Tuesday December 03, 2013 @09:12AM (#6840309)
"As of implicit parameters / implicit objects - ok, but what do you suggest as a replacement so that map/filter/reduce preserve types correctly? Or how do you do type-classes then?"

I don't have a specific answer to this question, but I do want to warn you that this is a dangerous line of reasoning. Given a complicated object like Scala or C++, you can easily have a situation where each individual element is necessary to support two or three other elements of the overall structure, yet, the overall structure can still be too complicated.

And to be clear, I'm not even saying you're wrong. Maybe there isn't a better choice. Scala's choice to be compatible with Java creates a very strange design situation. I'm just saying, this isn't a safe line of reasoning. I think it makes it very easy to become very short-sighted about your options by encouraging you to always be very locally focused.

Re:Another Scala rant on HN by CmonDev on Tuesday December 03, 2013 @08:31AM (#6840083)
Agreed, Covariance / Contravariance was a fantastic feature to borrow from C#! It just should have been implemented to be friendlier to people new to language.
Re:Another Scala rant on HN by tikhonj on Tuesday December 03, 2013 @09:27AM (#6840401)
Variance has been well understood in PL theory in basically forever. None of the languages had to borrow it from each other because they could all just get the inspiration from type theory.
Re:Another Scala rant on HN by pkolaczk on Tuesday December 03, 2013 @08:59AM (#6840232)
Ehm... No. If any, C# borrowed it from Scala. C# got them in version 4.0, which was first half of 2010. Scala had them since I remember (from day 1?) - for sure they were in Scala 2.6, which was released in 2006.
Re:Another Scala rant on HN by firepoet on Tuesday December 03, 2013 @08:52AM (#6840198)
Is that where he borrowed it from? I've seen mention of the language feature showing up in Eiffel, Sather, and so on. http://en.wikipedia.org/wiki/Covariance_and_contravariance_(...
Re:Another Scala rant on HN by MichaelGG on Tuesday December 03, 2013 @12:16PM (#6841610)
And C# could only add it because the now-F# folks had originally designed it into the CLR Generics system. It's highly unlikely C# would ever go far out of the straightforward IL generation it does to implement such a feature otherwise.
Re:Another Scala rant on HN by Locke1689 on Tuesday December 03, 2013 @08:17PM (#6844415)
Nope. The CLR has supported it back to v2, and C# delegates used the feature before language support was added in C# 4
Re:Another Scala rant on HN by MichaelGG on Tuesday December 03, 2013 @11:57PM (#6845114)
Right, variance was part of the original MSR proposal for CLR Generics.

How did delegates use variance? I've never been terribly clear on the whole delegates concept - they're like first class functions, except nominally typed and weird.

Re:Another Scala rant on HN by CmonDev on Tuesday December 03, 2013 @11:13AM (#6841115)
Sorry guys, I stand corrected :).
Re:Another Scala rant on HN by lmm on Tuesday December 03, 2013 @05:08AM (#6839478)
I'd remove structural types. I don't see them being actually used in scala libraries, and I think "traditional" types provide a better replacement for most (all?) use cases.
Re:Another Scala rant on HN by octo_t on Tuesday December 03, 2013 @05:43AM (#6839574)
So as i understand it the 'use case' is for coercing 3rd party types into your own type hierarchy. Suppose you had:

  trait Foo {
    def bar(): Int
  }
and 3rd party library had

  final class FooBar extends java.lang.Object {
    public int bar() { /** **/ }
  }
you could simply define your methods to take in a:

  type BarAble = { def bar():Int }

But obviously if the library class is not final, you can simply do:

  type ThirdPartyFoo = FooBar with Foo
  ThirdPartyFoo <: Foo
Re:Another Scala rant on HN by trailfox on Tuesday December 03, 2013 @06:10AM (#6839626)
Removing structural typing wouldn't be an improvement to my mind. It's the sort of thing you use maybe once a year, but when you do it's extremely useful to have around. It's a bit like saying that removing the ternary conditional operator in Java would make a big difference to developers' lives.
Re:Another Scala rant on HN by lmm on Tuesday December 03, 2013 @06:14AM (#6839641)
I think the kind of features you use maybe once a year are a bad thing to have in programming languages - ease of reading is more important than ease of writing.
Re:Another Scala rant on HN by trailfox on Tuesday December 03, 2013 @06:20AM (#6839657)
I should also point out that it's a feature which I don't believe detracts from readability. It's pretty clear from looking at code which uses ST what it does. There are examples in this thread.

It's a feature that you will use directly maybe once a year when adding it to a library, but I then use that library (and indirectly that feature) virtually every day. YMMV but we've found it very useful.

Re:Another Scala rant on HN by octo_t on Tuesday December 03, 2013 @05:35AM (#6839544)
Ding ding!

(That's the answer I'd give if someone asked me this question)

Re:Another Scala rant on HN by Pxtl on Tuesday December 03, 2013 @12:32PM (#6841735)
Python, C#, all the Java-derived languages... basically every C-ish syntax language except for C/C++ itself use + to concatenate strings. And it's an intuitive concept too - adding two strings is concatentation. That makes sense.

The problem isn't + string-concat, it's silently casting numerics into strings.

  "foo" + 6 + 6
Should be a compiler-error.
Re:Another Scala rant on HN by krapp on Tuesday December 03, 2013 @12:39PM (#6841781)

   "foo" + 6 + 6
>Should be a compiler-error.

Why? "foo" is already a string, getting "foo66" from that makes perfect sense to me.

6 + "foo" though would be crazy.

Re:Another Scala rant on HN by dllthomas on Tuesday December 03, 2013 @12:49PM (#6841832)
Because it makes intent explicit in a way that helps catch errors earlier, and they are kinds of errors that real programmers actually make.
Re:Another Scala rant on HN by krapp on Tuesday December 03, 2013 @12:56PM (#6841881)
Fair enough.
Re:Another Scala rant on HN by RivieraKid on Tuesday December 03, 2013 @08:45AM (#6840160)
Have a look at Ceylon, my first impression was that compared to Scala, there's much more focus on readability, regularity and productivity. Ceylon is one of the 2 languages (the other isbJulia) that I find almost perfect.
Re:Another Scala rant on HN by strictfp on Tuesday December 03, 2013 @07:20AM (#6839819)
Remove Java backwards compatibility.
Re:Another Scala rant on HN by CmonDev on Tuesday December 03, 2013 @08:34AM (#6840096)
Easy - drop the JVM branch and continue the CLR branch. This way you could gain better performance as well.
Re:Another Scala rant on HN by dragonwriter on Tuesday December 03, 2013 @11:56AM (#6841474)
> Easy - drop the JVM branch and continue the CLR branch.

The CLR branch, IIRC, was dropped because the CLRs reified generics -- which are better than erasure so long as your type system fits exactly what the CLR assumes -- are a very bad fit with Scala's more robust type system, which leaves you stuck with a bad interop story if you don't want to radically change Scala's type system to fit the CLR's assumptions.

Re:Another Scala rant on HN by trailfox on Tuesday December 03, 2013 @08:55AM (#6840214)
Better performance? What are you basing that on?
Re:Another Scala rant on HN by CmonDev on Tuesday December 03, 2013 @09:40AM (#6840483)
VM-level support of generics, value types and tail call optimization. My knowledge could be outdated though.

http://stackoverflow.com/a/267496/486561 http://stackoverflow.com/a/480362/486561

Re:Another Scala rant on HN by sluukkonen on Tuesday December 03, 2013 @12:05PM (#6841541)
Reified generics is one of the reasons why Scala on the .NET is effectively dead. The VM's type system isn't powerful enough to support some features of Scala, such as higher-kinded types.
Re:Another Scala rant on HN by CmonDev on Wednesday December 04, 2013 @04:05AM (#6845815)
JVM doesn't support reified generics for legacy reasons, it's said when need for compatibility slows down progress :(.
Re:Another Scala rant on HN by sluukkonen on Wednesday December 04, 2013 @01:31PM (#6848981)
But the JVM not having reified generics is a mostly a blessing for Scala. With reified generics, your language's type system can essentially be only as powerful as the VM's type system, and I think it's clear that Scala today wouldn't be the same if Sun had gone the reified generics route.

(Still, it would be nice to have specialized generic containers for some primitive types in the JVM)

Re:Another Scala rant on HN by MichaelGG on Tuesday December 03, 2013 @12:20PM (#6841650)
Tail calls are actually rather un-optimized in .NET. F# avoids them as much as possible. F# used to emit tail calls any time it could, but it hurt performance. IIRC, tail calls were also ignored in many areas prior to v4 (and they still have some limitations IIRC). The JVM could implement tailcalls via analysis; the tail prefix isn't truly needed.

But Xamarin's porting of Java to C# to run Android on Mono without the JVM did show a rather large perf increase. I'd assume that's mostly generics eliminating boxing.

Re:Another Scala rant on HN by kvb on Tuesday December 03, 2013 @03:32PM (#6842976)
What do you mean by "The JVM could implement tailcalls via analysis"? Offhand, I can't see a way for this to be practically viable, but I may just be lacking imagination.
Re:Another Scala rant on HN by MichaelGG on Tuesday December 03, 2013 @03:52PM (#6843107)
Maybe I'm dense, but why not the same way a compiler implements it? In a recursive function, at the point of recursion, flag the call to have codegen not setup a new stackframe and just reuse the current frame.

But you may be right that this might not be viable to run fast enough for JIT on a large codebase. Obviously you could tail-call enable every call that's eligible, but that probably doesn't generate optimal code. OTOH, they have tracing in the JIT for hotspot stuff, right? So if the tracing part counted how many call loops it had hit, it could decide to implement tailcalls in that path. Or perhaps it invokes analysis when the stack gets to be 75% full.

Re:Another Scala rant on HN by kvb on Tuesday December 03, 2013 @04:16PM (#6843246)
Right, my thought was that doing real tail calls everywhere that's eligible would almost certainly be a performance disaster. I'm not sure that hotspot could help, at least if applied naively, since correctness depends on never missing a tail call that could lead to unbounded stack usage.

For example, consider an F#-like language on the JVM. Given the definition `let apply f x = f x`, you could imagine `apply` getting called in all sorts of contexts that don't result in unbounded recursion, so a hotspot-like system would not generate a tail call when compiling the method given the first N invocations. But then if another function is defined as `let rec loop n = if n < 1 then n else apply loop (n-1)` and invoked as `loop 10000000`, then the lack of a tail call in `apply` is fatal.

Re:Another Scala rant on HN by MichaelGG on Tuesday December 03, 2013 @04:50PM (#6843453)
So if something kicked in at 75% stack usage (via a guard page?) and forced analysis, wouldn't that work? It'd be like the plethora of JVM options now: another configurable switch.
Re:Another Scala rant on HN by kvb on Tuesday December 03, 2013 @05:36PM (#6843685)
How much of the stack are you willing to look at when you hit a guard page? The non-tail call might not be right near the top, depending on the structure of the code. I'm not saying it's impossible, but I think the approach of having the higher-level language add the annotations is probably more practical.
Re:Another Scala rant on HN by MichaelGG on Tuesday December 03, 2013 @06:21PM (#6843932)
If the tail-call-needing function isn't found rather quickly (say, in the first 100? frames), then isn't it unlikely that the tail call will help? That seems like a much rarer case. Is the cost of going 1000 functions deep that expensive? Most threads aren't gonna hit a high % of stack without having some sort of problem anyways.

Of course it'd be better for the JVM to support this in bytecode, just like generics, stack allocation, and pointers. But it seems to me that if there was a real solid need for TCO then a JVM could implement it with tunable heuristics (most Java code doesn't need TCO, so if your code really depends on it in complex scenarios, you can always pass a -XXTcoInspectionDepth argument.)

Re:Another Scala rant on HN by trailfox on Tuesday December 03, 2013 @09:57AM (#6840592)
Scala implement tail call optimization in the compiler. In general the JVM has always outperformed the CLR:

http://benchmarksgame.alioth.debian.org/u64q/benchmark.php?t...

Re:Another Scala rant on HN by kvb on Tuesday December 03, 2013 @03:28PM (#6842949)
Note that Scala doesn't implement general tail call optimization; it only applies to direct self-recursive calls (as far as I'm aware). By contrast, on .NET F# implements true tail call optimization, including cases where the call is statically unknown at compile time (as in `let apply f x = f x`).
Re:Another Scala rant on HN by CmonDev on Tuesday December 03, 2013 @10:58AM (#6841015)
That's Mono - it lags behind .NET CLR.
Re:Another Scala rant on HN by dragonwriter on Tuesday December 03, 2013 @12:02PM (#6841515)
> That's Mono - it lags behind .NET CLR.

.NET is Windows-only, which is a significant limitation compared to the JVM. I don't think better performance on Windows -- even assuming going to CLR instead of JVM would provide that -- is a good reason for Scala to move to the CLR as the primary target.

Re:Another Scala rant on HN by CmonDev on Tuesday December 03, 2013 @12:38PM (#6841779)
I understand your point. Consider this: using Xamarin you can get native performance on iOS and better-than-Dalvik performance on Android. Is there a good tool chain for that in JVM/LLVM world that supports Scala?
Re:Another Scala rant on HN by dragonwriter on Tuesday December 03, 2013 @12:59PM (#6841896)
"Better than Dalvik" isn't necessarily a compelling selling point looking forward, since Android is almost certainly going to moving from Dalvik to ART as the default runtime fairly soon.
Re:Another Scala rant on HN by trailfox on Tuesday December 03, 2013 @11:15AM (#6841134)
I know, but the .NET CLR has lagged the JVM for years in terms of performance, but its a few years since I did a comparison...