In my last article, I wrote that the journey for newbie programmers could be difficult. While starting, there are many things to struggle with because of lack of experience. In the previous article, I mentioned three tips that I would like to share with beginners and then I described the first one. Here, I will continue with the second tip.
Make use of your IDE
In case you didn’t come across the ‘IDE’ acronym yet, it stands for Integrated Development Environment. In simple words, it’s just an application helping you to write code faster and easier. There are many popular IDEs like Visual Studio Code, PyCharm, IntelliJ, RStudio, etc… As they all differ slightly in tools and graphical interface, there are some common denominators among them.
A debugger is a very useful tool providing you with some help when looking for bugs (errors) in your code and enables you to analyze a running algorithm step by step. Depending on IDEs and the programming language you use, there are many resources such as video tutorials on Youtube presenting how to handle debugging properly.
Let’s say we learn the fundamentals of Machine Learning (highly recommend this course: Machine Learning Course) using the GNU OCTAVE language. Our task is to write a vectorized code (operations that are performed on multiple components of a vector at the same time) of the cost function:
Vectorization converts a scalar operation-based program to a matrix operation-based one. Since matrix multiplication requires the operands to be compliant in terms of their dimensions, we can get errors when trying to multiply two nonconformant matrices.
In this situation, we can use a debugger to pause code execution in the problematic line, which will enable us to take a closer look at the variables and solve the problem. To stop in a particular place we need to add a breakpoint for that specific line.
On the picture below red dot indicates the line before which the program will be stopped.
After reaching the desired point we can freely inspect all variables and test different solutions before restarting the program.
Now we can make amends and restart our program to see that our problem has been staved off. Debugging is quite intuitive and similar for most of the IDEs and programming languages. Once you acquire this skill you should be able to handle any debugger. Anyway, there are some nuances worth being considered when coding in a particular language. For example, GNU OCTAVE (like MATLAB, R, Python, JavaScript, etc.) is an interpreted language, which means that their interpreter runs through a program line by line and executes each command immediately (in contrast to compiled languages, like C++, Java, C#). Consider the following example:
Executing these three statements in the command window produces an error due to a typo in a third statement. Notice that the 1st and 2nd statements have been executed successfully and already changed the values of the variables: ‘a’ and ‘b’. After re-executing all three statements we would apply the 1st and 2nd statements changes for the second time, so it’s crucial to re-write only the 3rd statement. For compiled languages no statement would be executed if at least one of them were incorrect, thus no data would be changed.
Conclusions
The truth is that IDEs provide you with many advanced tools and features, all of them posing great material for an article. The most popular ones are syntax highlighting, code autocompleting, and more… You can always search for the most popular ones and read about the details to make your work easier. Worth mentioning that there are also many useful keyboard shortcuts like in RStudio: Ctrl + Tab and Ctrl + Shift + Tab for indenting or indenting backward respectively. You can also jump to a function implementation, find all variable references or replace all text occurrences. Similarly, I endorse looking for the details on the Internet depending on used IDE and technology.
Author: Paweł Golik
A third-year student of Computer Science at the Warsaw University of Technology. During his studies he also worked as a Junior Programmer. His interests include Data Science and Software Engineering To find out more, visit his profile on LinkedIn.
Main photo by Tim Mossholder on Unsplash