Live data from Hacker News

Lang: Python module for enforcing programming language constraints

github.com

11–20 of 21 posts

Re: Lang: Python module for enforcing programming language constraints

#11
post #9
post #7

Earlier quoted context omitted.

> I can see the value in quickly knowing if new code is mucking with private/protected properties. Would this do it? re.findall(r'(? Anytime you're using ``obj._foo`` and it's not ``self._foo`` that suggests you're mucking about with the internals of an object that the author didn't expect you to use.

That would miss some things, like iteration of all properties without a direct reference, subclasses accessing _Parent__private stuff, etc. I'm not actively looking for a solution, just noting this might be more well received if you could easily turn it off and on. Edit: Again, not looking for solutions. I thought the feedback of being able to turn it on/off might be useful for the OP.

Well, for your future reference, Pylint (https://www.pylint.org/) checks for that and many other common pitfalls. I'm sure its competitors PyChecker and Pyflakes do so as well.

Re: Lang: Python module for enforcing programming language constraints

#13

An impressive effort. Nonetheless, I feel like it would be better to warn about these things via static analysis rather than enforcing at run time.

I agree - enforcing some of these best practices as a lint step would be more useful than crashing at run time. The benefit of these features in Java/C++ is that they catch problems at compile time.

Re: Lang: Python module for enforcing programming language constraints

#15
??? Go write Java if you want to write Java. Don't try to write Java with Python syntax. Use Python to write Python.

Trying to force the idioms of the programming language you just left onto the programming language you just learned is the classic sign of not having put any effort whatsoever into learning the idioms of the new programming language.

Re: Lang: Python module for enforcing programming language constraints

#18
post #5

This makes me a little sad. So, a few observations: - The use of metaclasses for (almost?) every feature in this library makes it prone to metaclass conflicts. What if I want to inherit from two classes that use two different features from the library? >>> class MetaOne(type): ... pass ... >>> class MetaTwo(type): ... pass ... >>> class One(metaclass=MetaOne): ... pass ... >>> class Two(metaclass=MetaTwo): ... pass .…

A little off topic, but it's possible to automatically resolve metaclass conflicts in cases like this (e.g. construct a minimal suitable metaclass on the fly) :)

Re: Lang: Python module for enforcing programming language constraints

#19
post #18
post #5

This makes me a little sad. So, a few observations: - The use of metaclasses for (almost?) every feature in this library makes it prone to metaclass conflicts. What if I want to inherit from two classes that use two different features from the library? >>> class MetaOne(type): ... pass ... >>> class MetaTwo(type): ... pass ... >>> class One(metaclass=MetaOne): ... pass ... >>> class Two(metaclass=MetaTwo): ... pass .…

A little off topic, but it's possible to automatically resolve metaclass conflicts in cases like this (e.g. construct a minimal suitable metaclass on the fly) :)

That's OK if the programmer who caused the conflict is the same person who decided to use this lib. If not, that'll be frustrating for one of the two.
Post reply on HN