Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: How do I go from procedural to object oriented programming?

by salva (Canon)
on Apr 21, 2015 at 07:49 UTC ( [id://1124111]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How do I go from procedural to object oriented programming?
in thread How do I go from procedural to object oriented programming?

You can keep calling your subroutines functions even if they are procedures. Everybody calls them functions inside the context of imperative programming.

Functional programming was a obscure thing until a few* years ago. If I recall correctly, the popular meaning for functional programming back them was "programming using functions as first class objects". For instance, Lisp was considered a functional programming language because it was able to build, pass and call functions and closures at runtime, in opposition to other lower level languages as C which didn't support closures and couldn't build functions dynamically.

Then, the *real* functional programming wave toke over, there was an explosion of new functional languages and functional programming became synonymous to using functions without side effects as in the mathematical sense.

Nowadays, the name "function" is still used to designate procedures. Any programmer using an imperative language as C/C++, Python, Perl or even old-school functional languages as Lisp will use the term "function" to designate both functions and procedures. Very few would take the time to consider the difference and state it explicitly. AFAIK, the only imperative language making a difference between functions and procedures is Eiffel and then it uses a completely different nomenclature.

In summary, you can call your subs functions even if you don't do functional programming. And say that you do procedural programming, or more commonly, imperative programming (that subsumes both the procedural and object oriented paradigms).

*) I would say until around the turn of the millennium... but it is quite subjective.

  • Comment on Re^3: How do I go from procedural to object oriented programming?

Replies are listed 'Best First'.
Re^4: How do I go from procedural to object oriented programming?
by Jenda (Abbot) on Apr 21, 2015 at 08:39 UTC

    There are other languages that distinguish between functions and procedures with function meaning "a subroutine that does return a value" and procedure meaning "a subroutine that doesn't return anything". For example Pascal or any procedural extension to SQL I've ever seen. (Microsoft's TSQL, Oracles PL/SQL, ...)

    I think it's actually a little unlucky that C books speak about "void functions" rather than "procedures".

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

      Ah, Pascal differentiates between procedures and functions, but not in the procedural vs functional way. Pascal functions may have side effects, there is nothing in the language forbidding that.

      Regarding the SQL extensions, well, the distinction between functions and procedures is not so clear. The main difference seems to be as in the Pascal case: if there is a return value or not. But then, function calls are allowed embedded inside SQL statements and that opens the door to lots of other considerations, more related to database implementation and internal matters than to anything else.

      I think it's actually a little unlucky that C books speak about "void functions" rather than "procedures".

      Just returning a value doesn't make a function a function in the functional programming sense (deterministic, no side effects). In C (at least) that is exacerbated by the fact that return values are commonly used to report errors.

      So, it's true that C functions returning void are procedures, but then, most C functions returning values are also procedures. The distinction doesn't lie there.

        Don't confuse "any function" with "referentially transparent function". A function in the mathematical sense is something a little different than a function in the programming sense.

        Jenda
        Enoch was right!
        Enjoy the last years of Rome.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1124111]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-19 06:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found