Write a new method, make sure to reference self first. Write a new method, make sure to reference self first. Call the method, make sure to reference self first.
You don’t reference self when calling a method, what on earth are you talking about?
You start with the instance when calling the method, like most/all other OOP languages.
Also there are benefits with the explicit self/this to access instance properties.
In C++ you need to make sure all class properties/members have a naming scheme that does not conflict with potential parameter names or other names of other variables.
that’s because anyone who develops oop in Python is mentally ill.
Python is a scripting language, not to be confused with an actual programming language. Like everything else in development over the last decade, newbs are just shoehorning whatever is hot into the language because nobody is stopping them.
that’s because anyone who develops oop in Python is mentally ill.
Hard disagree there. I would argue that most “multi-paradigm” languages converge on the same features, given enough time to iterate. It’s not necessarily about hot-sauce. I honestly think its about utility and meeting your userbase where their heads are.
You’re right in that OOP feels very shoehorned in with Python. But not every project has a Linus Torvalds to publicly humiliate horrible ideas and implementations.
Yeah, some weird accusations. Python has had classes since its inception (1.0).
Also the image in the post makes no sense. It shows multiple (Spidey) instances all pointing to each other which is not how self works.
self is just a parameter that may contain different instances depending how it was called. This is also true for any other parameters in any function, each time a function is called it may have a different instance.
I was looking to see if there are equivalents to Java’s private and protected members, and it looks like Python’s answer to that is just throw one or two underscores in front of things to do that. And it doesn’t really do anything, more of just a naming convention. To me that feels like a basic OO structure that is shoehorned into Python.
A single underscore is just a naming convention, but double underscores triggers automatic name-mangling of the variable in question:
$ cat test.py
classfoo:def__init__(self, x):
self.__x = x
f = foo(1)
f.__x
$ python3 test.py
Traceback (most recent call last):
File"/mnt/d/test.py", line 6, in <module>
f.__x
AttributeError: 'foo' object has no attribute '__x'
However, much like private/protected variables in java, this is pretty trivial to circumvent if you want.
But I don’t believe that you can argue that access modifiers are required for OO not to be shoehorned into a language, not when influential OO languages like Smalltalk didn’t have this feature either. Java just happens to be closer to C++, where public/private/protected is much more rigidly enforced than either Java or Python
Kinda’ looks like how a psychotic break feels:-?
Write a new method, make sure to reference self first. Write a new method, make sure to reference self first. Call the method, make sure to reference self first.
Yeah, I can see it.
You don’t reference self when calling a method, what on earth are you talking about? You start with the instance when calling the method, like most/all other OOP languages.
Also there are benefits with the explicit self/this to access instance properties. In C++ you need to make sure all class properties/members have a naming scheme that does not conflict with potential parameter names or other names of other variables.
that’s because anyone who develops oop in Python is mentally ill.
Python is a scripting language, not to be confused with an actual programming language. Like everything else in development over the last decade, newbs are just shoehorning whatever is hot into the language because nobody is stopping them.
What 2003 forum thread did this comment crawl out of?
oop hasn’t been “hot” for 20 years.
Might not be hot, but it is sticky.
Hard disagree there. I would argue that most “multi-paradigm” languages converge on the same features, given enough time to iterate. It’s not necessarily about hot-sauce. I honestly think its about utility and meeting your userbase where their heads are.
then the Python userbase must have their heads shoved up their ass.
You’re right in that OOP feels very shoehorned in with Python. But not every project has a Linus Torvalds to publicly humiliate horrible ideas and implementations.
In what way does OOP feel shoehorned in with Python? I ask since that is not my own impression of the language.
Would you also be willing to share what language(s) you feel do(es) OOP without it being shoehorned in?
Yeah, some weird accusations. Python has had classes since its inception (1.0).
Also the image in the post makes no sense. It shows multiple (Spidey) instances all pointing to each other which is not how self works. self is just a parameter that may contain different instances depending how it was called. This is also true for any other parameters in any function, each time a function is called it may have a different instance.
I was looking to see if there are equivalents to Java’s private and protected members, and it looks like Python’s answer to that is just throw one or two underscores in front of things to do that. And it doesn’t really do anything, more of just a naming convention. To me that feels like a basic OO structure that is shoehorned into Python.
A single underscore is just a naming convention, but double underscores triggers automatic name-mangling of the variable in question:
$ cat test.py class foo: def __init__(self, x): self.__x = x f = foo(1) f.__x $ python3 test.py Traceback (most recent call last): File "/mnt/d/test.py", line 6, in <module> f.__x AttributeError: 'foo' object has no attribute '__x'However, much like private/protected variables in java, this is pretty trivial to circumvent if you want.
But I don’t believe that you can argue that access modifiers are required for OO not to be shoehorned into a language, not when influential OO languages like Smalltalk didn’t have this feature either. Java just happens to be closer to C++, where public/private/protected is much more rigidly enforced than either Java or Python