📜 ⬆️ ⬇️

How to prevent a programmer from writing bad code

image
Once, in one stupid article, one stupid habrayuser told one stupid idea . Its essence was that in his company a system was set up that controls the code written by programmers at the time of trying to add it to the repository and rejects code that does not pass by some criteria. I liked the idea. I (and 3 others) asked the author to develop a thought and write an article about it, but it never appeared. And I decided to figure it out myself.

Preamble


In the beginning I will explain why this idea captured me so much. With all the simplicity, it gives a whole bunch of advantages:


Implementation


I already thought that I would have to fence my bike. Nothing like this. Everything has been stolen before us.
Meet SVNStyleCop

Pros : installation in 5 minutes, stable operation, configuration flexibility.
Minuses : only Windows and only C # (Perhaps there are solutions for other languages ​​and platforms, but since Windows and C # are my version, I did not dig further).
')
Installation

1. Download the archive and unpack it anywhere on the computer where you have installed the SVN server.
2. Edit the SVNStyleCop.exe.config file, setting the path to the svnlook.exe utility (it is located in the SVN-server folder).
3. Edit the file SVNStyleCop.exe.config, writing in it which files will be analyzed. I just wrote
< pathPatterns >
< clear />
< add value =".*\.cs$" />
</ pathPatterns >


4. Put the SVNSettings.StyleCop file previously created by the StyleCop utility (program known, I will not describe in detail) in the folder of the SVNStyleCop file based on the company’s code-writing agreements. If you have no such agreements - do not admit it to anyone. Be ashamed and repent! Sit down and do it. You can not - contact some clever people .
5. Set the hook to the pre-commit event. In the SVN server of the Visual SVN, this is done from the context menu of the repository by inserting the contents of the pre-commit.cmd file from the SVNStyleCop distribution into the “Pre commit hook” section (remember to write valid paths in this file!).
6. We do some kind of stupidity that violates the rules, we try to commit and see something like


Voila, it works!

findings


With this thing is objectively better than without it. Everything that I wrote at the beginning of the article can really help save time, nerves and get some better quality code. Of course, the system described here is not a panacea for all ills, and the code can still be:


The ideal is unattainable, but having a well-formed code that is guaranteed to meet at least some requirements and rules is better than simply relying on the consciousness of various irresponsible individuals in such a conscious matter as programming.

Source: https://habr.com/ru/post/111463/


All Articles