Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Rewriting creation (with strict and warnings)

by benn (Priest)
on Aug 30, 2003 at 13:51 UTC ( #287907=poem: print w/ replies, xml ) Need Help??

Wondering about the whole human condition recently, I decided to have a look at some early source code to see if it could be tightened up in any way, or even spot any glaring bugs. Ovid has had a look at Genesis before (which I think may actually be part of the Vedas:: namespace), but I wanted to check out the main 'init()' routine.

A quick Perl-rewrite-hack of John 1.1 initially produced the code below. Note - all code is untested - I didn't dare run it until after peer review.

#!/usr/bin/perl use strict; use warnings; my $word; BEGIN { # In the beginning was the Word, # and the Word was with God, and the Word was God. $word='God'; # Note 'the'...obviously He intends a scalar... # The same was in the beginning with God. my $same; # Unused variable...typo? } # All things were made by him; and without him # was not any thing made that was made. my %things = make_all($word);# pass 'word' as maker. # In him was life; $word .= 'life'; # 'In' him??? Maybe concatenate # and the life was the light of men. $things{men}{light}=$word; # Something funny here... # And the light shineth in darkness; $things{darkness}{shine} = $word; # presume 'The light' means $thing +s{men}{light} # Is 'shineth' an attribute? leave + for now. # and the darkness comprehended it not. die "unknown error" unless ok($all{darkness}); # leftover Debug code?? +? sub make_all { # will replace with Class::Factory... my $maker = shift(); return map {$_=> make_thing($_,$maker) } (qw(light darkness heaven earth seas stars sun men winged_fowl + creeping_things)); #etc. etc. - see Genesis for full list } sub make_thing { # formless thing - add attributes later my ($name,$maker) = @_; return { 'name'=>$name, # should bless instead? 'maker'=>$maker # why? Copyright reasons?? }; }

My initial thoughts were that it looks like something more generic that has been cut down. That 'BEGIN' block looks a little suspicious - there's that unused variable...maybe this was initally part of a Create($maker) (where $maker could be "The Force" or "Jehovah" or "Allah" or whatever) routine that's been hacked about.

Also, there's something funny with that "{men}{light} = 'life'" thing. I reckon there might have been a bit of a boo-boo, and he ends up assigning "Godlife" to "light" rather than the other way round. As this then gets passed to "darkness", no wonder he was getting errors in his test suite.

So... refactoring and removing the "I made this, honest!" copyright stuff gives us something like this...

#!/usr/bin/perl use strict; use warnings; use Earth::Things; my %things = map {$_=> {'name'=>$_[0]} } (Earth::Things::list_all()); $things{men}{life}=$things{darkness}{shine} = "light";
...which I'm sure you'll agree is a lot neater, and a better base for expansion. Any volunteers for a sourceforge project?

Ben.

Comment on Rewriting creation (with strict and warnings)
Select or Download Code
Re: Rewriting creation (with strict and warnings)
by TomDLux (Vicar) on Aug 30, 2003 at 20:40 UTC

    Once you get The Constructor right, everything else falls into place.

    --
    TTTATCGGTCGTTATATAGATGTTTGCA

Re: Rewriting creation (with strict and warnings)
by Drgan (Beadle) on Sep 01, 2003 at 16:20 UTC
    I don't know man. God may have errors but I think he was wanted it that way. Otherwise he would have hired a bunch of OpenSource people to write his programs, not Microsoft. Wait, I would rather like to think he wrote it Perl and just forgot to fix the bugs. . . Scratch the Microsoft bit. . .
    "I have said, Ye [are] gods; and all of you [are] children of the most High." - Psalms 82:6
Re: Rewriting creation (with strict and warnings)
by PhilHibbs (Hermit) on Sep 02, 2003 at 18:17 UTC
      I think part of the problem may have been that it'd *already* been through Lingua::Aramaic, Lingua::Greek, Lingua::YeOldeEnglishe etc. before it reached me. I haven't even *looked* at all the Armageddon stuff near the bottom - letting it anywhere near TheDamian might spell disaster for us all...

      :) Ben.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: poem [id://287907]
Approved by bart
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2014-12-22 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls