« first day (1943 days earlier)      last day (3050 days later) » 

2:05 PM
May I submit that this edit is important because it clarifies that the asker does not merely mean "class methods", but rather any method in a class: programmers.stackexchange.com/review/suggested-edits/127486
 
Happy Coffee Day
 
@AaronHall I had no idea "class method" meant anything other than "a method a class has", is google correct in telling me that it actually means "static method"?
 
no, I would distinguish between a static method and a class method
 
@AaronHall What's the distinction?
a class method is a member function, no?
 
My reference point is Python
 
2:08 PM
well now I'm hopelessly confused
I declare this terminology stupid
 
A static method does not know its class
A class method does
 
@gnat very cool; this lends a lot of credence to the idea of SO limiting sending them here. I do recall when SO burned down their close queue, I still wouldn't call this conclusive - the debugging questions seems to have spiked more in the last 2-3 months from my perspective but perhaps I'm just not looking close enough. Still seems likely you're right based on that and a lack of evidence supporting any other theory
 
A method (or message) in object-oriented programming (OOP) is a procedure associated with an object class. An object is made up of behavior and data. Data is represented as properties of the object and behavior as methods. Methods are also the interface an object presents to the outside world. For example a window object would have methods such as open and close. One of the most important capabilities that a method provides is method overriding. The same name (e.g., area) can be used for multiple different kinds of classes. This allows the sending objects to invoke behaviors and to delegate the...
TIL
 
An instance method knows its instance (and thus its class)
 
@AaronHall wait what
 
2:09 PM
@AaronHall ...what does that even mean?
 
@LightnessRacesinOrbit were you unfamiliar with the term?
 
@JimmyHoffa The onebox broke the link - it's actually to a subcategory
 
the only interpretation I can come up with is "a class method doesn't use this" which would make it synonymous with instance method
 
Regardless, I think what we're discovering here is that we'd better avoid the term "method" entirely for being hopelessly ambiguous. That's what we do in C++. Member function, static member function. End of!
 
@LightnessRacesinOrbit oh yeah; "class method" and "instance method" are two distinctions I learned a couple years ago too after a big "the hell you talking about?"
 
2:11 PM
a method that has no idea what class it's a method of...is not even a method anymore, or at most it's a method of some utility class associated with another class
I guess
 
different language cultures use different terms for the same things
 
My favorite useful static method in Python is the str.maketrans method in Python 3.
 
@AaronHall if it helps, I did check the question for language tags before rejecting, and I've never heard any of this terminology in the context of Javascript so it seemed safe to assume it wasn't some weird C# thing
 
@Ixrec this stuff all depends on your perspective.. the actual mechanics at play are something I suspect everyone here is familiar with. Just the approach to explaining it is tinged by your language culture. For example, nobody anywhere in .NET would ever use the term "class method" because it makes no feckin sense at all and sounds stupid, but it's a totally standard term in I think ruby? and others
 
JavaScript doesn't have classes anyway so wtf
 
2:13 PM
what question?
 
@JimmyHoffa I'm still waiting for a coherent definition of what the term means in any context, lol
 
>>> 'abracadabra'.translate(str.maketrans('abc', 'bca'))
'bcrbabdbcrb'
 
@LightnessRacesinOrbit large portion of folk are still convinced it's an "OO" language and because of their misguided sense of both that and what "OO" is they presume JS both has classes and just calls them something else
 
@JimmyHoffa Yes I think we can agree those people are wrong
 
also because JS itself is confused about it
 
2:14 PM
@Ixrec in some languages they call static methods "class" methods because it's not associated with an instance, and non-static methods are "instance" methods
 
You can kind of fake classes in JS by abusing its prototype-based OO
@JimmyHoffa that's terribad
 
str.maketrans creates a dictionary. It has no reason to know it's attached to the str object.
 
