Scripting Languages of the Fourth Generation

Coffeescript is a mighty language
Why Python and Coffeescript are not given justice calling them scripting languages but instead should be seen as higher programming languages of the fourth generation: In the past weeks I have investingated the power of scripting languages and I want to share some insights with you to clean up with some prejudices about them.

For a long time the classical server-side language Java had been the dominant force of the backend development. It more and more displaced a large part of the in scientifical communities much condemned Perl and PHP development because of its clean and pure object-oriented concepts. A lot of Java application servers raised since then, all of which made the effort to increase the staff of efficiency. This brang a whole industrial community underway to more and more focus on web development.

In the midst of the 00s other scripting languages like Python and Ruby gained more and more momentum in backend development. They have been favored over Java many times as they implemented the object-oriented concepts even more pure and easy. It was the great success of them that they made the object-oriented development reachable for a non-scientific community that honored its ease of use without having the much feared configuration hassles and verboseness of Java.

Also, as the web development has gone more and more popular since the 90s, the scripting language Javascript came into the spotlight and established as a mainstream language for web developers as it were Perl and PHP on the server-side since then. However, there never was a real alternative to Javascript, so it has undergone a decent development since then and integrated object-oriented concepts in an ugly but indispensable way. Using prototypes and blocks in Javascript became a mighty but unmaintainable experts system which has never been understood by the many rookies of web development.

This has been the main reason why you find a lot of indisputable unmaintainable examples of code in the web still of today. Javascript has been given much contempt and hatred as it has been the least common denominator for the browser developers. However, its ugliness can be indisputably used in a good kind of way since the browsers agreed on a standard. As Python and Ruby have raised on the server-side a new language called Coffeescript fully compatible with Javascript but a real alternative to it seems to raise which combines the strength of Javascript with a deuglified syntax similar to Python and Ruby.

This blogpost claims, that even the much dishonored front-end-development with Javascript inside of browsers can enter a golden age, if a maintainable and simple languages raise, which can be flawlessly handled by everyone. As Java and C++ were called the third-generation languages, which made the development an engineering task, the ease of use of modern scripting languages is giving back their advantages to the mainstream developers. So they can be quite evidently called fourth-generation languages as they open up to everybody, what has begun as a scientific discipline with Java and C++ (even if the term 4GL language is used bewilderingly by someone else).

In the following I compare the most important features of object-oriented languages for most of the mentioned languages and describe their advantages and disadvantages. I compare the syntax of the higher programming languages of the third generation (C++, Obj-C, JAVA) to the modern scripting languages Python and Coffeescript.

Let’s first take a look to the syntax of calling methods. This brings us to the awareness that the concrete syntax only differs slightly in each case and that the concepts stay the same in either way.

C++: object->method(param1);
Obj-C: [object method:param1];
JAVA: object.method(param1);
Python: object.method(param1)
Coffee: object.method param1

Another often used but much underestimated feature is to call an object method only if the object exists. This example demonstrates well that especially Python and Coffeescript much take care of what Wikipedia calls „natural language“ of a higher programming language. Only Objective-C completely ignores messages to empty objects and needs no check for that. Another nice convenience in Python and Coffeescript is, that the last statement of a method also defines its return value.

C++: if (object != null) { object->method(param1); }
Obj-C: [object method:param1];
JAVA: if (object != nil) { object.method(param1); }
Python: object and object.method(param1)
Coffee: object?.method param1

We should also have a look at the declaration and initialization of objects in either of the host languages. They all have their own stringent concepts, the first three ones with a lot of semicolons and brackets, which gets confusing if you nest the code a lot.

C++: string value = new string("Hello World!");
Obj-C: NSString *value = [[NSString alloc] initWithString:@„Hello World!"];
JAVA: String value = new String("Hello World!");
Python: value = String("Hello World!")
Coffee: value = new String "Hello World!"

My favorite experiment to test how „natural“ a language is, is to check how it iterates over a list or array. There, a natural language really shows its advantages. But build your own opinion with the next lines of code:

std::vector cubes = std::vector cubes;
for (std::vector::iterator num = list.begin();
num != list.end(); ++num) {
Obj-C: NSMutableArray *cubes = [[NSMutableArray alloc] init];
for (num in list) cubes.addObject(Math.cube(num));
ArrayList cubes = new ArrayList(); 
for (Integer num in list) {
Python: cubes = [ math.cub(num) for num in list ]
Coffee: cubes = (math.cube num for num in list)

In the following I will show how a class with a private setter property is declared in each of the languages. In this example you can also see what brackets, semicolons and missing indentation does to your code. Though nesting gets ugly very fast, only Python and Coffeescript discourage the nesting by syntax (indentation really is a syntax feature). The first three languages do that only by convention (you can indent if you want) but not generally disallow it, which can lead to spaghetti code.

class Rectangle {
int _property;
public: void setProperty(int);
void Rectangle::setProperty (int a) { this._property = a; }
@interface Rectangle : NSObject { }
@property(assign, readonly) int property;
@implementation SomeClass
@synthesize property = _property;
class Rectangle {
private int property;
public void setName(int property) { = property; }
class Rectangle():
def setProperty(value): = value
class Rectangle
setProperty: (value) -> = value

In my long-years experience, the programmer community already has recognized and pointed their fingers on the mistakes, which have been made in software engineering during the last decades. What really is ugly style of programming much detracts from the real story that a program has to implement. What can be done is to improve the syntax of programming languages stepwise. A lot of languages like Python, Coffeescript, Java and Objective-C do a great job of improving their languages again and again watching their users. Though, still a lot has to be done. In the following I present a list of „show stoppers“ people are complaining about in these languages regularly.

C++: pointer arithmetics, verboseness, brackets / commas / semicolons
Obj-C: verboseness, brackets / commas / semicolons
JAVA: verboseness, configuration hassle, brackets / commas / semicolons
Python: missing typechecking (but instead improved readability, that seems a fair compromise)
Coffee: missing typechecking (but instead improved readability, that seems a fair compromise)

How much time could be better spent than checking the bracket syntax. So this blogpost really sets its glimpse to the ease of use of the languages and is just a praise to appreciate the great efforts these scripting languages gave us so far. Happy coding.
blog comments powered by Disqus