On Sat, Mar 28, 2020 at 11:28 AM Ivan Pozdeev via Python-Dev
<python-dev@python.org> wrote:
>
> On 26.03.2020 19:24, Ethan Furman wrote:
> > Before Enum, the repr for socket.AF_UNIX was:
> >
> > 1
> >
> > Not very useful for debugging.
>
> On the contrary, it's perfect. I know everything I need: it's an integer 
> constant, end of story.
>
> When examining some live object, I would probably see that "1" and won't even 
> need to look anything up to know what I'm dealing with.

This is something I see *very* frequently from expert and novice
Python programmers: the belief/assumption that seeing the concrete
data is the most important thing. As an extreme expert in socket
programming, you probably DO interpret the integer 1 as "AF_UNIX", but
quite honestly, I wouldn't recognize it as such. But a repr that says
that it's socket.AF_UNIX is far far more helpful. Consider:

Suppose you have a call to socket.socket(socket.SOCK_STREAM,
socket.AF_INET, socket.IPPROTO_TCP) - only they're not literal values,
they're coming from elsewhere. Pre-enum, all you know is that it's
being passed the integers 1, 2, and 6, and how are you going to figure
out what they mean? Thanks to the enum, you get to see them with their
names (which may make the bug obvious). But either way, they are
"socket.AF_INET" etc, they are not "socket.AddressFamily.AF_INET" -
the class is a mere implementation detail.

In actual fact, the concrete integer value is just an implementation
detail, too. As long as passing socket.AF_INET results in an
internet-address-family socket, it doesn't really matter what the
actual integer is. For the sake of cross-language debugging, it's
helpful to be able to see it, but most Python programmers aren't going
to need it.

ChrisA
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/MDTY2P2UWIU2O2OYP7A6RVJLB4PA73MM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to