3 ms·
> Method-syntax is more than syntactic sugar. No, method syntax is just syntax. In some languages methods are more than just syntax sugar, but there's nothing
by wtetzner 3y ago
> Method-syntax is more than syntactic sugar.
No, method syntax is just syntax. In some languages methods are more than just syntax sugar, but there's nothing special about the syntax itself.
- galaxyLogic 3y agoSyntax has no meaning unless it is associated with some semantics, like it is in all programming languages.
- wtetzner 3y agoThe point is that the semantics could very well be just an alternative form of function calls.
- galaxyLogic 3y agoIt could be, but it is not. In JavaScript you can say: let v = myOb.myFunk(); or you can say: let v2 = myFunk.call (myOb); Those the two different syntaxes you can use to make a method-call. They have the same result for all arguments. So you can say one is syntactic sugar over the other. Their semantics are the same. In other words they have the exactly same meaning. BUT if you write: let v3 = myFunk(); the result is different. And you get an error if your source-code assumes that 'this' is not undefined. That shows that the semantics of the 3rd example above is different from the semantics of the first two. In other words the semantics of a function-call and of a method-call are different. Therefore, we can say that method-call is not syntactic sugar for doing the same thing as a plain function-call.
- wtetzner 3y agoExcept we were never talking about JavaScript. I thought the OP made it pretty clear that they only cared about the syntax of method calls because they flow nicely and more easily support auto-complete in editors. Simple syntax sugar that translates `foo.bar(x, y)` into `bar(foo, x, y)` would suffice for both.
- galaxyLogic 3y ago> Syntax sugar that translates `foo.bar(x, y)` into `bar(foo, x, y)` For that to be syntactic sugar it would have to be the case that foo.bar(x, y) and bar(foo, x, y) always produce the same result for any given values of 'foo', 'x' and 'y'. Is there a language where that is the case?
- wtetzner 3y agoThere doesn't need to be a language where that's the case for it to be desirable in Odin. However, yes, there are languages where that's the case: https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax I would also argue that extension methods in languages like C# and Kotlin are just sugar.