Ruby vs. JavaScript: An Error Primer

DBC Week 7: Challenge #9

June 12, 2015

    Sitting here trying to think about a fundamental difference between Ruby and JavaScript the first thing that comes to mind is the error message. Or the lack thereof if you want to look at it that way.

    As a beginner to coding there have been many hurdles to pass and much frstration to overcome. I have found that one of the biggest sources of my frustration in learning something completely new is dealing with mistakes and errors. As a kid I was taught that mistakes are not a problem, that they should even be looked at as good because they are a learning tool. How are you going to learn how to do something right, if you don't ever know what it is like to do that thing wrong? Making a mistake is not something to be looked down upon, because it's what you do with, or on account of the mistake, that really the important thing. Great and magnifecent things have come form mistakes throughout history, and will continue to do so.

    The issue is that in order to grow from our mistakes, we have to have some information about those mistakes. What caused them? Where did they happen? What else could have been done? Why is that something else better? Conveniently both Ruby and Jacvascript give us information about our errors in the form of messages when they encounter some error in our script. However what those messges that each language sends is a fundamental difference between the two languages.

    In some sense Ruby is the good cop in this situation. Error messages in Ruby tend to give you a ton of information. The file name is given. The line number the error occurs on is given. The type of error is given. There is even an arrow pointing to the point of error included in the message. Once one learns how to read through a Ruby error message, fixing the problem is not all that big of an issue. You can go to the file called for, find the line mentioned, pinpoint where the error is happening, find the type of error that is occurring and go look up how to fix it. Maybe the task of actually making the code run will prove to be difficult, but Ruby will tell you everything you need to know to go about fixing it outside of telling you how to fix it.

    Of course if there's a good cop there has to be a bad cop. JavaScript is wearing the bad cop costume in this context. JavaScript tells you that there is an error and pretty much leaves it at that. JS gives you information about the error, but it's not as informative. Sure the line and file location are there, but outside of a one line message, there's not much more to it than that. JS tells you that it can't recognize something, or it can't take some action on undefined, or that some value is not defined. The issue is that all three of these messages can come about because of a misplaced comma or semi-colon that occurred somewhere else than the line being mentioned in the error message. JS error messages don't throw that clear and concise message as to what happened, where it happened and why it is happening.

    This is not to say that one of the languages is better than the other, or that someone should choose to use one language over the other because of the difference of how they treat errors. The point is that if you are one of those beginners, such as myself who are really and truely breaking into the world of coding for the first time, you need to be aware of the fact that if although JS doesn't give you the information that Ruby does about your error there's no reason to pull your hair trying to figure it out. What I have learned over the past week is that JS makes you work for it. You have to go back up and play around with the code. Maybe you forgot a comma and that's why your function is reading as not defined. Maybe you forgot one of the ever present semi-colons somewhere and two lines are being read as wone. JS makes you go back and sift through your stucture and sytax to see what is really going on, almost forcing you through a learning experience that is a little more active than reading. As long as you can employ the patience to work back through the file and check all your points of syntax, any error can be overcome.