News for hackers. Stuff that matters.
Re:Python has brought computer programming to a vast new aud... by pm90 on Thursday July 19, 2018 @05:34PM (#17570484)
This may sound super n00b but I really like that Java is explicit about everything. So for instance, you explicitly specify variables, methods as private with the keyword 'private'. In python you have to use an underscore, and its still not really private, its obfuscated. That's just one example, but in general I really like that kind of by-the-book verbosity, instead of having to mentally map it into the OOP concepts.
Re:Python has brought computer programming to a vast new aud... by ben-schaaf on Thursday July 19, 2018 @06:53PM (#17571053)
Double underscore is the real 'private':

    >>> class Foo:
            def __fn(self):
                return 2
    >>> Foo().__fn()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'Foo' object has no attribute '__fn'
    >>> Foo()._Foo__fn()
    2
A single underscore is more like 'protected', ie. it doesn't prevent subclasses from easily/accidentally overriding your function.
Re:Python has brought computer programming to a vast new aud... by kjeetgill on Thursday July 19, 2018 @09:29PM (#17571790)
I'm less concerned with encapsulation, but the explicitness is a godsend the larger your codebase or team.

Python keeps code much smaller but above a certain size I wish I could "promote" parts of my code to Java.

Partial typing in Python just isn't close to feeling the same.

Re:Python has brought computer programming to a vast new aud... by xapata on Thursday July 19, 2018 @06:24PM (#17570864)
Why would you want to actually enforce privacy? That makes it harder for the user to patch. Better to provide a mild discouragement via "_name".
Re:Python has brought computer programming to a vast new aud... by twblalock on Thursday July 19, 2018 @06:35PM (#17570945)
Because in traditional object-oriented design you would extend rather than patch. It's the open-closed principle.

There are many benefits to enforcing privacy, and one of the biggest ones is that you can make changes to the internals of your library without breaking your users' code, because they never had access to the internals.

Re:Python has brought computer programming to a vast new aud... by xapata on Thursday July 19, 2018 @06:42PM (#17570985)
You can get that benefit with Python. Name mangling helps. It gets the benefits of `final` without the annoying enforcement.

Don't stop me from patching your buggy code. If writing an extension is more efficient, that's how I'd solve the problem.

Re:Python has brought computer programming to a vast new aud... by marvin on Thursday July 19, 2018 @07:03PM (#17571118)
That's an eternal ideological debate where there is always a rebuttal on the form "a-ha - but you could just...", but the rationale is this: Your class will probably be doing things with the private variables that aren't obvious, and will break things if you access them from outside. (Either by them having a different value than you expect, or expecting a different value than you set).

Of course, if you have a perfect understanding of the code, this will never be a problem, as the program is always executed as it is written. But most likely, not everyone in your organization will be as patient, smart and attentive to the details as you are.

Re:Python has brought computer programming to a vast new aud... by StavrosK on Thursday July 19, 2018 @07:51PM (#17571373)
I don't understand the argument, though. Python's underscore variables are meant to not be accessed from outside. The argument against them isn't that you might be doing some non-obvious things inside the class, that's the whole point of them!

It's a way for the class user to say "I know this is terrible, I know this might break, I want to do it anyway".

Re:Python has brought computer programming to a vast new aud... by ychen306 on Thursday July 19, 2018 @09:36PM (#17571802)
The obvious usage of privacy is so you don't expose an API you don't want to maintain. It's also occasionally used to maintain some invariants; for instance, you can have a public method that wraps around some protected interface that does input checking/clean up. Having the compiler enforcing privacy, in this case, guarantees that whatever actual method you dynamically dispatches to has the "right" input (accidentally calling the interface directly won't compile).
Re:Python has brought computer programming to a vast new aud... by chomp on Thursday July 19, 2018 @06:41PM (#17570974)
Private doesn't mean much. You can still access private members in Java using reflection.
Re:Python has brought computer programming to a vast new aud... by kjeetgill on Thursday July 19, 2018 @09:09PM (#17571709)
This hole is incrementally being closed with the introduction of Java 9's modle system. You can only deep reflect into classes in your modules or those "open" to you.

There are both declaritive and command line param ways to open things so it's not as rigid as it sounds.

Re:Python has brought computer programming to a vast new aud... by kimdotcom on Thursday July 19, 2018 @09:28PM (#17571787)
Check out Ada.