Skip navigation
I feel haunted by exceptions.. Can you relate? ๐Ÿ˜…๐Ÿ‘จโ€๐Ÿ’ป
0:00

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