jueves, 27 de enero de 2011

Scala Considered Harmful For Large Projects? ... Not

I open this blog following a controversial topic :).

Scala is Bad:

I recently found this blog Scala considered harmful for large projects? please check it out. Now back to me. Now back to comments section in that blog. Now back to me.

After reading the post you might get an uneasy feeling that it might be right and Scala is not so cool and blah blah blah and then when reading the comment's you can see everyone offering a quite different point of view that the whole post falls apart.

Another similar interesting read is The next big JVM language.

And yet another misleading post Scala is not a better java.

It has some jewels like:

He says:
  1. "Java is culturally opposed to these ideas: it is deliberately simple."
  2. "This definition of a good programming practice is one that Scala vehemently opposes." followed by contradictory "Java was supposed to start small and grow"
  3. "Java is proud of removing multiple inheritance. "
  4. "If you're stuck with the JVM, I guess the question is: how much rope do you want to give your programmers? Scala is essentially the opposite answer to Java."
I say:
  1. Java is not simple nowadays. People cried over generics and Collections aside it's still a pain to use them. Boxing - Unboxing. And several other problematic areas I don't care to list. Ok you don't trust me? Read "Effective Java" to really understand that there are tons of pitfalls and most likely we are guilty of several of those in our code we think is so good. Oh but wait, read "API Design" by Jaroslav Tulach en then you might also realize that designing software even in Java it's so god damn easy to get wrong. Then think about all those cool framework you probably use. Dependency Injection, Aspect Oriented Programming, external config XMLs and many other ways of making the code's context hard to understand.
  2. Actually read the link. I dare you. My favorite lines that summarizes it perfectly "A true library does not change the rules of meaning for the language; it just adds new words." and "But the key point is that
    the new words defined by a library should look just like primitives of the language.". OMG it's exactly like Scala so Scala is actually what they tried to do back in 1998 according to this article.
  3. Like every statement I found everywhere spelled like that I must say "Says who?" or like wikipedia "Need reference". Ok multiple inheritance is problematic if done wrong and that statement is probably true. But Scala doesn't have multiple inheritance. I don't see how Java is better than Scala in this aspect. Java avoided the problem altogether causing pain for the good developers, Scala solved it gracefully empowering even beginners with the inclusion of Traits.
  4. "Stuck with the JVM" ok, deal-breaker, this guy hates Java and the JVM anyway I honestly don't trust his opinions regarding the JVM ecosystem.
Scala is Not Bad: 

A more reasonable explanation was written by Jim McBeath here Scala Pros and Cons check his "Other Posts" links too then please bookmark his blog and read it often.

Other good read is The Scala is too Complex Conspiracy but don't waste your time in the comments section (unless you Ctrl+F "Odersky" and read his comment, then close the window).

Scala is Good:  

An excellent read Scala == Effective Java ? clearly shows an example of how Scala is actually simpler than Java and removes a lot rope you could hang yourself with. The thing is we are so used to Java's problems that we think it's simple and deceive ourselves.

Another thing people tend to pick on are the operators. Java deliberately avoided operator overloading, it's a design choice. Scala solves it gracefully. It has just a simple rule, "a.method(b)" can also be written as "a method b", as an extra method's name can be made out of symbols like '+'. No surprises, everything is a method.

People tend to think operator overloading is a great chance to mess up your code because it's hard to tell what's happening. The imaginary problem is that a crazy programmers starts littering the code with unrecognizable operators making it hard to read. If I name a method that adds two number "fhwgads" it's pretty much same. If you can't trust in your team's ability to pick names you have bigger problems.

Then there is this whole thing about making a programming language so simple that nobody can get it wrong. But hey, we have reached a place where software is complex because it defines a complex reality, that's where languages are lacking. The problem is that complicated stuff becomes overly complicated to express. I can't understand why would anyone want a limited programming language nowadays, that is not where the world is going, check out the emerging languages in the last decade. No one wants or need a "stupid" language, there is a real need for an expressive language to help us convey a complex reality in elegant ways. Languages are converging to Lisp's features. The next main stream language is not one lacking the features every goddamn decent developer is craving for so stop looking for the "The Next Big Dumb JVM Language".

