Friday, May 2. 2008For all you know, it's just another Java libraryTrackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
btw the new netbeans scala plugin is awesome:
-code completion (both java and scala) -debugger -syntax highlighting -rename variables in the file -mark occurrences
"And not to put too fine a point on it, but Martin's team runs one of the best ISVs I've ever seen." I can believe that. I was chatting with some of Odersky's students at a conference when GJ was the current project, and they were laughing about how obsessed he was with fixing bugs in the compiler.
This is an excellent article. I personally think that for a lot of uses Scala's tool support isn't quite there yet, but it's definitely coming along apace since the language has been getting more stable. The growing stability of the language itself actually addresses some of the concerns you mention; Odersky I believe stated that with the book being released and so on, that the newer revisions of the language are intended to be more stable. I think that Scala's getting out of its "experimental" phase and becoming really usable by any scale, and that's exciting.
The interesting thing about making Scala interact with Java is that to do so effectively, you really need to be aware of what you're doing. Scala constructs are usable from Java, but not easily usable. The interface has to be carefully written to work in both contexts fluently, but this is largely the fault of the languages being fundamentally different in emphasis rather than any compatibility issue. Your main point is important. People should use what works best for them. What makes Scala interesting is that it's an effective language set upon a proven base, managing to mix the best of both of those worlds nicely.
"An interesting thing about the JVM. From 1.0 through 1.6, there has not been a new instruction added to the JVM. Wow. Think about it. Java came out when the 486 was around. How many instructions have been added to Intel machines since 1995? The Microsoft CLR has been around since 2000 and has gone through 3 revisions and new instructions have been added at every revision and source code compiled under an older revision does not work with newer revisions. On the other hand, I have Java 1.1 compiled code that works just fine under Java 1.6. Pretty amazing."
Shouldn't you have said that you have Java 1.6 compiled code that works fine under Java 1.1? I mean, to bring the point home. What your example conveys is that no instructions have been removed, not that none have been added.
Nice post!
Another data point for you: I've been using various Java debugging and profiling tools against a Scala-based project, including agentlib-based tools (hprof, jrat, etc) that instrument your program by rewriting bytecodes. These all have worked fine. All those tools were written originally without Scala in mind. I'm also happy to report that Scala works fine with the various Java networking frameworks such as the Apache Mina NIO framework and the Sun Grizzly NIO framework. And, of course, Scala works too with simple blocking socket I/O (java.net.*).
> On the other hand, I have Java 1.1 compiled code that works just fine under Java 1.6. Pretty amazing.
Not half as amazing as the other way around...
I agree completely with your analysis.
Scala is a language that happens to compile to Java byte codes, just like C/Fortran/etc can all compile to x86. My big (performance, rather than operational reliability) concern about code generation is whether the Scala compiler generates bytecodes to implement its language features, or if it generates invocations to Scala's runtime frameworks. If the latter, it would be much more like a threaded interpreted language, such as Forth. (http://en.wikipedia.org/wiki/Threaded_code) --bob (just a nit, but new bytecodes have been added, for example, invokedynamic http://jcp.org/en/jsr/detail?id=292)
Bob,
The analysis is different than compilation to X86. If you compile to X86, there are different calling conventions, different stack layout conventions and there's no way a GDB will work with a compiler that I write unless I follow the same conventions that GCC follows. Put another way, please cast your memory back to the impendence mis-matches between Pascal and C calling conventions on Windows and Mac or the hassle of debugging a name-mangled C++ program with a C debugging tool. None of that was fun. On the other hand, the JVM's byte-code is well defined, verifiable and has a single stack frame layout. Further, the semantics of Scala are very close to the semantics of Java (single inheritance, strongly typed, etc.) Scala calls on the stack intermingle with Java calls without proxy code or other things that languages such as JRuby need. Scala instances look, smell, and taste to the JVM just like Java instances and the Scala compiler emits the right class meta-information to make the Scala classes inspectable in jdb. Thus, it's possible to using jdb and other Java tools with Scala code. As to your comment about invokedynamic... that is proposed for Java 1.7 and is not part of Java 1.6. As to the above comments about running Java 1.6 code on a 1.1 JVM... that's not possible because the 1.1 JVM does not have 1.1 libraries and new methods on String, Double, Float, Int, etc. will be missing.
David, I guess I should have said VAX rather than x86. The calling conventions on the VAX were standardized across all the languages, and one DEBUGger supported all the languages, including inter-language calling, including BASIC, DIBOL, COBOL, C and Pascal and Fortran and PL/I. --bob
Bob,
> My big (performance, rather than operational reliability) concern about code generation is whether the Scala compiler generates bytecodes to implement its language features, or if it generates invocations to Scala's runtime frameworks. The Java-like subset of the Scala language compiles to bytecode very similar to what you'd get from javac. For the more advanced features: Closures are instances of anonymous classes that implement a simple interface. Captured immutable variables are done exactly as in Java's inner classes. Captured mutable variables are done with an extra level of indirection through another heap allocated object. Pattern matching is done in part through generated code, in part through "instanceof" style checks, and in part by calling an "unapply" method on an either a user supplied or compiler generated object. The exact mix depends on your pattern match. Lazy parameters are syntactic sugar for 0 argument closures. Lazy vals are the same, but memoized. Structural types are done using Java reflection, so there is some expense here. XML is largely done via libraries. Hopefully this gives you some feel for the performance characteristics implied by various features. As always there's no substitute for performance testing.
I have a huge people search applcication I will like to build using scala with lift. Anybody interested contact me at mondscheinsonate heart t.online dot de. Thanks
Nice article, David. Thanks.
Honestly tho, I don't think Java developers should be the focus of whatever marketing goes on with the language. Those functional kind of oopy things have been going on with scripting languages for the last few years. PHP, Java, and Ruby programmers might love the power that comes with the JVM and the lean methodology that is Scala. You can also consider me jealous that you're making a living with Scala, I'd love to make my full time gig something Lift related. |
David PollakCalendar
QuicksearchCategoriesBlog Administration |
||||||||||||||||||||||||||||||||||||||||||