DEV Community

Cover image for Errors: Friend or Foe?? (Probably a Foe)
Simon
Simon

Posted on

Errors: Friend or Foe?? (Probably a Foe)

We've all had that experience, that one bug that just didn't seem to go away. For most of us, it was in our early stages of learning.

For some weird reason, the code you copied from a YouTube tutorial doesn't seem to execute the way it did online and you're certain you wrote the same thing. Well, I bring good news and some bad news.

First, the bad news... drum-rolls you'll keep experiencing this regardless of your level of experience. Now the good news, is you're not alone.

Everyone makes mistakes, to err is human. Errors are simply messages from the interpreter or compiler telling you that you did something wrong.

When I first started programming, I've always had an interest in trading the forex, stocks, and crypto market by creating bots (Check out my article on that if you're interested too) so I took this awesome course on MQL4 on Udemy.

So there I was, about to take that first step, Started the MQL4 course, and downloaded and installed the MQL5 IDE. After watching and typing exactly what he typed. I hit the "compile" button.

ERRORS!!!
Ha! There I was (probably with tears in my eyes) with about 30 errors. I was so confused. What did I do wrong? Turns out MQL4 was getting deprecated and the Metaquotes platform wasn't supporting it anymore so I was trying to execute MQL4 code with an MQL5 compiler. Just wonderful.

I had no idea what to do. I searched some of the errors on google only to get more confused. I simply shut down my laptop and went to bed. I asked around and friends said I should take it slowly so I decided to start with python.

I started trying out new things, read books, and watched a ton of tutorials. Stumbled upon a lot more errors but my good buddies Google and StackOverflow always had my back.

Eventually, I decided to try out MQL5 once again, I wrote a script and errors popped up but I already got experience from python on how to read error messages. It took a couple of weeks, but I was finally able to fix those syntax errors on my moving average script. Yay.

Time to run the compiled code. Guess what? There wasn't any output... There were logical errors hidden in the code. Logical errors are a lot scarier than syntax errors. Why? They don't get picked up by the compiler or interpreter.

So I had to read what I just wrote (and copied from the internet)... Turns out reading code is a lot harder than writing code. More googling... More StackOverflow-ing... Long story short. I got my simple moving average script to work.

But I noticed I was far better at coding than I was months back. I could easily tell that I missed a semicolon or didn't close a bracket. It got easier. I still make mistakes to this day, even while writing this article, I probably made mistakes too. (Last time I checked I was human).

Types of Errors

  1. Syntax Errors: Syntax errors are mistakes in the source code, such as spelling and punctuation errors, incorrect labels, and so on, which cause an error message to be generated by the compiler. Trying to console.log in rust or missing a semicolon in c++ or not indenting properly in python, are just a number of the numerous syntax errors out there.

  2. Logical Errors: A logical error is a mistake in reasoning by the programmer, but it is not a mistake in the programming language. A loop always evaluating to true is an example.

  3. Execution Errors: An execution error occurs when a program is asked to do something that it cannot, resulting in a 'crash'. The widely used example of a run time error is asking a program to divide by 0.

Tips for Handling Errors

  1. Google is your best friend: The difference between a noob-dev and a pro-dev is that the pro-developer knows what to search for on google.

  2. Write readable code: Save future you the stress of trying to understand what past-you wrote. Comment properly, use meaningful variable names meaning don't use x as an identifier when you're storing a score in that variable.

  3. Use a simple IDE: No offense to Vi (I use it too) but when starting, use beginner-friendly IDEs with IntelliSense like Vs-code. Don't use vi until you already know how to quit the editor.

  4. Read the docs: Documentations may seem boring to read but they're the best way to know what a function does or what a variable is for. As a developer, you have to be a reader.

Errors are annoying, we can all agree on that. Trying to fix one error sometimes leads to 3 brand new errors. But still, these errors make us into the awesome developers we are.

Some might consider them a friend, some might consider them a foe but I Samuel Simon being of sound mind, willfully and voluntarily make this declaration that I consider them a foe.
😄😄

Thanks for reading to the end. Feel free to say your thoughts and opinions in the comments. Constructive criticism is always appreciated. Have a great day.

Top comments (0)