Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Re: Re: Re: Re: Using "my" suppresses "Name used only once" warning?

by bart (Canon)
on Feb 03, 2003 at 08:13 UTC ( [id://232166]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Re: Using "my" suppresses "Name used only once" warning?
in thread Using "my" suppresses "Name used only once" warning?

I guess I'm used to being able to tell whether a variable is a number or a string just from the prefix character (which is handy when reading unfamiliar or forgotten code).
/me gives Wysardry the odd look.

You mean the Hungarian notation? You can do that in Perl just as well. In fact, there's no requirement in those other languages that the type inferred from your conventional prefix actually agrees with the actual declared type. Nothing prevents you from declaring an integer strFoo or a string pointer iBar. Because it's only a convention.

If you really feel the need for this kind of "self-documentaion", go ahead. Nothing is stopping you.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Using "my" suppresses "Name used only once" warning?
by Wysardry (Pilgrim) on Feb 03, 2003 at 19:21 UTC

    Well, I'm not sure whether it's called Hungarian notation or not, but in BASIC for example, a string variable name is prefixed with a $ character, integers start with % and floating point numbers have no prefix.

    That way, you can have 3 different variables called $x, %x and x and know what type of value they can contain (even though "x" tells you little else).

    Trying to give a value in the wrong format, such as adding 0.5 to an integer, would cause a "type mismatch" error.

    Okay, so maybe that restriction does force you to do unecessary conversions at times, but those prefixes do make it easier to debug unfamiliar code.

    It also makes it more obvious what type of value a particular subroutine is expecting to have passed to it if you want to reuse it elsewhere.

    I'm sure I can find some way to make it clearer what type of value my variables are intended to be used with. I was just hoping there was some way to have that checked every once in a while during development.

    There have been plenty of good suggestions given to help anyway. :o)

      What dialect of basic was it? I've seen some that used the $, but I've never seen % being used in Basic.

      Jenda

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-03-28 22:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found