@LightnessRacesinOrbit I completely agree, but it's seen as the height of recognition and comprehension of "OO" among some languages; if a Rubyist asked you about those terms and you looked confused it would be the same as if you asked someone the difference between static and non-static methods and they looked confused: You'd think them an incompetent
different language cultures, different terms, same concepts
 
before Python 3, you had to import it from the string module
 
@AaronHall so is Python also use the "class" vs "instance" method terminology?
 
2:16 PM
So it's a static method
 
@JimmyHoffa that was my first guess, then Aaron said that was wrong and gave me an alternative I couldn't parse, which is why I'm confused
 
Here's my favorite example of a class method:
 
@Ixrec well, perhaps I have it wrong too... I don't know, it is a genuinely terrible term
 
>>> dict.fromkeys('abc')
{'a': None, 'c': None, 'b': None}
it knows its class, it has no instance, it's creating a new instance.
 
@AaronHall if I knew Python I might understand what makes that a class method..
I mean, that doesn't even look like a method definition to me
 
2:17 PM
what's this "knows its class" concept?
 
dict.fromkeys is a class method
 
what Lightness said, that's the part I'm waiting for
 
dict.fromkeys is a function of the class that is creating it
 
2:19 PM
@Ixrec in normal languages static methods "know" their class insofar as they have access to private static information
 
can you show me an example of a method that doesn't "know its class"
 
@LightnessRacesinOrbit Python is procedural - it can have free functions
 
@JimmyHoffa ... which aren't methods then ...
 
>>> from collections import OrderedDict
>>> OrderedDict.fromkeys('abc')
OrderedDict([('a', None), ('b', None), ('c', None)])
 
@AaronHall what is "it"? the way you wrote that sentence, "it" would have to be the fromkeys function, which makes no sense
 
2:20 PM
are we using "method" to mean "any function" now?
 
perhaps that's why they have this terribad terminology - languages with free functions have community's that tried to parse 3 different types of functions
@LightnessRacesinOrbit in Python maybe? I don't bloody know..
 
@AaronHall o.O
what's dict in your previous example
 
@AaronHall show a method definition that "knows it's class" perhaps maybe it will become clearer what you mean then?
 
8 mins ago, by Aaron Hall
>>> 'abracadabra'.translate(str.maketrans('abc', 'bca'))
'bcrbabdbcrb'
 
@JimmyHoffa why does the existence of "free functions" make it hard to say "free functions", "static methods" and "instance methods"?
 
2:21 PM
I see it but it still doesn't explain anything to me
 
str.maketrans is a static method
 
ok
what's OrderedDict.fromkeys if not a [free] function or a static method?
 
It's attached to the object for convenience
 
@Ixrec don't ask me! I'm just theorizing here why they have terminology that aligns in no way with any other language cultures
 
@LightnessRacesinOrbit that's a class method, it knows its class
 
2:22 PM
@JimmyHoffa lol
@AaronHall Repeating the same terminology doesn't help in explaining it :(
 
@Ixrec That wouldn't be Pythonic, would it?
 
a class method is a function of the class, an instance method is a function of the instance
 
@Yannis does PHP use the "class" method vs. "instance" method terminology as well?
I know there are multiple language cultures that do use such terms I believe
 
ok apparently I don't know Python at all. I have no idea what the distinction is between the two.
 
@AaronHall we understand static vs non-static, it's the other distinction you're making that you still haven't provided an explanation for
 
2:24 PM
In my world, you have free functions, and you have static "methods" and non-static "methods" and that's it.
 
I'm looking at the docs for dict.fromkeys() and str.maketrans() and I'm not seeing it either
 
@classmethod
def a_class_method(cls, x, y, z=None): ''

def a_instance_method(self, x, y, z=None): ''
 
@JimmyHoffa No. The terminology follows Java's.
 
@LightnessRacesinOrbit I think he's using the term class the way we use the term type because Python doesn't have a static type system so they perhaps lack terminology around the concepts of types
 
@AaronHall again, that's not the part we're confused about
 
2:24 PM
hey I've just had an excellent rep gathering idea :D
 
