Thursday March 23, 2006 I made some comments recently about scripting languages that generated flame storms in a variety of places. For example, JDJ and Artima. Yes, I did say those things. But there's a lot of context missing, and they're the flippant soundbite version of what should have been a long and careful explanation that could easily mushroom into a series of PhD theses. Amongst all the flamage there are all kinds of generalizations about "scripting languages" versus "compiled languages". My big problem with a lot of it is simply that these two polarizing categories are a pretty poor way of capturing the distinctions between language designs. The terms are almost as goofy as "Republican" versus "Democrat". Taking huge multi-dimensional spaces of choices on different issues, then combining and simplifying them all down to a brutally simple binary choice is goofy.
Over the years I've built quite a lot of scripting systems. I've also built a number of compilers for non-scripting languages. Given enough beer I'll even admit to having implemented a Cobol compiler for money in the deep dark past. But I've done more scripting systems than non-scripting systems.
There are issues in the tradeoffs between the two linguistic spaces all over the place. Someday I'd like to write a long tour through them, but there just aren't enough hours in a day. I have a hard time getting enough time to do even trivial blogging: being truly thoughtful takes a lot of time. But I'll try to cover a few.... For now, I'll make the generalization that "scripting language" means one that is interpreted with dynamic runtime typing, and the other camp is languages that are compiled to machine code and have static runtime typing. This is a broad over-simplifying generalization, but it matches pretty well what goes on in common conversations.
Raw execution performance: One of the usual arguments for scripting languages having acceptable performance is that the overhead of interpretation and dynamic typing doesn't matter. The performance of the system is dominated by other factors: typically IO and the language primitives. For example, PERL apps usually spend the majority of their time in file IO and string primitives. I've strongly made this argument in the past, and it's quite valid. But having observed developers usage patterns, the two most common things that happen to erode the argument are:
There are a variety of middle-ground solutions:
| v:=e | Declares v to have the same type as e, and assigns e to v. "x:=r*sin(t);" would be roughly equivalent to "double x = r*sin(t)". |
| v:==e | Just like :=, except that it makes v final |
There's a lot more to say, but this is enough for today...
Permalink
Comments [21]
Posted by Hon Hwang on March 23, 2006 at 01:46 PM PST #
Posted by Dave Benjamin on March 23, 2006 at 03:20 PM PST #
For example:
var x = new Foo();
And the compiler changes var to Foo for you. I honestly do not see what this gives me. In fact I think it is dangerous.
Compare the following two lines of code:
Foo x = y;
vs.
var x = y;
Which is more readable and less ambiguous?
Trust me, I am all for ease of use, but not at the expense of other "good" things. Especially since the IDE can help you in that regard.
I believe we have reached a point where the language is "good enough" and now our tools need to help is in other ways.
Netbeans 5.0 is a wonderful way of doing that! :)
Posted by Abraham Tehrani on March 23, 2006 at 03:39 PM PST #
Posted by Joao Pedrosa on March 23, 2006 at 05:33 PM PST #
I know I'm not the only one getting tired of certain people ramble on and on like they'd just be introduced to the concept of a scripting language.
Posted by Ivan on March 23, 2006 at 05:58 PM PST #
Posted by Patrick Wright on March 24, 2006 at 02:22 AM PST #
Posted by Alan Burlison's Blog on March 24, 2006 at 03:05 AM PST #
Posted by Computerworld Blogs on March 24, 2006 at 05:34 AM PST #
Posted by Bob on March 24, 2006 at 05:50 AM PST #
Posted by nemesis on March 24, 2006 at 06:57 AM PST #
Posted by Shahzad Bhatti on March 24, 2006 at 07:03 AM PST #
Posted by Notany on March 24, 2006 at 08:24 AM PST #
"scripting languages that are domain specific, but others are general purpose like Java, C#"
Your view of scripting is so twisted i don't even know where to begin. I just know i wouldn't like to do quick scripting jobs by glueing together other tools with java or C#...
Posted by nemesis on March 24, 2006 at 08:36 AM PST #
=================================================
Shorter Syntax for Common Operations
Java is quite verbose, but this verbosity can be eliminated quite easily:
0. Introduce the <code>var</code> keyword.
EG instead of:
Allow: Similarly allow:1. Make the <code>new</code> keyword optional.
EG instead of:
Allow: Combining 0 and 1 allow:2. For methods and classes make the curly braces optional if there is only one statement. IE like <code>for</code>, <code>if</code>, etc.
EG instead of:
class IntWrapper { public int i; }Allow: And instead of:public String toString() { return "Hello"; }Allow:3. If a class needs to only implement a single method that is defined in either an abstract class of an interface, then allow the method qualifiers, return type, name, and the arguments types to be omitted.
EG instead of:
class MyAction implements ActionListener { public void actionPerformed( ActionEvent notUsed ) { textArea.append( textField.getText() ); } }Allow (only using simplification 3, see below for an example using rules 1 to 3):class MyAction implements ActionListener { ( notUsed ) { textArea.append( textField.getText() ); } }Now an example of combining all rules 1 to 3, instead of:textField.addActionListner( new ActionListener() { public void actionPerformed( ActionEvent notUsed ) { textArea.append( textField.getText() ); } });Allow (using all 3 simplifications): These rules would reduce verbosity, be easy to implement and would be backwards compatible.JUSTIFICATION :
The syntax in Java is quite long and this has led to a number of related languages that have shorter syntax but are otherwise similar, e.g. Scala, Groovy, and Nice. Also there are plenty of requests for features that amount to little more than short syntax, e.g. closures (5014235) and functors (5061325) are closely related to inner classes.
All of these issues could be addressed with the shorter syntax suggested and this would be a relatively minor change to Java yet bring many of the benifits offered by Scala, Groovy, Nice, closures, and functors.
CUSTOMER SUBMITTED WORKAROUND :
Whilst modern IDEs do reduce typing; some people prefer a text editor, some environments like embedded can't run IDEs, and there is always the need to present textual examples in papers, tutorials, books, etc.
Posted by Howard Lovatt on March 24, 2006 at 03:55 PM PST #
Posted by Fuerte on March 25, 2006 at 02:55 AM PST #
I'm not sure sure about all those changes or the need for some of them.
<em>0. Introduce the <code>var</code> keyword.</em>
To make this change, a new keyword would be introduced, causing any program that uses the word 'var' as a variable name (and I would imagine there are quite a few) to fail to compile, requiring tedious changes and full regression testing of any affected class. The only other keywords free for use are 'goto' and 'const', neither of which really seems to fit what you're going for.
<em>1. Make the <code>new</code> keyword optional.</em>
And what happens in this case when some clever maintainer comes along and adds a new method:
public class Bob{ public Bob(){ String str = String(); } // . . . complex logic ... public String String(){ return "Bob"; } }While that case may not be so bad (str probably gets a new value later, anyway), what about this case where a future coder attempts to create a quick utility method for themselves. While they identify the risk to their own code, they fail to check for other errors this might cause.
public class Robert { public Robert(){ Date startTime = Date(); //get the start date to log metrics on total runtime } /** * Returns a new <code>Date</code> object with time set to zero. * @returns firstMillisecondDate date on the first possible millisecond for * a <code>Date</code> object. */ public Date Date() { Date d = new Date(); //used deprecated 'new' keyword to avoid calling self d.setTime(0); return d; } }Again, while these examples may seem be a little extreme, they should not be ignored and would pose a risk to legacy code.
<em>2. For methods and classes make the curly braces optional if there is only one statement. IE like <code>for</code>, <code>if</code>, etc.</em>
I don't see any issues with this one, it makes the code a little confusing if you're not used to it, but it does save a few characters. This reminds me of one piece of syntaxy goodness I always enjoy in Perl that I'd enjoy having in Java. For short, simple if statements, you can prefix the if with the action to take. Here's an example. Instead of:
if(badData){ return; }or if(badData) return;
In Perl you could so this:
return if (badData); or return if badData;
I probably mistype my if-statements once a day when I try you use Perl-style in Java. I don't know, sometimes I just like the way it makes the program read, it's a little more natural for me. I'm sure there a thousands of other programmers out there that would hate, but I just kind of like it. :-)
<em>3. If a class needs to only implement a single method that is defined in either an abstract class of an interface, then allow the method qualifiers, return type, name, and the arguments types to be omitted.</em>
This one would just be another matter of taste. Looks a little confusing and arbitrary to me. I like being able to see exactly what a method is supposed to do: return type, parameters, exceptions, everything. I just see a little risk here, for a maintainablity point of view, for confusing code. Trying to modify someone else's code in the first place is a nightmare, much less when they chose to take shortcuts, either variable names (*cough* var *cough*) or clever tricks with the language to cut out a few curlies.
I think they are all interesting ideas and it's great to hear people being excited about Java and it's future, so keep it up, please.
Posted by Tim on March 25, 2006 at 09:39 PM PST #
Thanks for the comments, I didn't really explain myself that well on some of the points - so I will try and do better :)
1. Sure <code>var</code> is a new keyword and you would have to refactor code. Refactoring isn't too bad these days because IDE's are good. Also you could compile with <code>-source 5</code> (or similar). I didn't find the introduction of <code>enum</code> to be a problem and I guess <code>var</code> would be the same.
2. A method having the same name as class would have to be qualified like any other name clash (or use <code>-source</code> and or refactor), e.g.:
public class Bob{ String str; public Bob() { str = this.String(); str = new String(); } String String() { return "Bob"; } }Just a further note on <code>new</code>; I am not preposing that it is deprecated, it is needed to qualify use as above.3. Not needing curly brackets and default for overridden methd, sure some people may well prefer the longer form. It might even be possible to use a pretty printer to swap to your prefered form, e.g. Jalopy does this for <code>if</code> etc.
Thanks again for your comments - Howard.
Posted by Howard Lovatt on March 25, 2006 at 11:05 PM PST #
Posted by Marcos Eliziario Santos on March 27, 2006 at 09:20 AM PST #
Posted by D'Arcy on March 27, 2006 at 11:17 AM PST #
Posted by Morten Christensen on March 29, 2006 at 12:26 PM PST #
Posted by Alex Dolftei on March 30, 2006 at 10:27 AM PST #