New article:
⚠️Why you should avoid import * in Python 🐍
https://pybit.es/articles/why-you-should-avoid-import-in-python/
Covering:
- Why modules are great and namespacing explained
- Why import * is a problem
- A practical example where a function gets overriden
- The recommended way to do imports
- What PEP8 has to say about this
- Protection workaround, use __all__ to define your module's public interface
#python #pythonprogramming #modules #encapsulation #namespacing #zenofpython #bestpractices #pitfalls #imports #dundermethods
#python #pythonprogramming #modules #encapsulation #namespacing #zenofpython #bestpractices #pitfalls #imports #dundermethods
Just found myself considering when/whether to work on a particular blog post that’s been bobbing about in my brain, and I answered myself with “Now is better than never. Although never is often better than *right* now.”
I have been assimilated.
#Python query: should the string message inside Exception (sub)classes be considered part of the API / contract?
On one hand, client code performing "stringly typed" comparisons to a caught exception's text, is a code smell. Changing to raise a subclass of the old exception, w/ a different message, "should" be backwards compatible.
OTOH, esp when a codebase historically had too-broad exception classing, users have to #ZenOfPython rule 9 & do that string compare. Now they're broken. Ugh.
Go Proverbs - https://go-proverbs.github.io/
Like #ZenOfPython but for #Go.
„Clear is better than clever“ and „A little copying saves a dependency“ are my favs. What are yours?
#zenofpython #go #GoProverbs #golang
@Lomig@octodon.social Pardon désoler j'aurais du faire plus attention (faudrait il une instance mastondon pour les bretonnant ?). Pour moi le beurre doux n'existe pas c'est du beurre sans sel, je précise beurre salé car //explicite is better than implicite// #zenOfPython