Program Intoa Language

A valuable piece of wisdom coming from TheScienceOfProgramming. Or at least that's where I got it. It may sound controversial nowadays, and especially on wiki, but I think it still is generally a good piece of advice although there may be exceptions from the rule here and there.

The idea is that the programmer should design the program as if he/she has the most perfect programming language available. And then the implementation will become a translation exercise into the language at hand. The main idea is that programmers should avoid being sucked into the idiosyncrasies of any particular language.

The programming then becomes an exercise in translating a design (or at least a plan of attack, a sketch, etc.) that should be based on general computing science constructs that are adequate for a particular problem, into the particulars of a programming language.

For example, regardless that SQL is not exactly relational you can imagine yourself operating strictly in a relational environment, and just find the means to translate relational operators into SQL. The idiosyncrasies of SQL become then irrelevant. Like AlwaysUseSelectDistinct.

Another example is that by twisting Java a little bit with lots of classes inside methods, you can easily make it like you program in a really functional language. One can even program in Java like in classical Pascal. I translated a Pascal approach in Java, with a VAR declaration, and procedures inside procedures, and procedure variables and parameters and all that jazz, and it even look superficially similar (couldn't trick it to use := for assignment, however :).

Languages become then a very secondary concern, in the general case. Of course, when some language makes it very difficult for one to translate an element into it, one has to be aware of that. Most current languages suck and will be overridden by later developments, and such the ProgramIntoaLanguage attitude can give a lot of satisfaction and fewer emotional attachments (Python vs Java vs Ruby vs Smalltalk, oh dear:) ). It struck me recently how in this day and age, decades after Dijkstra and Knuth preached about non-determinism and co-routine and asynchronous I/O (async IO is discussed in the very first volume of TheArtOfComputerProgramming as the natural order of things in programming computers), still both Java and .NET platforms are so fundamentally synchronous and fundamentally missing essential features. Therefore it pays dearly to become emotionally attached to any particular language, and not see the greater picture, whereas languages just become lesser details, obstacles to be overcome in the translation process.


I think a very funny application of this principle is in the JScheme implementation of a Scheme interpreter in Java. Some very talented and capable schemers have done it, but if somebody with a Java mindset looks at the code, oh the horror !! The key to reading that code is that all the rules, patterns and idiosyncrasies of Java should be put aside. The guys were programming a Scheme interpreter the way they saw fit, and the conventional idioms of Java could not have mattered less.


See ThinkObjectsButWriteAssembler ThinkObjectsAnyway DomainSpecificLanguage


EditText of this page (last edited November 15, 2004) or FindPage with title or text search