@AaronHall you're the one who said class method != static method
 
Well I'm trying to keep up...
 
@AaronHall so it becomes a class method just by putting "@classmethod" above it's definition?
 
ok, staticmethod:
 
does cls mean something special?
 
2:25 PM
@staticmethod
def a_static_method(x, y, z=None): ''
Yes, cls is the class that it is a function of
 
@AaronHall how do you then call that?
 
cls.classmethod(x, y)
 
no no, the static method
 
cls.a_static_method(x, y)
 
... ?? those are identical
 
2:27 PM
or instance.a_static_method(x, y)
 
wait, so str.maketrans is a class method and not a static method because its arguments are strings? is that it?
 
@AaronHall oh wait - a static method can be called on any class or instance?
 
they look identical, but there's a dotted lookup, and the decorators use descriptors to determine what the first argument is (or isn't...)
 
so it's a free function with syntactic sugar to make it look like it's a member of other things
 
You can call a class method on an instance
you can't use an instance method on a class.
 
2:28 PM
@AaronHall but can you call a static method on any class or instance? I mean, your static method definition didn't specify a class
 
1225
Q: What is the difference between @staticmethod and @classmethod in Python?

Daryl SpitzerWhat is the difference between a function decorated with @staticmethod and one decorated with @classmethod?

 
cls.an_instance_method(x, y) would raise an error
 
@Ixrec dammit
0
Q: What are "class methods" and "instance methods", in Python?

Lightness Races in OrbitThere has been a discussion in chat relating to a question (the question itself being irrelevant to this one), that has revealed I may not know Python whatsoever. In my mind, although terminology differs across languages, we may generally categorise functions as: [free] functions static method...

lol
 
> With classmethods, the class of the object instance is implicitly passed as the first argument instead of self.
 
@JimmyHoffa Yes
 
2:29 PM
wait, self isn't the class of the object instance?
are we passing types around instead of objects?
 
self implies instance
 
@Ixrec they don't have a type system so I don't think they use the term "type" - I think "class" means type to them
 
or is the "class" a special instance that has only the non-instance methods?
 
and I have discovered why they don't call class methods "static" methods, they apparently call free functions static methods, because they have a way of making any free function accessible as if it were a member of anything
 
2:30 PM
what I just linked completely contradicts the possibility that static method == free function
 
I have an answer on that link. :)
 
@Ixrec he just said you can call it on any class or instance, it isn't a member of anything but pretends to be a member of everything... that's a free function with syntactic sugar
 
Isn't it obvious? — Yannis ♦ 14 secs ago
dafuq seriously
 
hey, I'm allowed to troll every now and then
 
> They behave like plain functions except that you can call them from an instance or the class:
 
2:31 PM
MOD ABUSE CALL THE - ER....
if it were obvious do you really think we'd be having this conversation
 
@Ixrec your link supports my position. They have syntactic sugar to make free functions pretend to be methods, and then they call them "static" methods. class methods are what the rest of us call static methods, and instance methods are what the rest of us call "methods"
 
@JimmyHoffa if this is correct it's a very good way of putting it. To the answermobile!!
 
a.static_foo(1) doesn't look like a free function to me
 
@Ixrec it is though
it's defined without any type or instance
 
that's so wonky
 
2:33 PM
yeah, it's just sugar..
 
did those sorts of "methods" predate proper methods in Python?
I can see it being historical
 
but it is defined as part of a class
 
@Ixrec no it's not
 
@Ixrec apparently not
 
now it sounds like you're arguing free functions == static methods in all languages
ok, in the thing I linked it is
 
2:34 PM
he's not
 
@Ixrec no it's not
 
What's the smalltalk convention on this?
 
class A(object):
@staticmethod
def static_foo(x):
print "executing static_foo(%s)"%x
^it's part of A, isn't it?
 
@JimmyHoffa does look like it to me
 
the fact that it could have been declared outside of A doesn't change the fact that it isn't declared outside of A
 
