5
benj
324d

I know we are supposed to rant here... but I've been on sabbatical for a bit and just rediscovering how fun computers are has been so refreshing!!

Here's the next little post about a toy chip8 emulator I've been working on 😊

https://benjcal.space/posts/...

Comments
  • 1
    The moral of the story isn't at all about premature optimization or clever code. It was a type confusion. Your assumption of what the function returns was wrong and therefore you processed the result incorrectly.

    In General, if it returns an int, you should define the variable holding that result as an int. You can do checks on the result and then explicitly cast to a detected narrower type.

    But if you think to yourself "why is it returning this type instead of just that type which obviously is more narrow and therefore preferable," then you should investigate that function further as chances are high that you'll find a bug in your reasoning about the function or in the function itself.

    Always be vigilant lest the bugs taint your code and poison your reasoning.
  • 1
    @Oktokolo you are absolutely right!

    I think there are two extremes which I've been... high-level languages in which types doesn't matter, and low level 8bit and 32 bit embedded in which registers and cycles matter quite a bit... This C dev for me was totally new, and quite enjoyable, even if on the way I def made more than a few blunders!
  • 2
    It’s very well written. 🍺
  • 0
    @nanobot 🙏
Add Comment