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.
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.
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.