Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Never invent such names; only use them as documented." Who?

I read PEP 8 for to know whether (an imaginary) me creating an object with a name such as __foo__ is a good idea or not. PEP 8 says this about __double_leading_and_trailing_underscore__:

Never invent such names; only use them as documented.

My question is: who?

I am a programmer. I write an API for other programmers. Python was implemented by programmers. The language reference for the implementation was written by programmers or at least ex-programmers, and the programmers using my API will write something that may or may not be used by further programmers.

Now this unfolded, which programmer is PEP 8 speaking of when they say, "Never invent such names"?

Someone is obviously encouraged to invent such names, since they exist, while others are uninvited to do so.

Which group of programmers should "Never invent such names" ?

like image 275
n611x007 Avatar asked Jan 15 '15 14:01

n611x007


1 Answers

You are discouraged from using such names in your APIs, yes, because if and when the Python core developers pick the same name for Python itself, you'll lose out, your API can break.

So, if you are not a Python core developer or writing a PEP that may be one day become part of the Python standard library or core language definition, try to stay away from using dunder names in your API.

like image 177
Martijn Pieters Avatar answered Nov 15 '22 14:11

Martijn Pieters