P is for Practical | |
PerlMonks |
Re^2: My problems to understand the Perl documentationby LanX (Saint) |
on Aug 23, 2020 at 00:34 UTC ( [id://11121002]=note: print w/replies, xml ) | Need Help?? |
> (Note that in Wikipedia, the CS definitions of "subroutine" and "function" are synonymous.) Linking to the same page doesn't mean they are "synonymous". WP entries on programming are written by programmers. If their main language is redefining a concept they'll take it as normative. Compare the notion of "closure" in PHP for "anonymous subroutine" which is ... "unfortunate". In Python are anonymous subroutines aka "lambdas" restricted to one expression only which is ... "even more unfortunate". IOW various WP authors will introduce their own truth. Anyway this WP goes into some details to explain why the concept vary between different languages.
In strictly functional programming languages such as Haskell, subprograms can have no side effects, which means that various internal states of the program will not change. Functions will always return the same result if repeatedly called with the same arguments. Such languages typically only support functions, since subroutines that do not return a value have no use unless they can cause a side effect.
In programming languages such as C, C++, and C#, subroutines may also simply be called functions, not to be confused with mathematical functions or functional programming, which are different concepts.
So subroutines and functions are synonymous in Perl, but not in general. To be more precise Perl's sub is a meta construct implementing all features from procedures and functions like known in older languages, from this perspective the names are linguistically just "pars pro toto" in Perl. In Perl you can use a sub like °
so the wordings become sometimes fuzzy.
Cheers Rolf °) the listed items are not exclusive, there are overlaps.
In Section
Meditations
|
|