Sequel Error Handling
Last time I talked about using exceptions with Sinatra’s error handling to easily format resource errors without having naming schemas or global variables. When doing work with exceptions it is up to you to draw a firm line on what an exceptional circumstance is. If you get a code review and the feedback is, “The code is terrible! How could you use exceptions like this. Java Developer!” Then they may be parroting something they read in fad magazine which was originally published 10 years ago, or, more likely, the proper feedback that you should hear is, “Your code is not terrible, but bad. The execution path is extremely confusing and in 2 months you won’t be able to follow it either.” From there you have two options. Redefine what an exceptional circumstance is in your domain, or figure out what is causing the yo-yoing in between the exception and the normal program flow.
Print Stuff Mail It
It’s been a bit quiet around the copypastel labs for a couple of months now. We’ve been busy.
Sinatra Error Blues
When working on someone else’s code it is often hard to tell if something you don’t like is bad code, or if it is just a style of thinking you need to get used too. For instance, when updating a model with a restricted parameter (such as id), should it raise an error, or just ignore the parameter? On one hand if you have a new developer he may be confused as hell when he has unexpected bugs because the restricted columns are silently ignoring their parameters. I have even been tripped up a few times myself! An error would be much clearer and give you a path to instantly fix it. On the other hand, if you truly know your tools, then this is expected behavior. It allows you to cut down on error handling and makes the intent of the code much clearer.
QR (de)Coding
If you’ve ever come across our 404 page, you’ve no doubt noticed our QR code meant to help with your feeling of being lost. The code is generated with pure Ruby, with one of the many libraries a quick Google search brings up. However, when it comes to decoding QR codes, the findings are much slimmer.