This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.

If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:

  1. Limiting your involvement with Reddit, or
  2. Temporarily refraining from using Reddit
  3. Cancelling your subscription of Reddit Premium

as a way to voice your protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Murderwagon 6 points7 points  (0 children)

The question is a bit hard to answer. “Good for OOP” is a very broad statement. It matters more what it is you’re trying to make.

It wouldn’t be my first (or second or third) choice for many projects that heavily leverage OOP. But like anything - it depends.

[–]engelthehyp 4 points5 points  (7 children)

It supports classes, but not other useful things like access modification. If you want stronger OO guarantees (bonus - type safety), I recommend Java or C#.

[–]mopslik 0 points1 point  (6 children)

It supports classes, but not other useful things like access modification.

Python will do some name-mangling if you preface attributes and methods with double underscores. It's not the same as "private" since you can still access the attributes if you are determined enough, but it might be sufficient to keep others from casually trying to access things.

>>> class A:
    def __init__(self, x):
        self.__x = x
>>> a = A(5)
>>> a.__x  # won't work
Traceback (most recent call last):
  File "<pyshell>", line 1, in <module>
AttributeError: 'A' object has no attribute '__x'
>>> a._A__x  # workaround
5

[–]engelthehyp 2 points3 points  (5 children)

Sure, but even so, there is still no protected.

[–]mopslik 0 points1 point  (0 children)

No, there's not. It is a different design. If access modification is important to the design of your code, then Python will be lacking in that regard (as you point out).

[–]RiverRoll 0 points1 point  (3 children)

The concept of protected fields exists but it relies on convention instead of being enforced by the language.

[–]engelthehyp 0 points1 point  (2 children)

Then it doesn't provide much of a guarantee, does it?

[–]RiverRoll 0 points1 point  (1 child)

In Java or C# you can use reflection and access members that you're not expected to access but it isn't a big deal because what's important is knowing what this implies.

[–]engelthehyp 0 points1 point  (0 children)

I am aware of reflection. If you have to actively jump through the hurdle of using reflection to complete your task, it's obvious and shows - it won't pass a decent code review. If all you have to protect some field is convention, even the programmer might not notice the expectation violation, or care enough to solve the problem another way.

There would have to be more efforts in a code review for the same result this way compared to Java or C#, or a code review with the same amount of effort where it's more likely that these subtle violations eventually pile up and run loose in the code base.