2 ms·
If you pass around numbers as strings (or JSON, or XML) even though they can be more compactly encoded in binary, you’re doing sloppy programming. If you then p
by thwarted 16y ago
If you pass around numbers as strings (or JSON, or XML) even though they can be more compactly encoded in binary, you’re doing sloppy programming. If you then parse those back into a native int at some later point and assume it won’t overflow, you’re really doing sloppy programming.
I find this to be a terrible example of what's sloppy. Formatting as text is more portable, it's one of the tenets of the UNIX Philosophy.
If you encode numbers in binary, you also need to somehow communicate the endianness of the encoding (maybe this is standardized, and you always use htonl, but something still needs to know that you're using "network order"), and you need to store how many bytes the number represents (because the int size on the target may be different a different size) , and you need to provide some way to easily convert back to a readable format for debugging.
By the OP's logic, SMTP and HTTP are "sloppy" because they are readable and easily debugable; admittedly, they are sloppy for other reasons, but not because they don't encode things in binary.