2:36 PM
@Ixrec ok then. So it's...a function. I guess
has no access at all to anything in it's class, where a class method has access to other class information I guess?
 
Hey, at least it's not a monad.
 
@Yannis at least then I would know what the hell he was talking aboujt
 
You, sure. Anyone else? I doubt it.
 
Dec 14 at 17:45, by Jimmy Hoffa
Dec 7 at 17:07, by Jimmy Hoffa
Jul 27 at 13:30, by Jimmy Hoffa
Jul 14 at 15:02, by Jimmy Hoffa
@Ampt Have you accepted Haskell into your home, and into your heart?
 
anyway
now that I've found my way to the python docs on the @classmethod and @staticmethod decorators, it's now clear that these terms refer to real things that have definite meanings
the big remaining mystery is the cls thing that @classmethod generates, which those docs don't really say anything about
other than claiming it's "the class", which doesn't help much
does that mean it's a special object with all the non-instance methods of the class but no instance-y bits, or is there other magic going on?
 
2:41 PM
So, to me this edit is an important distinction: programmers.stackexchange.com/review/suggested-edits/127486
 
note that these terms are still totally meaningless in Javascript =)
but sure, I have nothing against someone else approving (it won't let me change my mind)
 
oh, and I'm going to answer that new question...
 
@AaronHall yay
 
I missed the deleted comment
 
didn't miss much
 
2:43 PM
ok :)
 
2:54 PM
ffs I hate when people delete their questions just as I'm answering them
arse
 
feedback welcome on my answer
 
meh still not clear
from either of them :(
don't show my CV to any of your Python guys ok
 
what's not clear?
Do I need to quote the question, and write more to the question?
 
I don't know because it's not clear to me
I'm still not getting this "knows its class" business
Was Jimmy right earlier about the syntactic sugar to make free functions behave as if they were members?
and am I at least right in saying that Python is batshit insane with a completely different notion and categorisation of "method" to everything else?
 
So a class method isn't static because members of the class can change (though they usually don't)
 
3:03 PM
wait what
 
@LightnessRacesinOrbit sort of.. I think because it's "in" the class, it is accessible as a member, but it has zero access to anything in that class - not other static methods or other class methods or anything. "class" methods however I think have access to other classmethods
 
a static method doesn't rely on the class
 
