0
Deference between procedure and function?
8 odpowiedzi
+ 6
Self-contained blocks of your program, that usually have a name and can be invoked at will, are also called subroutines.
A procedure is typically a block of instructions that just does things in sequence, but there is no result to return to the caller.
A function does some calculations based on its parameters, and returns the result to the caller (where it might be assigned to a variable or printed).
A method is a function declared inside a class in object oriented programming.
+ 6
Lol Jan Markus
It is correct to say that each programming language uses a bit different terminology... According to the "Zeitgeist", the ideas that were fashionable at the time of language design. So this can be confusing for learners. Even I got confused today, by the fact that Ruby functions are described as "method" throughout the course, although there are no objects involved, they are really just standalone functions.
Python functions, even if we don't write a return statement, implicitly return None. So it is still correct to call them functions.
+ 4
iirc, in PL/SQL, a function *must* return value. a procedure also *can* return value, but it's NOT compulsory to return it.
+ 4
Tibor Santa Regarding Ruby / Python - methods vs functions... it does appear that Ruby methods should be functions.
But, in reality, what may appear to be global functions are in fact methods bound to the root Object instance.
So, in Ruby, these are actually methods.
https://stackoverflow.com/a/8393639/5087494
As far as Python returning None... that's actually an easier pill for me to swallow considering so many other language oddities I can't seem to get past my uvula due to an involuntary gag reflex. 🤣😂
+ 3
FWIW... this thread on StackExchange covers the scenarios quite well in grasping the differences between procedures and functions across a variety of perspectives, vernaculars, and backgrounds.
https://softwareengineering.stackexchange.com/questions/20909/method-vs-function-vs-procedure/20948#20948
I might add that in VB.NET and classic VB, the Sub and Function keywords are used to defined callable routines such that Sub (routines / procedures) do not return a value, while Functions do.
+ 3
MZ Ahmadzai 🇦🇫 if you are specifically interested in PL/SQL then I recommend to read this, Oracle started republishing their introductory PL/SQL tutorial and it does mention also this topic:
https://www.oracle.com/news/connect/plsql-101-part-1.html
Quoted from the article: "PL/SQL supports the definition of named blocks of code, also known as subprograms. Subprograms can be procedures or functions. Generally, a procedure is used to perform an action and a function is used to calculate and return a value."
+ 2
In C, a procedure can be 'modeled' by a function that returns void.
+ 1
Tibor Santa , ok thanks , definitely I'll check for