Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Maintainable Code?

by sporte01 (Acolyte)
on Nov 11, 2002 at 20:17 UTC ( [id://212070]=note: print w/replies, xml ) Need Help??


in reply to Maintainable Code?

Perfect time to get on the high horse. I have two points of view, but I'll state this much. When writing perl, stick to objects, simple hashes and simple arrays along with references. It prevents you from writing hashes of hashes, which is error-prone. What if you misspell a key? More reason to hate hashes for non-internal reasons (in method/code block) only. I remember once i returned a hash, tried to use one of the keys, it was mispelled, had a false sense of how the code worked, thus creating harder to maintain code as well as buggy. ... but we all have our preferences.

But anyway, lemme jump to the other horse. It sounds like you guys need a small committee, 2 or 3, to write a coding standards doc. Level the playing field so that everyone knows how to pass data around, how to name functions, etc etc... That's ALL that is needed. So if someone uses a hash of hashes, and it says it is or isn't in the coding doc, you can point it out, and help that person learn that it's ok to use.

Replies are listed 'Best First'.
Re: Re: Maintainable Code?
by chromatic (Archbishop) on Nov 11, 2002 at 23:17 UTC
    What if you misspell a key?

    My test cases catch it, just as they do if I mistype an array index. :)

      Whilst I completely disagree that the ability to silently typo would ever stop me from using the enormous utility of hashes, there are times when it would be very useful to be able to turn off the autovivification of elements.

      Perhaps this could be added as an attribute in Perl 6 so that it could be controlled on a hash by hash basis? I settle for another strict option so that it could be controlled on a lexical basis.

      Ideally, I think that it would be great to be able to do this lexically on a hash by hash basis. That way you could indicate some parts of your code that you want to autovivify keys of this hash within this scope, where you know you are going to be creating them, but turn it off in other places where you simply want to access the value of existing keys.

      I appreciate that you can use exists to implement this, but its one of those housekeeping chores that I'd really like to be able to have the compiler/interpreter take care of for me. Its less likely to forget than I am:^)


      Nah! You're thinking of Simon Templar, originally played (on UKTV) by Roger Moore and later by Ian Ogilvy
Re: Maintainable Code?
by Abigail-II (Bishop) on Nov 12, 2002 at 16:42 UTC
    Mistyping hash keys is something that happens when you use hashes. It's not something that only happens when you use hashes of hashes, nor do hashes of hashes make it worse.

    And you can prevent this from happening by making all your keys constants, and prepending a + in front of each key that otherwise might be autoquoted.

    Disallowing hashes of hashes sounds as useful to me as disallowing arithmetic which involves divisions, as some people don't master division.

    Abigail

Re: Re: Maintainable Code?
by Anonymous Monk on Nov 11, 2002 at 22:57 UTC
    If you accept simple hashes and references, then you have accepted hashes of hashes already.

    As for misspelling problems with hashes, if you use Perl 5.8 then you can lock down hashes without a huge performance penalty, making typos easier to catch.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://212070]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-23 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found