Perl symantics

Discussion in 'Perl Misc' started by sln@netherlands.com, Apr 3, 2009.

  1. Guest

    There's been written guidelines naming 'C/C++' style
    variables based on type.

    Perl seems to be all caps, first letter caps, no caps.
    And that is it.

    What's that all about?

    -sln
     
    , Apr 3, 2009
    #1
    1. Advertising

  2. wrote:
    > There's been written guidelines naming 'C/C++' style
    > variables based on type.
    >
    > Perl seems to be all caps, first letter caps, no caps.
    > And that is it.
    >
    > What's that all about?


    It's about having a name contain information about the variable:

    - constant vs. variable (most people use ALLCAPS to name a constant)
    - global vs. local vs. object attribute (some people use a leading
    Uppercase to name a global variable, alllowercase for local variables
    and a leading "m_" to name an object m_ember)
    - variable type (integer, char, ...) (some people use a leading "c_" to
    name a c_haracter variable, a leading "i_" to name an i_nteger variable
    etc).
    Occasionally, it comes in handy: how often have you wondered what type a
    variable is, whether it is a global or a local variable etc.

    's that what you mean?

    Groetjes,

    Josef
    --
    These are my personal views and not those of Fujitsu Technology Solutions!
    Josef Möllers (Pinguinpfleger bei FTS)
    If failure had no penalty success would not be a prize (T. Pratchett)
    Company Details: http://de.ts.fujitsu.com/imprint.html
     
    Josef Moellers, Apr 3, 2009
    #2
    1. Advertising

  3. >>>>> "sln" == sln <> writes:

    sln> There's been written guidelines naming 'C/C++' style
    sln> variables based on type.

    sln> Perl seems to be all caps, first letter caps, no caps.
    sln> And that is it.

    sln> What's that all about?

    In C/C++, the *variables* are typed, and as the programmer, you have to be
    aware of that almost constantly, or you can't even enter valid code. Hence,
    people come up with naming schemes for variables so they can do the work that
    should be done by automation. :)

    In Perl, the *values* are typed, and you're free to say what you mean, and the
    runtime system just *does the right thing*, and your productivity is
    dramatically increased.

    I still don't understand why people like typed variables. :(

    print "Just another Perl hacker,"; # and smalltalk, and lisp, and python ...

    --
    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
    <> <URL:http://www.stonehenge.com/merlyn/>
    Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
    See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
     
    Randal L. Schwartz, Apr 3, 2009
    #3
  4. Tim McDaniel Guest

    In article <>,
    Randal L. Schwartz <> wrote:
    >I still don't understand why people like typed variables.


    For me, I like the sanity checking that can happen with strong typing.
    If I know that variable "count" is used for the count of the number of
    items that it's supposed to process, for examle, then I know it should
    contain only an integer and I'd really like to know if code tries to
    assign 'frog' to it, ideally at compile time.

    I'd like to try stronger enforced assertions, like "this must be an
    integer >= 0". I hope someone will reply with the five Perl CPAN
    modules that implement such notions.

    --
    Tim McDaniel,
     
    Tim McDaniel, Apr 3, 2009
    #4
  5. ccc31807 Guest

    On Apr 3, 10:55 am, (Randal L. Schwartz) wrote:
    > print "Just another Perl hacker,"; # and smalltalk, and lisp, and python ....


    Your opinion, please.

    I've made an effort to learn Lisp in the past year and am now writing
    some small scripts in Lisp. I've also played with Erlang and Clojure,
    and am inclined to give priority to Erlang because (1) it seems to do
    better with multi core processors, and (2) I have very little need for
    Java libraries that Clojure provides. Do you have an opinion as to the
    future of Lisp/Erlang/Clojure?

    In an interview recently, Tim Bray said that he had switched from Perl
    to Ruby. Do you have an opinion as to the future of Perl/Python/Ruby?
    I guess I'm a little curious as to Parrot, whether it will be able to
    compete with the JVM and the CLR.

    CC
     
    ccc31807, Apr 3, 2009
    #5
  6. On 2009-04-03 16:37, Tim McDaniel <> wrote:
    > In article <>,
    > Randal L. Schwartz <> wrote:
    >>I still don't understand why people like typed variables.

    >
    > For me, I like the sanity checking that can happen with strong typing.
    > If I know that variable "count" is used for the count of the number of
    > items that it's supposed to process, for examle, then I know it should
    > contain only an integer and I'd really like to know if code tries to
    > assign 'frog' to it, ideally at compile time.


    Yup, the ability to catch such errors at compile time is the big
    advantage of typed variables. While it is theoretically possible to
    catch many such errors by static analysis of the program code (and some
    newer dynamically typed languages do this) it is expensive and you don't
    want to do this every time a script is executed.

    > I'd like to try stronger enforced assertions, like "this must be an
    > integer >= 0". I hope someone will reply with the five Perl CPAN
    > modules that implement such notions.


    Smart::Comments comes to mind, although I haven't used it myself. I just
    sprinkle my scripts with lots of 'die "bla" unless $foo;' statements.

    hp
     
    Peter J. Holzer, Apr 3, 2009
    #6
  7. >>>>> "Tim" == Tim McDaniel <> writes:

    Tim> For me, I like the sanity checking that can happen with strong typing.
    Tim> If I know that variable "count" is used for the count of the number of
    Tim> items that it's supposed to process, for examle, then I know it should
    Tim> contain only an integer and I'd really like to know if code tries to
    Tim> assign 'frog' to it, ideally at compile time.

    You mean, you won't be writing unit tests for that, or relying on
    the + operator to properly blow up?

    Compile-time checking is insufficient to perform all tests, hence you will
    need to write tests. Since you're writing tests anyway, compile-time checking
    isn't necessary, since you're already checking for proper behavior.

    Hence, compile-time checking is irrelevant.

    --
    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
    <> <URL:http://www.stonehenge.com/merlyn/>
    Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
    See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
     
    Randal L. Schwartz, Apr 3, 2009
    #7
  8. Tim McDaniel Guest

    In article <>,
    Randal L. Schwartz <> wrote:
    >>>>>> "Tim" == Tim McDaniel <> writes:

    >
    >Tim> For me, I like the sanity checking that can happen with strong
    >Tim> typing. If I know that variable "count" is used for the count
    >Tim> of the number of items that it's supposed to process, for
    >Tim> examle, then I know it should contain only an integer and I'd
    >Tim> really like to know if code tries to assign 'frog' to it,
    >Tim> ideally at compile time.
    >
    >You mean, you won't be ... relying on the + operator to properly blow
    >up?


    At compile time? Only if it does flow analysis.

    >Compile-time checking is insufficient to perform all tests, hence you
    >will need to write tests. Since you're writing tests anyway,
    >compile-time checking isn't necessary, since you're already checking
    >for proper behavior.


    There's variable amounts of effort involved, though. See how many
    replies here say some version of "Add use warnings; use strict;".
    Sure, those checks are not sufficient to catch ALL problems, but that
    little effort gets a big payback. Similarly, "int" and such give
    similar large-grained control but can give large (if not complete)
    paybacks.

    Also, where it is possible make a declaration that sticks, that's an
    assertion provided in one place and used everywhere, instead of adding
    an assertion everywhere the value gets assigned to or used.


    I have a vague memory of Perl adding some sort of attributes facility
    for variables, but the same vague memory suggests that they were
    half-baked and have never been really supported or popular. Am I
    mistaken? If they are solid now, where can I read up on them?

    --
    Tim McDaniel,
     
    Tim McDaniel, Apr 4, 2009
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,817
  2. Russell Shaw

    Copy by value symantics

    Russell Shaw, Jun 6, 2005, in forum: C Programming
    Replies:
    10
    Views:
    552
    Malcolm
    Jun 8, 2005
  3. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Jan 23, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    309
    PerlFAQ Server
    Jan 23, 2011
  4. PerlFAQ Server
    Replies:
    0
    Views:
    697
    PerlFAQ Server
    Feb 3, 2011
  5. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Feb 27, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    302
    PerlFAQ Server
    Feb 27, 2011
Loading...

Share This Page