News for hackers. Stuff that matters.
Re:Why Scala seems difficult but really isn’t by mark242 on Wednesday June 22, 2011 @11:15AM (#2683456)
"The perfect Java replacement would have"...

"local type inference". That's Scala. List(1,2,3)

"less verbosity (e.g. public by default)". That's Scala. def myMethod(arg:Int=1, arg:String="myDefaultValue") ... with no boilerplate crap.

"full closures". That's Scala. val myImmutable = { runThisCode }

"anonymous blocks". That's Scala.

"no generics". That's-- more or less Scala.

"special syntax for arrays and hashes". That's Scala.

"operator overloading". That's Scala.

"the ability of a variable to behave as if dynamic". That's Scala.

"I would also completely purge checked exceptions". Scala, so long as you stop writing try catch blocks.

"and also get rid of the general syntax for anonymous classes". Scala.

Look, I just recently rewrote a ten-thousand-line Java web app into Scala. I got-- no joke-- 75% code reduction, and the only reason I didn't get more was due to the fact that I decided to stick with Struts2 instead of moving to Lift.

Think of your typical method that accesses a Hibernate named query, and returns a boolean as to whether or not that item exists.

Here's the Scala version:

def domainExists(domain:String) = Option(HibernateUtil.getSession.getNamedQuery("domain.findByName").setParameter("name", domain.trim.toLowerCase).uniqueResult.asInstanceOf[Domain]).getOrElse(new Domain()).id > 0

That's a one-liner, and I'm sure there are Scala experts out there who could reduce that code even further.

Re:Why Scala seems difficult but really isn’t by pdhborges on Wednesday June 22, 2011 @11:26AM (#2683514)
Here is the Java version:

  public boolean domainExists(String domain) {
    return Option.of((Domain) HibernateUtil.getSession().getNamedQuery("domain.findByName").setParameter("name", domain.trim().toLowerCase()).uniqueResult()).getOrElse(new Domain()).id > 0;
  }
Re:Why Scala seems difficult but really isn’t by bad_user on Wednesday June 22, 2011 @12:38PM (#2683888)
You made more or less my point -- but my point was that Scala provides too much; and I don't want to choose a subset, as my subset will be different than yours.

Also, I would like a language that's as close to the JVM type system as possible, yielding the same performance as Java in all instances (including on Android, where Dalvik doesn't have the same GC and optimization characteristics).

     "no generics". That's-- more or less Scala.
Generics are an inherent part of what Scala is. Surely it takes care of some gotchas, but I see many code samples where I feel like puking.

Generics weren't really meant for languages without Hindley-Milner.

     "the ability of a variable to behave as if dynamic". 
     That's Scala.
Scala is not dynamic by any stretch of imagination, no matter how much wishful thinking you can incur because it has structural typing -- I see this notion flying by all the time, but people generally don't know what they are talking about.

E.g. you don't see people saying this same thing about Haskell, when compared to Lisp, even if Haskell is even more concise than Scala, taking structural typing to extremes.

What I mean was that I'd like something like the dynamic types in C#.

Re:Why Scala seems difficult but really isn’t by riffraff on Wednesday June 22, 2011 @12:56PM (#2683983)
I believe grandparent point about dynamic variables is the newly introduced Dynamic type in scala 2.9.
Re:Why Scala seems difficult but really isn’t by bad_user on Wednesday June 22, 2011 @05:19PM (#2685335)
Oh, sweat, I may be wrong but that's what I wanted.

Unfortunately, for now it is an experimental feature. But thanks for pointing it out, it seems that it's coming :)

Re:Why Scala seems difficult but really isn’t by mark242 on Wednesday June 22, 2011 @01:34PM (#2684165)
"You made more or less my point -- but my point was that Scala provides too much; and I don't want to choose a subset, as my subset will be different than yours."

Sorry, but that's the most ass-backwards point I've heard. The language provides too much power and flexibility, and you want to be locked into one specific format, syntax, and the subsequent reinventing-the-wheel nightmare that causes most projects to go horribly over time, budget, and stress levels?

Re:Why Scala seems difficult but really isn’t by lemming on Wednesday June 22, 2011 @02:31PM (#2684436)
Um, I think you might be over-attributing language features to project failure, there.

The language subsetting issue is a huge problem, c.f. C++. The complexity of Scala makes it very difficult to understand a lot of library code, even if you're quite competent in it. To keep code for a large code base manageable and understandable, most companies will end up defining the "allowed Scala" in a coding standard. This is a failure of the language, IMO.