“public” or “private” attribute in Python ? What is the best way?

Typically, Python code strives to adhere to the Uniform Access Principle. Specifically, the accepted approach is: Expose your instance variables directly, allowing, for instance, foo.x = 0, not foo.set_x(0) If you need to wrap the accesses inside methods, for whatever reason, use @property, which preserves the access semantics. That is, foo.x = 0 now invokes … Read more

Good way to encapsulate Integer.parseInt()

You could return an Integer instead of an int, returning null on parse failure. It’s a shame Java doesn’t provide a way of doing this without there being an exception thrown internally though – you can hide the exception (by catching it and returning null), but it could still be a performance issue if you’re parsing hundreds of thousands of … Read more