From: Jim Weirich Date: 2003-08-21T10:23:39+09:00 Subject: Line Noise (was Punctuation as noise) On Wed, 2003-08-20 at 13:49, Hal E. Fulton wrote: Hal Fulton wrote: > I cranked out a quick bit of ugly code (see > below). Obviously it's crude -- e.g., it doesn't > take note of strings or comments (and it's not > clear what it should do if it did). I did something like this a while back when a Java programmer complained about all that "line noise" in Ruby. I pointed out that Java used much more puncuation than the typical Ruby program and wrote the following program to demonstrate... #!/usr/bin/env ruby ARGV.each { |fn| noise = open(fn) { |file| file.read }.gsub(/[A-Za-z0-9_ \t\n]/m, "") puts "#{fn} (#{noise.size}): #{noise}" } Runnnig this over a set of programs written in different languages gives... animal.cc (83): #<>{:()=;};:{:();};::(){::<<"\";}:{:();};::(){::<<"\";}(){*[]={,};(=;<;++)[]->();;} Animal.java (67): {{();}{(){..("");}}{(){..("");}}([]){[]=[]{(),()};(=;<.;++)[].();}} animal.pl (41): ;{{};}{"\";};{{};}{"\";};$(->,->){$->();} animal.py (23): :():"":():""[(),()]:.() animal.rb (10): """"[.,.]. Onestepback.org is down at the moment, but I'll post the code for all the animal programs there when it comes back online. -- -- Jim Weirich jweirich@one.net http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)