Post-Programming for Dummies

February 15, 2008

new examples of usefulness of meta-programming compiler

Filed under: Uncategorized — ppfd @ 8:28 am

example 1:

meta: ExpandComparators

if a < b < c < d < e
puts “a < b < c < d < e”
end

meta: End

becomes:

if ((a < b) && (b < c)  && (c < d) && (d < e))
puts “a < b < c < d < e”
end

obviously useful if you are doing this sort of comparison a lot.

Another example:

ruby compileMeta.rb –fixToS  myProgram.rb (this doesn’t even need to be run on a “rbm” – ruby meta – file)

will turn, for example:

puts “testVal: “  + 1 + “!=” + 2

into:

puts “testVal: ” + 1.to_s + “!=” +  2.to_s

Now, that last example might not seem like much, but consider:

1.) It is an unambiguous error (i.e. there is nothing else that could POSSIBLY be going on)

2.) I make it a lot

3.) This can be just one of many possible unambiguous and common errors that I make – I can have a flag like –fixMyErrors so that the call to the ruby interpreter becomes:

ruby compileMeta.rb –fixMyErrors myErrorFile.rb myProgram.rb

myErrorFile.rb can also do more intelligent things like check parens.

One final possible counter-argument is that this functionality could be replaced with a good IDE. Nonsense! First, show me a good IDE. Second, now that you’ve shown me Emacs, does it have a good, easy-to-use way of implementing these kinds of changes? Is it ruby-specific? Oh, I have to know Lisp? So I have to learn Lisp to write Ruby?

Anyway, I am continuing to try to justify this time-sink, as you can tell.

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.