Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
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. -
benj8831y@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!
Related Rants
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/...
rant
chip8
emu
!rant