DEV Community

Discussion on: Keep your code dumb

Collapse
weswedding profile image
Weston Wedding • Edited on

I ported some logic from the GSAP animation library to C++ for use in an Arduino library that imitated the GSAP's "Tween" and "Timeline" objects in order to make animating some LEDs easier.

GSAP has some lazy initialization logic inside some of their functions and I went along with it because, hey, why not? Lazy initialization is clever and I like clever!

Unfortunately it resulted in unpredictable crashes that sent me on hours of wild goose-chasing as I went from one potential cause to another.

Eventually I realized it was the lazy initializing hiding my "real" memory usage and I was trying to allocate more memory than I had in ways that depended entirely on what I was trying to do with my library in any given program.

This would've been easy on a real computer, but you don't get stack traces or error messages in Arduino to debug with. Things just stop. Crashes would happen slower or quicker depending on how many debug messages I was using because those take up memory, too.

Collapse
joelnet profile image
JavaScript Joel Author

Sounds very similar to our experience. I find those hidden kind of bugs waste the most time.