Line Noise (was Punctuation as noise)

Discussion in 'Ruby' started by Jim Weirich, Aug 21, 2003.

  1. Jim Weirich

    Jim Weirich Guest

    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 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)
    Jim Weirich, Aug 21, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Leffer

    Regular expression for punctuation

    Chris Leffer, Jul 9, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    412
    Chris Leffer
    Jul 9, 2003
  2. Chris R. Timmons

    Re: Regular expression for punctuation

    Chris R. Timmons, Jul 10, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    466
    Chris R. Timmons
    Jul 10, 2003
  3. DBLWizard
    Replies:
    10
    Views:
    733
    Brock Allen
    Apr 2, 2005
  4. Peter Strøiman
    Replies:
    1
    Views:
    2,056
    Peter Strøiman
    Aug 23, 2005
  5. Adam Hartshorne
    Replies:
    1
    Views:
    640
    Victor Bazarov
    Jul 9, 2005
Loading...

Share This Page