today I'm thinking about why it's useful for someone who mostly works in higher-level languages (python, JS, scala, etc) to understand how computers represent things in bytes.

some ideas I have so far:

- reading the output of strace
- doing back-of-the-envelope storage calculations
- choosing the right size for a DB primary key (to prevent overflow)
- knowing the limits of JS numbers
- optimizing algorithms (like knowing that multiplying by 2^n is fast)
- debugging encoding issues

what else?

I'm also curious about whether there's ever a reason to understand how two's complement works (I'm sure it's cool but I've never needed to learn it so far, only that signed and unsigned integers are different)

Ten years ago I wold have thought you crazy to say that. But you are right, and old folks like me who have made use of/relied on details properties of particular machine storage hopefully now realize those tricks -- cuz that's what they are -- are side effects that should be avoided, not exploited.

The old justifications are mostly gone. Speed, compactness of expression, storage limitations, crappy compilers and tools -- and I only say this part to make myself more popular (lol) -- macho programming. Cleverness for cleverness' sake. I've done enough clever programming (as opposed to elegant programming, say) with good intent (and often good effect). But I dont think its a good habit at all, today, in modern languages, or in old languages we still (I still) use: C, C++.

In my current embedded work, little machines with limited resources, relying on word length and overflow off the end of a word, or using shifting to speed up math -- those are all really bad concepts.

I'm pretty sure gcc will apply those tricks if you say X = Y * 2 and X and Y are integers. THAT'S GREAT! Our language can be portable (Y * 2) and the fungible compiler output gets the gain.

LOL -- that said, representation of numbers within a machine is to me *fascinating*, as is representations of meaning of characters, numbers, symbols and their relations to glyphs, etc.

Someone has to know that stuff to make machines. The old days though are long gone, where you apply what you think are machine-dependent trickery (word length) to gain advantage with a compiler.

@b0rk

Follow

@tomjennings @b0rk Is pretty useful to understand which algebraic properties hold for unsigned ints or floats despite overflow and rounding, and which ones don't; algorithm correctness can depend on it. Most of the time we don't care but occasionally we care a lot.

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.