The thing is Scala IS simpler if used like Java. The novice programmer will find that simple tasks take less lines than Java and it's easier to not mess it up. They will also code algorithms imperatively and everything will work just as in Java. The only thing I'm sure they will miss are "continue" and "break" but are definitely going to love "match" vs the old "switch". Casting, if any is changed from "((Cast)variable)" to "variable.asInstanceOf[Cast]", albeit verbose it doesn't force you to add the almost always necessary enclosing parenthesis. You might also have to fix some number casting with a "num.toInt" or stuff like that.

Leaving "break" and "continue" aside all you Java code base can be translated to Scala without breaking a sweat.

Then as you get deeper into Scala you will discover the cool stuff that nobody forces you upon and you will like it. You will only have to work as a team to learn and improve. Read the Scala books. Talk about it, say "hey check out this cool way of doing x I discovered in Scala!" and that's it. All you need is a passionate team to go ahead and learn it together. As more people stop cowering behind their false sense of safety and leap in Scala the less we have to go around protecting the "dumb programmers", let's all break our ignorance and embrace self improvement, encourage it and even demand it.

Please check Odersky's opion on the different level programmers can have Scala levels: beginner to expert, application programmer to library designer and a great response to close this article of mine Critique of Odersky’s Scala levels.

5 comentarios:

  1. Thanks! I was tempted to answer that post but you have better arguments. :)
    The (repeated) argument about "keeping Java simple" as a "journeyman language" leads you to VisualBasic. I don't think that's the goal of Java, but if you want to use a simple language that everybody can understand, know yourself out, go ahead with VB (use Mono if you need) and stop complaining! :)
    Many arguments against Scala can be resumed as "I'm afraid of new stuff and I don't want to learn" (although there' valid points too).
    I wonder how those people learned Java...

    ResponderEliminar
  2. Well I definitely don't want to steer Java towards Visual Basic ;) But I also don't want to steer Scala to C++... and I've been getting that feeling lately.

    I've hardly ever encountered Java code that I didn't understand except for obvious reasons that the code was just written in an obscure way. But lurking on the Scala list I've seen many WTF examples where I've got no clue.

    So obviously I haven't reached Odersky's L3 or Morris' L4+ level but the thing is that I am supposed to understand it when I'm in a project! When things don't werk and I'm stepping into library code to figure out what's going wrong I need to at least understand the L3+ level code!

    I think we shouldn't ignore that this might pose a problem if we want Scala to be adopted by the masses.

    ResponderEliminar
    Respuestas
    1. Yes, i think scala is like brainfuck (If you don't know what is "brainfuck programming language" google it!) And this is a big problem. What if code has 20 simple lines, and 10 zipped lines? My point is: do you ever tryed to understund zipp-ed text file in your notepad? It is unreadable, and i prefer to read longer human readable code, than zipped code. Scala is like zip, and this is nothing good. There always is two opossitive sides, one when code you need to write is too long, and second when it is too short. Java is in the middle, it is not to short and it is not too long. It is not the thing, that i'm afraid to learn stupid scala. For me almost everyone now wish to be famous making new "holy programming language and/or framework for masses". And it is usually just shit, because all the good things have been already discovered. The evolution of programming languages is to be more human readable, to create software just by ideas, and the computer do the rest. Only one thing stop us from that - computational power of our computers. We have problem with code-assist on plain text in eclipse on modern fast machines. So think about understanding speech and context, and your spoken just ideas by computer. We need new faster computers, not new programming language like scala. It is worse than JAVA!

      Eliminar
  3. Thanks, I liked a lot. I think this post by Odersky adds to the topic: Simple or Complicated?

    ResponderEliminar
  4. The debate is basically the same age old debate that has been going on since C and Lisp have co-existed: Which is better, the high level of decoupling and abstraction functional programming provides, or the more low level style that is closer to assembly and the way the computer behaves?

    Scala Vs. Java which is simpler is a stupid debate when debated among engineers because those engineers have already been taught how to program in C like languages. Of course they think C like syntax is easier! Ask a Ruby developer whether he prefers Java or Scala, though, and I bet he'll say Scala.

    The real test is to test readability with people who have no programming experience and see which they find easier to use.

    ResponderEliminar