One thing I have yet to see is compiled code that can modify itself safely. Try to poke at your own program memory and the OS will probably go down or segfault or something (not poke in the sense of push memory, but just mess around in general). As an example, here's the start of a calculator I wrote in TCL:
proc num {newval} {
global curnum;
global clr;
if "$clr == 1" then {set curnum 0; set clear 0}
set curnum [expr ($curnum*10)+$newval];
}
for {set x 1} {$x<10} {incr x} {
set txt$x $x;
set no$x [button .b$x -text "$x" -command "num $x"];
}
In a compiled language, this would require a load of 10 button statements (although this is actually 11 lines... I had a way to remove the procedure, but I forgot it and now I'm stuck with this). However, on a larger scale, this could be used to generate something like the insane table in Lamebulun 1, with just a few lines of code. I chose TCL for this, as it's block formatting and positional syntax make it ideal for a mess like this.Another useful trick with interpreted code is perl one-liners and similar. Taken from the linux gazette:
perl -wlne'BEGIN{$b=rand$=}$a=qw/Up exit Down/[($_<=>int$b)+1];print eval$a' A compiled language like C would require you to have some overhead, i.e. stdio.h, explicitly defining vars with types, etc. When you start playing with perl, ruby or similar languages, and understand them enough to code like that, trivial tasks become much easier. Unfortunately, I'm not really at that level yet with any language, so trivial tasks have to be performed manually.My final point about scripts/interpreted languages, is that they are almost forced to embrace open source principles. If you write a script, people are going to read it. It can't be helped. I somehow don't see someone selling a script with a standard license, saying you can't reverse-engineer it. Whilst a license may not permit you to modify and re-release code, you can still learn from it, which is almost as good.
This article was originally written by rekless |