Reading code is a hard skill to inculcate. I just realized this just recently when I had to look at every sort of code be it C+ +, PHP, Java or Python. And I was really amazed how people around me were able to navigate such vast and diverse code bases. Did they really understand all these programming languages? Everyone around me was giving me code pointers as to where to look and where to change code.
And then a particular thing hit me. It’s not that they really understand much about a particular coding language, it is just that they had gotten better at debugging these languages by reading the test plans.
So, how does one really get better at reading code?
By debugging it . I mean really. I learned so much about PHP and C+ + just by debugging it. And now I am really writing pretty long C+ + Codes. Actually, No. I am copy pasting large C+ + codes for my use case and making the required changes. But the thing to note is that I am not blocked anymore. And now I can understand most of the code I read as well making me atleast 2X the ML engineer I was before.
So, here is my step by step guide to get better at reading code.
This is the first part. Most of the code you will ever see would be written in a modular way and would define some classes or functions which will be used somewhere else. I would ask you here keep it simple and just find a simple function and try to run in the codebase you are looking at. Most of the times you should be able to see it easily just by scanning for some keywords like function
, def
or params in some brackets.
This is the most involved part you will have and it would be better if someone could help you in this part who knows about the language or the platform. But the thing is you would need minimal help. You just need to ask two questions:
Answer to these questions can easily be found on the internet or on your companies internal resources too.
Find out how you can print variables. For Python, it is simply print
. For C++
its cout
, for PHP its echo
and printf
. Once you have that you can start by printing the variable at each step and see what happens. Better yet if the setup contains a debugger tool that can help you understand values of variables at each point.
This is use-case specific and here is where the most fun part starts. You write some logic to add your usecase to the existing code. You create some functions, delete some lines of code from existing codebase. Stack overflow and language manuals would be your friends here. Also you can check the source code of your own organization to understand how to do certain things with the language.
The final step once you change code is to get it reviewed, and put it in production. This is a great way to improve your coding skills as a person who understands this language would help you to follow coding standards and push you in the right direction.
If you want to learn more about Python , I would like to call out an excellent course on Learn Intermediate level Python from the University of Michigan. Do check it out.
I am going to be writing more beginner-friendly posts in the future too. Follow me up at Medium or Subscribe to my blog to be informed about them. As always, I welcome feedback and constructive criticism and can be reached on Twitter @mlwhiz .
Also, a small disclaimer — There might be some affiliate links in this post to relevant resources, as sharing knowledge is never a bad idea.
comments powered by Disqus