Subroutine Calling Conventions

Hello everyone.

In trying to find places that I might be able to exchange links to get traffic to my tutorial site, I found an article about how one should determine if a tutorial is good. One of the things that they mention is that a tutorial that teaches

&subname()

as a valid subroutine calling convention is out of date. It continues to explain that this does do something, but not what people think it does.

As a matter of fact, I just finished writing a major tutorial on subroutines myself last night. I have looked at numerous resources, all of which say

&subname;
(I know that's slightly different, but similar enough to cause alarm) and
subname ()

are both acceptable. I looked again today, and found the same information. So could someone please clear this up...what (if any) difference is there between these two conventions, and am I making some major mistake if I write tutorials with the ampersand method?

3 Comments

Hi Chris

Firstly congratulations for even asking for feedback. That's vastly better than just publishing.

I suspect you'll get a range of responses, so I won't say too much about the content of any tutorials. I'd rather concentrate of more general matters.

Your tute's URL should have appreared above.

I have the 3rd edition of Programming Perl, and on p 218 the differences (in sub calling conventions) are spelled out, so check that source as being definitive.

I used to have on-line tutorials, but they because obsolete so I deleted them all.

Joel's link (which you gave) does give a very good set of guidelines in a relatively short document.

Also, I would recommend not writing tutorials before you really comfortable answering such questions yourself.

For instance, you didn't say you'd written some demos trying to ascertain what the different calling conventions did. That may not have revealed the subtle use of @_ in calling &NAME, but at least it would indicate an investigative attitude, which is good for us readers to know :-). You could have published that code and gotten feedback on fixing it, and offered the corrected versions as a stand-alone demo warning new users of the complications.

Cheers
Ron

Hi Chris! My comment was going to be far too long and so it became a post of its own: https://blogs.perl.org/users/joel_berger/2013/12/the-perils-of-and-prototypes-too.html

Cheers

Leave a comment

About Chris K

user-pic I'm a student teaching himself Perl and want to learn more.