Hacker News new | ask | show | jobs
by cgrubb 3841 days ago
> You always "encode" something into bytes, and "decode" bytes back into something. There should be exactly two functions, because the functions have different types: "encode" is str -> bytes, "decode" is bytes -> str. Explicit is better than implicit.

I'm not sure "encoding" tells us that the output is bytes. Surely information can be encoded in other ways. Names like .to_bytes() and .from_bytes() might have saved a lot of trips to the documentation.

2 comments

I would use .to_str() instead of .from_bytes(), since the action is from the perspective of the object you're calling it on.
> Surely information can be encoded in other ways.

Information - yes. Strings... I'm not sure. What other representations are you thinking about?

urlencode(mapping) --> querystring