Hello all
Recently, I received a couple of pull request in GIT and I wanted to make things clear on what I accept and on what bug me that could make me reject the pull request or ask for modification.
First of all, I’m not there to refuse any new feature or improvement. But, be sure of one thing, your code will be inspected line per line and what I search for is
1. READABILITY
- This is the main criteria, Am I able to read it like I would read a book? Do I know you direct intention as soon as I look at your code. I’m really sensitive on the look and readability of the code. “ALWAYS CODE LIKE IF THE GUY THAT WILL MAINTAIN YOUR CODE IS A KILLER PSYCHOPATH” As an open source community, there will be other people that will look at your work. May be you will develop a cool feature and fade out and then, we will find a bug and won’t be able to debug it because the code is too hard to read and understand. So, please, look at how it is currently written and try to replicate.
1.1 Take the time to think to the code you will write.
- Most people, mostly noob, will just go on the computer and start to code, i’ve been like this and now, I know it’s a mistake. if you do a new cool feature, take the time to think of it, make it clear in your head, structure it, make it work in your head before to go on the keyboard.
1.2 Take time to name your variable correctly
- Variable name is really important, if you have trouble to name your variable, the step 1.1 have may not have been done correctly. If you pass 10 minutes searching for a variable name, the feature currently developed may not have been enough defined and think... There is still probably still some algorithm not defined. If you have trouble to define your algorithm, imagine the guy that will read this after you!
speak to me more thanCode:xRatePerSec = gyroXRawData * gyroScaleFactor;
I’m sure that I will figure out the seccond one, but, I will have to analyze all member to know exaclty what they are, but, I don’t have to do it if name are clearly named.Code:xRPS = gD + gS;
1.3 Respect indentation and bracing
- I know that we can write code really cryptic way, but, it’s not because it’s code that it have to be cryptic, it’s not because it’s “C” code that it have to be cryptic and mostly, it’s not because it’s microcontroller code that it have to be cryptic. Sometime, that can look like it because we use some register value... but in those case, we don’t have choice. Otherwise no cryptic code. Avoid
and worst when many one after the othersCode:if (a > b) c++; else d++;
Code:if (a > b) c++; else d++; if (g > h) i++; else j++;
So, first the name are bad, but, I have discussed that case. So, just indent it and put some brace will put some air in the code and make the it more readable and easy for the eye to pass through it.
I also indent precompile header so that I can read it like it is normal codeCode:if (a > b) { c++; } else { d++ }
Code:processThing(); #if defined (monDefine) readMyStuff(); #endif
1.4 I’m agaist comment
- My rules of thumb is simple, if I have to comment, it’s because my code is not easily readable. I’m not completely against it, but, for really complicated stuff, but, one thing's sure, most of the time, programmer comment their code because they were not able to make the code to document itself. This one is more a personal matter and can be discussed, but... I will push for it
Also, please note that most of the time, people that will look after what you have done, will probably catch more faster and see some improvement. Not because you are slow or something like this, but, because they will catch your intention more faster because it have been already defined by you. So, don’t be offended if I see a useless condition, way to simplify your algorithm but, that will do the same thing or if I see that you just change change thing but, that do nothing at all.
For all those point, I may ask you to rework a bit and update your commit range. Be sure we all have the same goal, the improvement of Aeroquad. So, i’m not there to refuse anything but to filter as much as I can. And it's your duty, as developers to fit the code style of the project. Like you would have to do if you were programming into a company!





Reply With Quote

Bookmarks