3 ms·
I loved Scala until a minor version updated somewhere around 2.9-2.11 destroyed all my hope. Eight years later I still refused to use it to build anything. Yet,
by rubyn00bie 6y ago
I loved Scala until a minor version updated somewhere around 2.9-2.11 destroyed all my hope. Eight years later I still refused to use it to build anything. Yet, with that said, IMHO, it can be fucking great _second_ language.
If you haven't used a statically typed language before, i.e. you're from Ruby, JS, Python, et. al then it's one bangin' ass brain rodeo. I'd highly recommend spending a couple months trying to learn it. Once you're done, you will almost certainly spend near zero effort learning any other typesystem save the MLs (which would, in some ways, probably be a better rodeo).
One of my favorite "ah-ha! that is totally how it fucking works" moments with Scala was going to see how `Function` worked only to find this bad boi: https://www.scala-lang.org/api/current/scala/Function22.html https://www.scala-lang.org/api/current/scala/Function22.html
A lot of time people think there's more magic going on than there is and just seeing that's how a function works with 22 arguments was pretty illuminating for me coming from Ruby.
- fmakunbound 6y ago> only to find this bad boi: https://www.scala-lang.org/api/current/scala/Function22.html https://www.scala-lang.org/api/current/scala/Function22.html Dang. I just checked in the Common Lisp I use and it's a bit higher. What's the reason for having to have at least 22 concrete function signatures like that? CL-USER> call-arguments-limit 4611686018427387903 (62 bits, #x3FFFFFFFFFFFFFFF)
- rbonvall 6y agoOriginally there was no way of abstracting over an arbitrary number of type parameters in the language, so a different trait was required for each arity. The choice of 22 was arbitrary, I think. This is no longer true in Scala 3, so there will be no such limit: http://dotty.epfl.ch/docs/reference/dropped-features/limit22.html http://dotty.epfl.ch/docs/reference/dropped-features/limit22...
- lmm 6y agoThe JVM had no support for functions as values (it was designed around the idea of only having objects with methods). So if you want to very closely mirror Java at runtime (e.g. you want Java reflection libraries to work with your language) but you want to use functions as values, you have to bridge that gap with classes whose instances will represent functions.
- didibus 6y agoIt's for optimization, at run-time you could handle functions with more arguments, but with this it can be compiled to directly call the exact function based on the number of arguments statically used at the call-site and their type. To do this though, you need a defined static type for the type of Functions each of a different number of arguments. 22 is just where they stopped to keep defining those types.
- sireat 6y agoI actually like Scala. I teach it to complete beginners to programming and generally it goes great - there is a huge demand for junior Scala developers in my neck of woods. However when I found that 22 argument monster a while ago it was a bit of a wtf moment to me. Why 22? Why not 21 or 23 ? Is it one of those no one is going to need more than 22 arguments?
- ibraheemdev 6y ago22 is just arbitrary. > Is it one of those no one is going to need more than 22 arguments? You can work around this limit with nested tuples, or just defining Function23 yourself. Although if your function accepts 23 arguments, you should probably refactor that anyways. It is also worth noting that Scala 3 drops this limitation by implementing function arguments with arrays: https://github.com/lampepfl/dotty/pull/1758 https://github.com/lampepfl/dotty/pull/1758