4 ms·
What do you mean by "class methods automatically referring to "y" as the instance variable "y". I realize c# and Java? do it". Neither C# nor Java even use the
by pvg 10y ago
What do you mean by "class methods automatically referring to "y" as the instance variable "y". I realize c# and Java? do it". Neither C# nor Java even use the terminology 'class method'.
- bpicolo 10y agoSure they do? https://msdn.microsoft.com/en-us/library/ms173114.aspx https://msdn.microsoft.com/en-us/library/ms173114.aspx https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html https://docs.oracle.com/javase/tutorial/java/javaOO/methods.... Unless the goal is to be overly pedantic and claim "method" is the term vs "class method". Take a look at the Vector example. "y" in the constructor and other methods refers to instance variable y on the Vector class instance.
- pvg 10y agobe overly pedantic and claim "method" is the term vs "class method". That's not me being overly pedantic, that's you misusing standard terminology. The term "class method" has a specific meaning that's quite distinct from "instance method" - the thing you're actually talking about. In fact, if you go to the docs of the very language this post is about: https://marcobambini.github.io/gravity/classes.html https://marcobambini.github.io/gravity/classes.html You'll find verbiage about 'class methods', again, as distinct from 'methods'. I can't think of an OO language or context in which 'class method' to just mean 'instance method' would make any sense.
- bpicolo 10y agoSure. Does not seem that difficult to infer from context what I was referring to, but you're technically correct. The terms are not that far off from each other in either definition or literal wording.
- pvg 10y agoI honestly had no idea what you were talking about. The terms are near-opposite in meaning and usage.
- cstrahan 10y agoI think pvg's point is that "class method" is often used interchangeably with "static function" -- that is, functions that are not called on instances (e.g. SomeClass.foo() vs (new SomeClass()).foo()). It would seem that you were talking about what most people would call instance methods, or commonly just "methods" (unless you're in a language like Ruby, where you don't have functions as a first class entity -- if you want "class methods" as they are called, you define a method on the target class object's meta-class.)
- lilactown 10y agoHe means how in Java you can do something like this: class Foo { private Integer bar = 0; public Integer baz() { Integer inc = 2; bar += inc; return bar; } } Where `bar` is referred to in the same way a local variable is, even though it's actually a property of the class the method is defined on. It's equivalent to using `this.bar` but the compiler accepts it anyway.
- pvg 10y agoRight, the confusing thing was talking about 'class methods'.
- hnbroseph 10y agothe confusing thing was pointlessly wasting time on things that weren't confusing.
- xxs 10y agoplease don't use java.lang.Integer unless you really have to. I know it's just an example but it gives the wrong ideas of what good code is. Each operation in baz() consists of Integer.intValue() and Integer.valueOf(int), like Integer inc = Integer.valueOf(2); bar = Integer.valueOf(bar.intValue() + inc.intValue()) ... besides dealing with unneeded indirection values outside [-128 : 127] actually create an object that has to be allocated+GC'd each assignment. Such nuances give Java the bad rap. 'int' maps straight to the hardware, java.lang.Integer - not so much.