5 ms·
> You always "encode" something into bytes, and "decode" bytes back into something. There should be exactly two functions, because the functions have different
by cgrubb 11y 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.
- paulgayham 11y agoEncode is STR to Bytes? WTF? You 'encode' a string, already in UTF-8, to raw bytes? WTF?!
- mark-r 11y agoI would use .to_str() instead of .from_bytes(), since the action is from the perspective of the object you're calling it on.
- viraptor 11y ago> Surely information can be encoded in other ways. Information - yes. Strings... I'm not sure. What other representations are you thinking about?
- msellout 11y agourlencode(mapping) --> querystring