Monday, November 29, 2010
Scala an alternative to Java for programming
Scala as an alternative programming language looks credible.
Being a Java programmer, my summary is going to be more from that perspective. Java developers could look at it as a replacement for "javac" or in simpler words, a new ".java File parser" for Java which supports a new Programming style. Of-course there are scala (Java) classes /APIs to support that. It finally generates Java code and byte code ! That's similar to what JRuby or groovy does. It runs on the JVM.
Hence it could look like a language created to solve the top X problems perceived in Java from a programmer productivity point of view, rather than a language built from the ground up from a performance / stability standpoint. That is fine as long as it is done well, overall. As a matter of fact, it could make sense, as the Java strength is the maturity of the JVM.
Another way to look at Scala is something that Java itself did not do till date. Making more intelligent use of the compile time knowledge. It would be great if Oracle could bring this to the table. Another main capability is Scala bringing in more previously framework features right in to the programming language.
Some cool stuff : Lots of stuff that could be done in Java itself in compile time has been done.
- Primitives treat very very large objects the same way as smaller types. [Java fuss] Why have BIGINTEGER class for it ? Make it as simple as handling int values.
- maps contain a - calling a method in operator notation : In Scala everything is a function. Including operators. At-least that's what they want us to believe.
- Lots of smart compiler time gimmicks like the "Conversion Method" eg. he talks about that avoids an extra public static method call to create a Wrapper Object just for compilation sakes. This can reduce calls to Integer.parseInt.... It works by picking up just one resolving identifier from scope. if more present, it gives error.
- Using three "=" sign is a new syntax introduced for assertions. Eg. assert (result === 17)
- Usage of triple quotes to insert CSS etc are good syntactical makeup.
- Everything is a method. so =, +, == etc are also treated as methods.
- Duck typing : is the ability to call methods of another class, with the same method structure of a class, even though they have no common super object. Same method structure eg. getLength method in MyOwnClass.java and Array.java can be called by a parent method easily.
- Scala's additional features will reduce the need for tools outside of the language (eg. Spring Framework) and this will help programs become more maintainable.
- You can use all the Java APIs inside Scala as its finally generating Java Code. Hence you still have the capability to use all Java APIs out there, inside Scala. No re-inventing the wheel.
Anecdote :
Of course there are arguments that, many of the design patterns spread by the gang of four were actually programming language constructs and not patterns.
Some of the things that make me feel a bit edgy are :
a) It still uses the JVM. Hence we still run the same risk from a licensing perspective (from Oracle).
b) Not sure if it is mature enough for projects that run for over five years with medium sized teams. I stress on this as I have seen that Java as a programming language is very useful in this case as it reduces the effort to make changes or introduce changes. This is something I feel a company like us should really worry about long term. Writing "Hello World" programs are not enough. For eg. imagine the flexibility of "threadlocal" as a simple concept that allows SAS magic on any mickey based products etc.. Programming platforms should support that level of "insight" built in.
c) Debugging will look odd : The runti me is as stable as the JVM, as its finally byte code. The fact that your code will be called by a wrapping Java class will make it feel odd. For peculiar errors, you may actually go to the Scala generated Java files. Look at it like, sometimes we go to the generated .java Servlet file when trying to debug a peculiar problem in the JSP.
d) Being a Wrapper around normal Java code means that it is not superior than Java performance, but could still strive to be better than other programming languages like Ruby or python from a performance standpoint.
Anecdote :
Nearly all languages first bootstrap the new language in some existing language, and then rewrite the compiler in the new language they create. So Scala is written in Scala and Javac in Java.
References : Video on Scala named "The Feel Of Scala" by Bill Venners. Bill Venners is a very credible Java guy (Artima fame), great presentation style.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment