In my last post , I described how clean codes helped me to become a better programmer. In just about two years I have adopted some system which makes writing code much easier and better. Although, I am not a Hokage like my boss but at least I am on the road to becoming a good Shinobi. Although that path is long and winding and full of challenges but mastering the techniques of clean code bit by bit will help me overcome them. But a good ninja also requires a good set of blades. As a programmer, when I started out I had no tools. I was writing code in notepad or even in console using nano in linux. This made me feel like a hacker though. With a black screen, a hoodie and sitting in the corner of the server room (had no clue what I was doing). But little did I know about good editors and plugins which would have saved me a lot of time in debugging and help structure my program so that I was not lost going through a hundred of lines of code.
Here in Delta Engine we mainly use Visual Studio as our main editor. The code base is mainly c# with a little of C++, python and cuda code. The editor can be customized to your need with themes, fonts and size. One could use color code to separate the classes, methods, properties and interfaces. This is visually very appealing and also helps to navigate through the code easily. Even while writing this helps a lot to know what is being used where. The intelliSense of the editor is very helpful but a much better intellisense is provided by resharper. Resharper and Ncrunch are two of the few extensions for Visual Studio that one has to use in the company.
Resharper makes code structure and formatting much simpler and easier. It suggests if there are parts which can be removed or parts which can be made a linq expression. It also suggests renaming, variable names, if you are violating any of the code rules which are applied. All this with just two keystrokes alt+enter. This however can lead to some not so fun situation. I was so used to this feature that one time I just pressed alt+enter and made a class sealed just cause resharper suggested it. Next day all the code which the other guys were working on broke. Thanks to mercurial however this was an easy fix. More about mercurial and version control some other day. Finally, the key feature from Resharper which I personally like is the auto formatting with just three keystrokes Ctrl+E+F you can clean the whole file format. All the unnecessary using at the top are removed, one line methods are made into lambda expressions, unnecessary brackets and braces are removed. One other feature of resharper worth noting is that if you have some class, methods, variable, properties or fields which you declared but never used you will get a warning or error based on your severity setting. This helps to keep the code base concise and helps prevents code rot.
For executing tests in real time we have nCrunch. It save a lot of time as it monitors each line of the code as you type. If there is no test associated with that line of code it will be white. P.S never write code without a failing test as my mentor and boss would put it. This alone gives an indication if that line is even required. With a failing test, without even debugging one can follow the red dots on the side to reach the point where it is failing and can fix it if it is an obvious fix. While the green dots on the side gives you the satisfaction of a passing test. The execution time of the tests can be also seen in these dots. This can also help optimize the code when needed.
However, to run both resharper and ncrunch together one has to have a good setup with fast CPU having above four cores. Also, the Ram can be a problem sometimes if you are working with multiple visual studios with both ncrunch and Resharper enabled.
This was just a short intro to the tools used in C# here in Delta Engine. Thanks to this I have also set up editors such as Charm which is similar to resharper in case of intellisense and exploring tools like PyCrunch for python unit testing. These are the few tools which we use here daily there is also Ndepend which checks for advance violation in the code base like cyclic dependencies, SOLID principles, dead codes and many more. Code duplicate checker in Team City. What is Team City? We will discuss it with version control. Cause a Shinobi never works alone!