Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Nice writeup, and well put.

    Another point that I would have made is: often, novices structure code in weird ways, with procedures that aren’t very useful outside the context in which they were conceived because they are big and do too many things. They use variables that get recycled over too many intermediate calculations, or conversely fail to break calculations into intermediate steps saved in variables.

    Naming is a good detector for such problems. If you can’t think of a good precise name

    • When I name an array after the objects it contains, I don't know whether to use the plural, or the singular, ie whether to call it objects, or object.

      @persons means I start saying $persons[0], $persons[2]. @person reads nicer when referring to the elements, $person[1], $person[2].

      But the second might confuse a reader of the code?
      • No don't name it after the members. Name it after the collection. Thus, the array becomes @person. When read out loud, it becomes "the person array".

        This avoids ever having to ask the "is it singular, is it plural?" question. Name all your variables in the singular, even if, in some corner cases it comes out sounding a little weird.

        If everything is always singular, no exceptions, you never have to stop and pause to think about its name. This optimisation pays off big time in the long run.

        • My array and hash names are always singular, but not my scalars. When a scalar is intended to store an arrayref, I use the plural, and when it’s intended to store a hashref, its name ends in _for.

          I agree otherwise, though.