Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Re: Re: Problem with tie *STDIN, 'IO::Scalar', \$text;

by LunaticLeo (Scribe)
on Apr 30, 2001 at 20:36 UTC ( #76642=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Problem with tie *STDIN, 'IO::Scalar', \$text;
in thread Problem with tie *STDIN, 'IO::Scalar', \$text;

I think you have overlooked some major diabolical evil :).

Named blocks, as opposed to functions, HIDE the external effects of the block from the reader. Using the name of the block as some kind of documentation feature is a poor choice.

Even if you want your subroutine to affect globals, you can pass globals in and return new values for globals. This "documents" your named block even better; explicitly telling the reader what this chunk of code depends on and what it changes.

$GLOBAL1 = do_stuff($GLOBAL0, $GLOBAL1);

is MUCH better than:

... set globals ... ... do_stuff; ... ... use modified globals

I have had to read code like this (and it is very hard):

&read_input; &calculate_this; &calculate_that; &write_output; # some to files others to databases # all in one function. sub calculate_this { ... } sub read_input { ... } sub write_output { ... } sub calculate_that { ... }

This was horrible. I was tempted to just remove the "sub" lines, but then I noticed the subs were not declared in the order they were used. As I paid more attention, some variables inside the subs were my()'ed but had the same name as globals.

We had to audit this code to make sure it was calculating money dispusements correctly. How can you audit this code?

It was painfull to read, impossible to audit, and such a rats nest it was difficult to modify. I lay most of the blame at the fact that it was using globals, locals, and named blocks. Writing functions force a certain amount of structure. Even if the structure is lame it is emminently more readable and auditable.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2020-10-01 02:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (172 votes). Check out past polls.

    Notices?