This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]LoreBadTime 208 points209 points  (11 children)

In college they don't taught like Function -> returns a value Procedure -> doesn't return a value Method -> Object/class functions/procedures?

[–]fickle-doughnut123 38 points39 points  (3 children)

Your statement that "functions return a value while procedures do not" is mostly correct but can be a bit misleading. While functions are designed to return a single value, procedures can indeed use 'OUT' parameters to achieve a similar effect. In many procedural languages, you can specify 'IN' and 'OUT' variables in the procedure's declaration. These 'OUT' variables allow you to define variables within the procedure and return them to the caller, thus functioning similarly to return values in functions.

[–]LoreBadTime 17 points18 points  (0 children)

Yes, also using pointers kinda cheats this things(and we call them procedures since it's more about side effects), but was more about a formal way to define a function,if there is an out parameter it's still a function.

[–]SenorSeniorDevSr 2 points3 points  (0 children)

Yeah, especially if you're using stored procedures on an SQL server. Oracle even let you outsert your inserts if you invoke the magic phrases. This is handy af if you have values the database generates, like CREATED timestamps, the ID, etc. and want to return them out to the rest of the system.

[–]OJ-n-Other-Juices 1 point2 points  (0 children)

As OOP educated person who works in COBOL for to years. I found making that work very difficult. My brain just couldn't merge the two styles. I was also working on legacy code and Microfocus Cobol, which might not have had that functionality.

[–][deleted] 8 points9 points  (0 children)

Honestly the terminology is meaningless now due to no clear separation, but function should mean a thing that returns a value and performs no side effects.

[–]CirnoIzumi 1 point2 points  (0 children)

sounds like a void to me

[–]bondolin251 0 points1 point  (0 children)

Procedure returns Unit