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

Re^2: Aren't there code refs as well as function refs?

by dd-b (Monk)
on Mar 04, 2023 at 03:53 UTC ( [id://11150732] : note . print w/replies, xml ) Need Help??


in reply to Re: Aren't there code refs as well as function refs?
in thread Aren't there code refs as well as function refs?

Prototypes kept going! I kind of went off them a long time ago, they seemed to not be where things were going. Also--I notice they don't affect indirect and other common kinds of calls; this would look hugely likely to cause immense confusion!

I can of course dig into the places where I wonder what's going on. That code tends to be over my head, though, so it's a deep dive.

Perl is always an adventure!

  • Comment on Re^2: Aren't there code refs as well as function refs?

Replies are listed 'Best First'.
Re^3: Aren't there code refs as well as function refs?
by kcott (Archbishop) on Mar 04, 2023 at 07:26 UTC

    I avoid prototypes in my code, except for the empty prototype '()' to create "Constant Functions".

    In v5.36.0, the experimental status of subroutine Signatures was removed. You may find this to be a better method to declare parameters. Do note that prototypes and signatures are not different syntaxes for the same thing: follow the link for details. This is something I do like and have been using in all of my personal code since Perl v5.36.0 was released.

    Not that I'm recommending it but, just so you know, you can use both a prototype and a signature with the same subroutine. If you do this, use of the :prototype() attribute is advised to avoid ambiguity.

    — Ken

      I avoid prototypes in my code, except for the empty

      Likewise...

      When I first came across prototypes in Perl they sounded extremely useful. However, I have come to realise that they are never really necessary at all - or if they are, I have not come across the use case. The complications they add to understanding and maintaining the code is not worth the tradeoff.