Friday, January 6, 2017

ns-3's check-style.py, A Boon

ns-3's check-style.py, A Boon 

At least for me


In the initial years of my college, I was known for my bad codes. By bad I don't mean that they were wrong or inefficient, but by bad I mean they looked really bad. You can just say I was really a miser when it came to spaces. In India, where the presentation of assignment sometimes makes up for nearly half of the evaluation, I was really losing out.

It was the winter of 2015, when my life changed (*dramatic music*). I had completed my first ever module for ns-3, the DHCP module, and had sent it out for reviews. As expected, the very first review pointed out that the module was no where close to the coding standards of ns-3 contributions 😟. But this one also came with a silver lining, alongside the problem, the reviewer had also mentioned the solution. To check and rectify badly indented contributed codes, ns-3 community has made a solution of its own. In the utils of ns-3 lies check-style.py. This small python script is capable of finding out indentation faults in C like language and can also be used to correct it. The way to use it for has been explained in the official documentation.

The best thing about this script is that its effectiveness is not limited to ns-3. Since, the time I have been introduced to it, I have used this on all my codes. The trick is very simple and apparent. Copy this script to your assignment folder, and follow the same instruction as ns-3 documentation:

./<path to check-style.py> --level=3 --in-place -f <path of file you want to correct>

PS: This was the very first code of ns-3 to which I contributed to.

Pre-requisite - Uncrustify

No comments:

Post a Comment