I feel haunted by exceptions.. Can you relate? ๐ ๐จโ๐ป
I feel haunted by exceptions.. Can you relate? ๐
๐จโ๐ป
๐ก Continue reading for error handling tips!
"Error handling is important, but if it obscures logic, itโs wrong."
- Robert C. Martin
I want to back this quote with another quote from the inventor of C++:
"I like my code to be elegant and efficient. The logic should be straightforward to make it hard for bugs to hide, the dependencies minimal to ease maintenance, error handling complete according to an articulated strategy, and performance close to optimal so as not to tempt people to make the code messy with unprincipled optimizations. Clean code does one thing well.
- Bjarne Stroustrup
Best way to have error handling is by writing clean code. Making sure you have elegant and efficient solutions so bugs can't hide but will be very obvious once an exception occurs. You can do so by doing three thing:
1. Clear naming
Choose clear naming for variables and functions. Don't shorten names but write them out, this will stop assumptions when someone else needs to look at it, or you need to look at it yourself after a few weeks. This can be backed by comments, but only for notes! Commenting to explain means your code needs to be simplified ๐.
2. Formatting/conventions
Choose a consistent format and convention for your code base. Use code suffix for private, public, and protected but also for properties and local variables. This will make it much easier to read the code. ๐
3. Design patterns
Stick to design patterns that are optimal for your needs. This helps giving you a rule set to hold on to that helps a lot tracing issues. ๐ If you aren't familiar with design patterns I recommend to read books: Game Programming Patterns and Head first Design Patterns. ๐
Hope you find this useful, if you do, feel free to save this post so you can read again later!
----
But nevertheless, I feel very much haunted by null reference exceptions.. happens all the time to me ๐
and keeps surprising me.
How about you? What exception are you haunted by while programming?
Happy coding everyone! ๐จโ๐ป
๐ก Feel free to like, save and share this post!
~ Follow me for more @justinbieshaar
Comments
Comments from the original post on Instagram
No comments yet
