Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re (tilly) 2: Frivolous function names

by tilly (Archbishop)
on Dec 06, 2001 at 18:35 UTC ( #129917=note: print w/replies, xml ) Need Help??

in reply to Re: Frivolous function names
in thread Frivolous function names

Ironic. While offering me advice on how to avoid having any ambiguous names, you have hit on a horribly ambiguous name that I would never leave in code.

One of the most common programming errors - and a hard one to see - is to reverse the meaning of a flag. For that reason I consider any flag horribly misnamed unless the name is a yes/no question which its value is an answer to. For instance your flag might be appropriately named $will_create. Do that and you will stop making that particular mistake again.

Replies are listed 'Best First'.
Re: Re (tilly) 2: Frivolous function names
by demerphq (Chancellor) on Dec 06, 2001 at 18:51 UTC
    I admit I didnt take a lot of time to write my code snippet as my point was to avoid naming problems and use a flag. The choice of name for the flag variable would be the authors call. Although on second thought I wouldnt use $will_create but probably $create_on_demand

    Anyway, point well taken though, in future Ill put more thought into variable names in my snippets...


    On second thought there is a point here actually. You were talking about externally available names, whereas $flag while poorly named is internal and thus less of an issue. This isnt to say that $flag was a good name, it is not. But there is more room for error in internal use code than external use code, especially if said variables/code are properly scoped. </bad_excuse>

    Yves / DeMerphq
    This space for rent.

      I call that a really bad excuse.

      Flipping flags in internal code is an incredibly easy and common error to make. There are some estimates suggesting that it is actually more common than off-by-one errors - but not as often caught because it is much harder to see the error. (According to legend I heard the very first Fortran compiler made this error - the flag determining whether to compile carefully or not was reversed. No idea whether that is true.)

      As far as I am concerned the entire question of whether summon/get is OK is much less important than getting flags reversed. As matters stand, I don't think people would accidentally call summon, and most of the time get is right. But flipping flags is a basic error that you will make again and again...

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2019-10-17 11:16 GMT
Find Nodes?
    Voting Booth?