Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: On Foreach Loops and Maintainability

by ignatz (Vicar)
on Oct 11, 2002 at 17:40 UTC ( [id://204597]=note: print w/replies, xml ) Need Help??


in reply to On Foreach Loops and Maintainability

The whole premise seems ugly. arg1, arg2, arg3 bleach:-P

For me the most important thing is the process: Do arg1, then arg2, then arg3, etc. The code needs to clearly define what the process is:

@process = qw/ arg1 arg2 arg3 arg4 arg5 /; foreach ( @process ) { if ( $object->method( $_ ) ) { # ... do stuff } }
Even better:
foreach ( $object->getProcess() ) { if ( $object->method( $_ ) ) { # ... do stuff } }
so that the object controls what the process is and as the object changes so can the process. (ADDED: I could see distilling this down even more and in better ways.)

I'd bet that this is the slowest way to do things, but at least for me it seems the clearest. I don't know what posts you are refering to so I could be completely talking out of my butt.

()-()
 \"/
  `                                                     

Replies are listed 'Best First'.
Re:x2 On Foreach Loops and Maintainability
by grinder (Bishop) on Oct 11, 2002 at 21:45 UTC

    I too have a little problem with the names. Those ascending numbers lead me to conclude that the problem domain is being poorly mapped into Perl. merlyn says that you should capture regularities in code. Yes indeed, but that still doesn't validate this map { "arg$_" } approach as being a good one. A completely different approach is required. Which is why I like ignatz's idea.

    Can someone post references to the thread(s) that rob_au is talking about? I seem to have missed them, and I'm not sure if I'm taking the example too literally.

    One thing that I can see in favour of rob_au's initial approach is that it allows you grep the source code to find out where arg4 is used. Never underestimate the power of static analysis. If you're creating those names on the fly then you don't have that luxury.

    If the project is big enough, then it may even be worth going as far as pulling those names out of the source code and storing them in a data file. That gives you a different degree of flexibility and control. You can write a Makefile to ensure that you can run a program against the data file to make sure it is stays coherent.


    print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2024-03-28 09:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found