Object oriented programming in Python be like:
-
I'll add that 100% of the above is understood by the compiler. Unlike Python or JavaScript where you don't know how bad you have it until the program is already running.
At least python has a decent runtime typing system
JS's type system feels like what you'd get by giving a monkey access to unlimited cocaine and a computer
-
Oh, you assigned a method to a variable before calling it? Congratulations,
this
is nowundefined
.Yes. There's no telling what
this
is.this
could be anything. We tried to keep track ofthis
, but no one knows whenthis
will change. -
Yes. There's no telling what
this
is.this
could be anything. We tried to keep track ofthis
, but no one knows whenthis
will change.I used to be with
this
, but then they changed whatthis
was.Now what I'm with isn't
this
, and what'sthis
seems weird and scary to me.This'll happen to you!
-
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.
wrote on last edited by [email protected]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.
-
Not like C# is all that much better. So much garbage in the fundamentals just because it was done that way at the start and "they can't change it now". The best example is the IList interface.
Theoretically this interface exposes both index-based access and collection-like modifications and as such would be perfect in a function if you need those two features on a type. In reality you can't use it as a function parameter because half the official types implementing IList aren't modifiable and throw a runtime error. E.g Arrays
Embrace the holy light of Dart
-
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.
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.
-
Now my brain wants to relate Java somehow to beancounters.
Well it is owned by Oracle now
-
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?
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.
-
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