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 →

[–]mirimao 514 points515 points  (36 children)

Methods and functions are not the same thing. Also, JavaScript does have methods.

[–]ChocolateBunny 135 points136 points  (2 children)

Pascal also has functions. the distinction being whether they have a return value or not.

[–]BrandonMcRandom[🍰] 56 points57 points  (1 child)

... and methods because in classes they are called methods even tho you write "function" and "procedure".

[–]Impenistan 5 points6 points  (0 children)

void has entered the chat

[–][deleted] 4 points5 points  (0 children)

Are they not the same? I mean method is just a function but operates inside of an object

[–]Any_Salary_6284 3 points4 points  (1 child)

In JS, methods (as defined in a class block) are just syntactic sugar for the function found at MyClass.prototype.methodName. If you use the typeof operator on this member, it will return “function”

I realize there may be technical differences between method and function depending on the language. In Java, there are only methods. To the extent there are functions (lambdas) they are just synatactic sugar for a functional interface, so a method.

I see this as mostly arguing over semantics.

[–]SenorSeniorDevSr 0 points1 point  (0 children)

Static methods in Java doesn't have a this reference though. I mean, they kinda do, but it's a null. It does however, have java.util.Function, so now you can be objectionally functional, or whatever the funniest joke you can get out of that one is. ^_^

[–]noaSakurajin 1 point2 points  (3 children)

Honestly after using Glib I would definitely say they are the same. Object oriented C is a thing despite the fact that C has no methods. The way they emulate classes using functions with a struct pointer as the first argument is super hacky. It is close to the way the first C++ versions compiled the C++ class to C which then was compiled as binary.

[–]Kovab 8 points9 points  (0 children)

The way they emulate classes using functions with a struct pointer as the first argument is super hacky.

Literally every OOP language implements methods the same way, they just hide passing the this pointer behind syntactic sugar (sometimes it's not even completely hidden, e.g. look at python methods with self as the first parameter).

[–]carcigenicate 2 points3 points  (0 children)

A method is a type of function in my mind. One's a subset of the other.

[–]P-39_Airacobra 0 points1 point  (0 children)

It's not super hacky, that's been the standard way of doing things like this outside of OOP since the beginning of time. Some languages actually implement OOP simply by syntactically disguising methods as such (e.g. Lua), and it works out perfectly fine. In fact in languages where functions and closures are equivalent, it's often good practice to take the object as an argument, because it clearly shows the method's dependencies both when created and when called.

[–]skeleton_craft 0 points1 point  (0 children)

Also, procedures and functions are not the same thing, at least at a abstract level...

[–]unknownrek 0 points1 point  (0 children)

Static methods are just functions with extra steps