Prefixes and namespaces
/* Namespaces are one honking great idea -- let's do more of those! */ There are two ways to avoid name conflicts: prefixes and namespaces. Programming languages that lacks namespaces (such as C) need to use prefixes. For example: PROTOCOL_SSLv2, PROTOCOL_SSLv3, PROTOCOL_SSLv23. Python used the same prefixed names when reflect C constants to module level Python globals. But when convert integer constants to IntEnum, is it needed to preserve common prefix? Or may be we can drop it, because enum class name plays its role? class Protocol(IntEnum): PROTOCOL_SSLv2 = ... PROTOCOL_SSLv3 = ... PROTOCOL_SSLv23 = ... or class Protocol(IntEnum): SSLv2 = ... SSLv3 = ... SSLv23 = ... ? Protocol.PROTOCOL_SSLv2 or Protocol.SSLv2?
On Sat, Feb 21, 2015 at 1:28 PM, Serhiy Storchaka <storchaka@gmail.com> wrote:
/* Namespaces are one honking great idea -- let's do more of those! */
There are two ways to avoid name conflicts: prefixes and namespaces. Programming languages that lacks namespaces (such as C) need to use prefixes. For example: PROTOCOL_SSLv2, PROTOCOL_SSLv3, PROTOCOL_SSLv23. Python used the same prefixed names when reflect C constants to module level Python globals. But when convert integer constants to IntEnum, is it needed to preserve common prefix? Or may be we can drop it, because enum class name plays its role?
class Protocol(IntEnum): PROTOCOL_SSLv2 = ... PROTOCOL_SSLv3 = ... PROTOCOL_SSLv23 = ...
or
class Protocol(IntEnum): SSLv2 = ... SSLv3 = ... SSLv23 = ...
? Protocol.PROTOCOL_SSLv2 or Protocol.SSLv2?
So I like the latter (Protocol.SSLv2) but would qualify that with the request that ssl.PROTOCOL_SSLv2 continue to work until Python 2 is dead and libraries like requests, urllib3, httplib2, etc. no longer need to support those versions.
On 02/21/2015 11:49 AM, Ian Cordasco wrote:
On Sat, Feb 21, 2015 at 1:28 PM, Serhiy Storchaka wrote:
? Protocol.PROTOCOL_SSLv2 or Protocol.SSLv2 ?
So I like the latter (Protocol.SSLv2) but would qualify that with the request that ssl.PROTOCOL_SSLv2 continue to work until Python 2 is dead and libraries like requests, urllib3, httplib2, etc. no longer need to support those versions.
Good idea, and easy enough to do since Enum supports aliases. -- ~Ethan~
On 21.02.15 21:49, Ian Cordasco wrote:
So I like the latter (Protocol.SSLv2) but would qualify that with the request that ssl.PROTOCOL_SSLv2 continue to work until Python 2 is dead and libraries like requests, urllib3, httplib2, etc. no longer need to support those versions.
Of course, ssl.PROTOCOL_SSLv2 will continue to work until Python 2.7 and 3.4 are dead.
On Sat, 21 Feb 2015 21:28:21 +0200 Serhiy Storchaka <storchaka@gmail.com> wrote:
/* Namespaces are one honking great idea -- let's do more of those! */
There are two ways to avoid name conflicts: prefixes and namespaces. Programming languages that lacks namespaces (such as C) need to use prefixes. For example: PROTOCOL_SSLv2, PROTOCOL_SSLv3, PROTOCOL_SSLv23. Python used the same prefixed names when reflect C constants to module level Python globals.
Python still uses the names, and they are still globals. There's no reason to change that. The enum is simply there to improve debugging when printing the values. Regards Antoine.
participants (4)
-
Antoine Pitrou
-
Ethan Furman
-
Ian Cordasco
-
Serhiy Storchaka