I am writing a simple IRC chatbot in Python and, in an effort to get more into OOP, made a basic "connection" class that manages all the backing-and-forthing involved. But IRC protocol is rather annoying to work with, so I wrote a function that takes the raw message from the server and translates it into a form that's much easier to work with. (It separates out the user/channel the message came from, the message it contained, etc.)
In my first iteration of this function, I used a tuple to return this information, but this was extremely difficult to work with as I had to remember which item in the tuple corresponded with what information. Then I changed it to return a dictionary, with the indices being "channel," "user," and "msg." (Not all are used for every message/event, of course.) But as I'm looking back at my code written for that system, it too seems a bit unwieldy. So what's the best* way to go about doing this? Was my string-indexed list a good way to go? Or should I continue with the tuples, but unpack it into separate variables? Thanks in advance.
- I'm going for readability, maintainability, and Pythonicness (if that's a word)