this is so completely different from how every other class-based language works :(
whyyyyyyy
 
@AaronHall You don't know Java or C# or C++ or any of the common static type system languages do you?
@LightnessRacesinOrbit Python started as a procedural language..
 
@JimmyHoffa So did C++
 
3:04 PM
I do not know their type systems
I've used Ruby a little, but it was a long time ago
 
@AaronHall you should learn one - it would help you communicate with a broader audience on some of these higher level concepts which you're clearly familiar with and understand
 
this whole conversation is cross talk because we don't know Python and you don't know any of the myriad type systems we're familiar with
 
I'm not cross
a little hungry perhaps
 
@LightnessRacesinOrbit you're a C++ coder; you're cross with everything and everyone
 
3:06 PM
@JimmyHoffa I'm cross cross
 
This is just executable pseudocode, what's the big deal?
 
just the other day you were yelling at a tea pot
 
@JimmyHoffa that was a C pot
 
@LightnessRacesinOrbit C/C++
 
user55340
3:07 PM
@Yannis Isn't it pythonic.. don't you think?
 
user55340
(I'm sure I can come up with some awful lyrics for that...)
 
haha
1
Q: Does my design break modularity and loose coupling?

hlapointeI want to know if my implementation is modular and loosely coupled such that pieces can be replaced easily. Any concrete class that extends the abstract class HexGridLayout will be expected to update the field coords by using the field center of the HexGrid. Does passing HexGrid to the HexGri...

^-- good question?
 
@MichaelT doooo itttttt!!
 
I think I fixed it.. I'm not sure whether it was fitting or not before
 
@JimmyHoffa hard to answer but looks on-topic
I enjoyed your original comment on the original
 
user55340
3:08 PM
@LightnessRacesinOrbit Thinking about it... some of the meter is just a bit awkward to work with.
 
@MichaelT if it helps you can use the common substitution s/python/whython/
 
I answered, but I get no love
 
@AaronHall I find Bryan Oakley's answer far clearer to be honest
The way you use the term "class" is very strange to me (probably totally normal for Python folk)
 
user55340
Hmm... my cat's pestivious meter is set to 11 today for some reason.
 
is it a class cat or an instance cat or a static cat
 
3:15 PM
@LightnessRacesinOrbit cats don't support that shit, they're all just free cats
 
user55340
Short hair, so the static cat isn't as prevalent.
 
@MichaelT temperature? Perhaps the frozingness demands more interaction with the various electrically heated devices nearby
Whenever it's cold outside and I let my dog out; when he comes back in the cold seems to have put a rocket up his butt because he flies in and runs circles around the house for like a minute, presumably trying to warm back up
 
user55340
Nov 20 '14 at 20:36, by MichaelT
Me and my cat.
 
@JimmyHoffa ok
yep definitely hungry
 
user55340
@JimmyHoffa heater in the room. Thermostat sensor says its 70F in here (I can get one room of the house comfortable). And its pestivious nature is that of "purr", rub up against me. One claw extended tap my hand.
 
user55340
3:18 PM
(just put some cat treats in a "you need to work at it to get them out" treat dispenser)
 
@MichaelT my cat would stand by that thing screaming his discontent until somebody gave it a treat
 
user55340
My cat doesn't care too much for the string part - but the hole in the side for getting a treat out... he's all for that.
 
3:29 PM
updated my answer
 
@AaronHall gonna take me a while to read. hungry.
the difference from other languages seems to stem from classes being treated as first class objects. ish?
and static methods are really just free functions in the class's "namespace"
 
@Ixrec in Python, everything is an object. Including the class definition
So each instance object is an object, and they are instances of classes, which are also objects.
 
this would all make great interview discussion
gives me things to talk about while I'm explaining how I have written Python but don't really "know" it
 
>>> isinstance(object, object)
True
>>> class Object(object): ''
...
>>> instance = Object()
>>> isinstance(instance, Object)
True
>>> isinstance(instance, object)
True
>>> isinstance(Object, object)
True
object is an instance of type
and type is an object
>>> isinstance(object, type)
True
>>> isinstance(type, object)
True
type is the metaclass of object
So the class is an object that can be passed around as an argument
 
3:41 PM
Is that where the confusion comes from?
 
no
the confusion comes from you answering questions about terminology with the same terminology :P
but your answer is better now
 
ok, ask me more questions or tell me how to improve it
Use more and different terminology?
 
I think Jimmy summed it up pretty well
We've probably taken this as far as we can without a common language
a line at the top saying "forget everything you think you know about 'methods' from other languages" would be the icing on the cake for the first-time reader
to go back to your initial question, then, the edit seems fine if you explain in the reason that it's due to ambiguity with Python's bizarre "method" concept, and check that that's really what the OP (who may be a Pythonista) meant
 
I don't know if "forget everything you think you know about 'methods' from other languages" is quite right
 
pretty sure it is
meanwhile I was hoping for more love on the question itself :( sadface
did I mention I'm hungry
 
3:53 PM
mmmm bagel and lox
want one?
 
user55340
Whee! Present for me from me in the mail.
 
nah gonna oven cook some chicken dippers I think
it's amazing how many people are now "remembering Lemmy". didn't realise until today that any of them had actually met him let alone knew him
 
What if I had said, "remember math class? y is a function of x (f(x))? well a classmethod is a function of the class"
 
probably not useful as I can't see how you'd maintain that analogy while describing instance and static methods
and it's already pretty weak even for class methods
:P
 
What? It applies precisely the same!
an instance method is a function of the instance
A static method is a function of neither!
 

« first day (1943 days earlier)      last day (3050 days later) »