On 7 August 2010 18:19, Alexey <[email protected]> wrote: > Something about the recent (not just this particular discussion) > debates about Scala and Java has been bothering me. Something isn't > sitting right. I think I may have figured it out. Scala is being > advertised as a functional language. That's all fine and good, except > one can't really compare it to languages like Erlang. Why? Because > the real functional benefits Erlang is famous for do not extend to > Scala, as far as I know. I may be wrong here, but given the fact that > Scala compiles into standard JVM bytecode and interoperates with > normal Java API (bidirectionally) tells me that even though one > programs in Scala in a functional manner, it's actually run the same > way as any other bytecode-based software on the JVM -- imperatively. > > Haskel, Erlang, Java, etc. all run the the same hardware. So why do you feel that a virtual machine would force a language to be imperative whereas a physical machine wouldn't?
For that matter, what does it even mean to "run imperatively"? Imperative and declarative are just different conceptual styles for thinking about programming problems. Admittedly, most languages will tend to encourage one style over the other, and will offer constructs and syntax support for that. Some languages will even make a particular style almost impossible (Okay, I guess you *could* write an entire imperative program using state Monads in Haskel, but why on earth would you?) Object-Oriented is no different. You can write OO in C by putting function pointers in structs and calling them objects. It may not be elegant, but it works, and it's the basis for programming against Microsoft's COM. This is analogous to taking an SAM interface in Java and calling it a function, you can even call it "Function" if you wish; Google does: http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Function.html A functional language is therefore one with constructs allowing you to treat functions as first class values. and yes, Scala *is* Functional: http://james-iry.blogspot.com/2010/03/robert-fischer-finally-admits-that.html Just like we have to be careful about distinguishing between Java-the- > language and Java-the-virtual-machine, we need to understand the > reality of what "functional" means when it relates to Scala. I have > yet to see easy parallelism solutions coming from Scala out of the > box. Yes, we get to use lambda-oriented syntax and an arguably better > type system, but we're not really talking about a total shift in > thinking. I believe you mentioned Erlang earlier. A language widely praised for having actors, which help massively with concurrency. Scala has Actors - in fact, it was inspired by erlang All grant you that actors don't actually *need* functional programming (http://doc.akkasource.org/typed-actors-java) But it helps... > Some people have already mentioned how familiarity with > Scala made them better Java programmers as they were able to bring > some of the good concepts/patterns into their Java code. It's > possible to program in a kind-of sort-of functional style in Java. > Plain and simple. And rightfully people say that doesn't make it a > real functional language. There's a saying: "cameras don't take photographs, people do" The same goes for FP. It's ultimately a paradigm, a style of thinking. The choice of language just affects how easy (or hard) that paradigm will be to use. Just look at joda-time, and google-collections, both are very obviously written in an FP style. > Scala seems nice and I want to invest time > into it for my own personal betterment and maybe use it in the "real > world" as I better understand its strengths, but it's not a functional > language. At best, it's a functional mask on top of the same old > imperative bytecode-driven VM with the same old runtime advantages and > hiccups we've come to expect from Java code. At worst, it's a bunch > of performance sacrifice in order to achieve the above. > End of the day, any language you care to name will be running on von Neumann architecture (http://en.wikipedia.org/wiki/Von_Neumann_architecture) once you get down to "the metal" Far from being a sacrifice, Scala chose the JVM in part because it was so performant, and heavily optimised. > I fully admit that as a longtime Java developer, having achieved a > good level of proficiency, I can be intellectually lazy when > considering becoming a near-total newbie with a new language. But > that's not everything. I also am cautious about mixing up buzzwords > with facts and getting swept up in emotionally charged debates over > technology. On the one hand, emotions are important because sometimes > they are symptoms of real arguments we're not yet able to articulate > properly. On the other hand, there's evidence that sometimes people > are less than forthright when evangelizing technology (the recent Go! > article seems like a prime example of this). Complexity of a language > seems like a pretty tough thing to try to quantify. The best I could > do I think is to provide real-world examples like Dick's. Then people > can debate how well those examples fit their circumstances and whether > the way they were solves was indeed the simplest/fastest/best/whatever > way. Otherwise, we're just kind of pissing in the wind, if you pardon > the expression. > > I empathise 100%, examples are vital! So... there's an interesting discussion here: http://scala-programming-language.1934581.n4.nabble.com/LOC-ratios-wrt-java-td2313912.html#a2313912 about a small Java->Scala conversion. (it goes over 2 pages) The original Java is here: http://github.com/cageface/brains/blob/0ee0bfce5bda549e7a3f778ba6a6ef82a441339e/recommend/MovieLens.java and the Scala here: http://github.com/cageface/brains/blob/b93cacb3944c8af7a8aebfedebed311d3f8516b8/scala/src/main/scala/brains/recommend/MovieLens.scala Judge for yourself which seems simpler :) > On Aug 6, 6:07 pm, Kevin Wright <[email protected]> wrote: > > You can't claim that the numbers I posted are subjective, I counted > > them fair and square! > > *this* post however, will be subjective. > > > > The idea that all kids go to "high school" and have a "grade 11" is > > also subjective :) > > I give you... Kojo!http://netbeans.dzone.com/learn-scala-with-kojo > > > > It's also subjective to simply discredit any methodology that happens > > to disagree with your gut feelings. > > > > Incidentally, the "few object-oriented features" in Scala amount to a > > more complete/purer OO language than the entirety of Java. > > i.e. > > all values are objects (no primitives) > > all members are defined on an *instance* of some class, and are > > capable of inheritance/overriding (no statics) > > > > The way I see it is that Scala = Java > > - the non-OO bits > > - other boilerplate > > - frustrating restrictions > > + FP > > + a world class type system > > > > and yes, that's subjective. At least until someone comes up with > > measurable criteria for "frustrating restrictions" :) > > > > On 06/08/2010, ADRA <[email protected]> wrote: > > > > > > > > > This whole topic is by its nature subjective. Its not like Scala and > > > Java are exact language fits for one another. As I see it, Scala is a > > > functional language that has some object oriented features. Java is an > > > object oriented language with a few procedural features (baggage) and > > > will eventually have a few functional features. If you want to ask > > > which one is easier, ask yourself if you like Wrox or Head start > > > books. Each book conveys the information to you in the end, but each > > > person reading them will have wildly different takes on each style of > > > presenting the content. > > > > > If you really want a quantifiable result, then get a pilot program > > > with two high school grade 11 classes and teach one class Java and the > > > other Scala. Personally, I find Java vastly simpler understand and use > > > vs Scala, but I come from a solid procedural foundation long before I > > > touched java. To forget the educational background of the person in > > > question is a horrible mistake to make in this topic. > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "The Java Posse" group. > > > To post to this group, send email to [email protected]. > > > To unsubscribe from this group, send email to > > > [email protected]<javaposse%[email protected]> > . > > > For more options, visit this group at > > >http://groups.google.com/group/javaposse?hl=en. > > > > -- > > Kevin Wright > > > > mail/google talk: [email protected] > > wave: [email protected] > > skype: kev.lee.wright > > twitter: @thecoda > > -- > You received this message because you are subscribed to the Google Groups > "The Java Posse" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<javaposse%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/javaposse?hl=en. > > -- Kevin Wright mail/google talk: [email protected] wave: [email protected] skype: kev.lee.wright twitter: @thecoda -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
