2008-02-15

Esoteric Programming Language: CopyNPaste

Well, there is just a good bunch of Esoteric Programming Languages on the market, some really serious (means: causing serious damage to your brain), some meant as a joke .

Sigh, would I have more time, I could contribute with an idea for a new one.

What makes modern PLs so successful? It is that they express common programming patterns and paradigms directly on the code level.
A good example is Scala, which incorporates e.g. the singleton pattern with the keyword 'object', or implicit getter/setter generation for a property (you find that in Groovy too).

And here is the new idea, here is one pattern which was never implemented on language level:
Copy and Paste.

Really, a such often used pattern, and no language designed for it ....

And it would be so easy!

Simply take a base language, say: Java.

There you could have a class with a method, say:


1 public class MyTest {
2 ...
3 public Collection doSomething(Collection input) {
4 Collection newcoll = new SomeCollectionType();
5 Iterator iter = input.iterator();
6 while (iter.hasNext()) {
7 Element elem = (Element) iter.next();
8 Object someNewElem = somethingReallyImpressingDoneWith( elem );
9 newcoll.add( someNewElem );
10 }
11 }
12 }


In Java, adding a new method which also iterates over its input, but does some other impressing stuff with the elements and does not return a collection would be very annoying. You would copy and paste the above method and change the parts which shall differ from the original version per hand.

But why doing it yourself if your computer can do it for you? So it would be much better to simply tell your computer what to do, and the best way is to make this an integral part of the language itsself.

So the job could be done very easy with CopyNPaste, a language based on Java, but with additional features:


1 public class MyTest {
2 ...
3 public Collection doSomething(Collection input) {
4 Collection newcoll = new SomeCollectionType();
5 Iterator iter = input.iterator();
6 while (iter.hasNext()) {
7 Element elem = (Element) iter.next();
8 Object someNewElem = somethingReallyImpressingDoneWith( elem );
9 newcoll.add( someNewElem );
10 }
11 }
12
13 paste:: copy(L:{3-11}) -> {
14 onLine(1): s/Collection/void/ s/doSomething/doSomeOtherThing/ ;
15 delLine(2);
16 delLine(6);
17 onLine(5): delChar({1-21}) ; s/thingReallyImpressing/OtherThing/ ;
18 }
19 }


It will indeed become more interesting if the second method will be used as template for a third one ...

The advantages are obvious: You have to think only once about the way the first method doSomething() shall work. Then you are free to concentrate on how the method doSomeOtherThing() differs from that method.
You are free to think in your copy and paste paradigm without leaving this context when doing the new coding.

Thinks can be so easy ...

Keine Kommentare: