Language Subversion Response

Factored from TheLclass to avoid detracting from the original dialogue:

I can't accept the notion that this is a "subversion" of the language. It uses regular features of the language to provide a very useful notation oriented syntax not provided by the base language. It does nothing that is intended to obscure Java syntax, only refactor the duplication of

List foo = Arrays.asList(new Object[] { some arguments });
List bar = Arrays.asList(new Object[] { some other arguments });
Perhaps if you don't naturally see that this is a common form of duplication and want to get rid of it for that reason, you'd call it a subversion. -- JeffBay

Well, you subvert the "spirit" of Java because it wasn't designed to support convenient data structures, nor was it designed for flexibility, so like someone observed, TheLclass is an "abomination" as far as idiomatic Java is concerned. But to subvert, a language like Java to make it do what is needed as opposed to what it was intended for, well, that's a virtue.

In the same spirit, for example you can create inner procedures:

 Class X {
 //...

void algorithm (...) {

// and now you needed an inner procedure int subStep(...), // or at least that's how you used to do it in Pascal, what do you do ?

class SubStep1 { int _ (param1, param2) { // ... here you can access enclosing variables just like in Pascal } } final SubStep1 subStep1= new SubStep1();

//... // and in the main body of the algorithm, // see, it now looks like a call to a procedure, not like invoking a method on an object subStep1._(x1, x2); //... } }
With many thanks to the genius of GuySteele who let some (not nearly enough) Scheme creep into Java through the back door.

Although quite why failing to block some folk's desire to write Pascal in any language is an act of "genius" is not clear. Why not implement the steps of algorithm() using TemplateMethod?

First of all, TemplateMethod has nothing to do with anything, other than YAGNI. Second, writing in Pascal is quite an honour, and the fact that Java does not have procedure and inner procedures is not some kind of virtue for Java, nor is it any virtue that real modules were lost along the way.

Depends what you mean by Pascal. Standard pascal isn't such an honor to write programs in - it lacks strings beyond 255 length, and is about as bad or worse than programming in C. The 255 string length is not the only problem, the strings are FuBar for other reasons too. Improved versions of Pascal such as Delphi are indeed an honor to write in (well, sort of). The object wheenies have taken over the delphi language and it is becoming the next Ada (a large complex language rather than a simple one). Delphi has two object systems; old turbo pascal style borland objects and new delphi classes (yuck, violating OnceAndOnlyOnce). Niklaus Wirth would definitely not approve of this complexity and EvolvingLanguage (he'd prefer a designed language which trimmed this extra junk away, so I'm not sure if Delphi can even be considered Pascal, it's something else more like an Ada - a language of its own).

For the purpose of writing algorithmic code Pascal is an improvement over most of its successors.

[Yeah, this is a hardcore case of damning Steele with faint praise.]

I'd bet that Steele would be happy to know that his additions to Java language allow people to write Pascal style code in Java. This shows how much more advanced is Java in comparison to C++ and, of course, in comparison to CeeSharp. As a matter of fact this can even be thought of ML style since they apparently arranged it on purpose that classes inside methods can only access method variables declared final in the scope of the method. So unlike in Pascal you can't modify the content of an outer variable. And also just like in ML you need to make references explicit.

Now of course, if one really wants Pascal and not ML, here's the way to declare the VAR section:

 voir myProcedure(...) {

class VAR { int x1= 1; String x2="x2"; int i; } final VAR _ = new VAR() ; // those will be the method's variables

class SubProcedure? { int _ ( int arg1, String arg2) { _.x1 = arg1; // this is assignment in the outer procedure "scope" _.i++; // this was an INC(i) } ... _.x2 = ""; subProcedure(arg1,arg2); }
Now because Java is a much lesser language than Pascal, the VAR trick in Java does not scale quite nicely with the level of imbrication. That is because a new _ VAR object inside the subProcedure will mask the _ VAR object in the method scope, so a subSubProcedure will not have access to the identifiers of the outer method. However, there's a nice workaround even to that: use _1 instead of _ for the VAR section inside the sub-procedure, _2 inside the sub-sub-procedure so inside a deeply imbricated procedure _k. will address the variables in the procedure at the level k of imbrication.

  class SubProcedure? { int _ (arg1,arg2) {
    class VAR { int i=0 } final VAR _1= new VAR();

class SubSubProcedure? { void _ () { class VAR { int x; } final VAR _2 = new VAR(); _.i++; //refer to i inside the method _1.i++; //refer to i inside the subProcedure; _2.x++; //refer to x inside the subSubProcedure; }} final SubSubProcedure? subsubProcedure= new SubSubProcedure?();

_1.i++;

}} final SubProcedure? subProcedure= new SubProcedure?();
Of course, one is not a real Pascal programmer until one reaches at least level 3 of imbrication (not to mention imbibition).

Pascal is dead, which one are you talking about? Standard Pascal? Apple Pascal? Delphi? ISO Pascal? Extended Pascal? Java has strings beyond 255 characters, so Java is superior in this respect to standard pascal. You can't just say that Java is a lesser language because in some ways Java is much better/greater than Pascal. Any language that has strings beyond 255 characters is better than standard pascal! That's why people use PHP, Java, C++, and Delphi instead of old Pascal, because Pascal, like CeeLanguage, didn't get strings right. People use strings every day, and Pascal doesn't have good strings, they are FuBar. If you can't get strings right, your language will die. NiklausWirth has failed to get strings right so many times. Even in his latest OberonLanguage, strings are still FuBar because you have to predefine the string length instead of it growing automatically like in PHP, Java, or Delphi. Wirth hasn't learned his lesson and probably never will. Delphi is not Pascal, so what do you mean when you say Pascal?


EditText of this page (last edited April 14, 2012) or FindPage with title or text search