1) One function that does everything. Many think that they should only create functions if they are reused. No. Create functions for anything that can be thought of as a generic action. This greatly helps in readability and structure.
-
Näytä tämä ketju
-
2) No early exits int foo() { if(x) { // lots of code ... return y; } return 0; } Reverse that statement. Now the reader a lot to go through to make sure the "bad" exit case is ok If it's reversed, everything below the if does not matter for the "bad" case
14 vastausta 13 uudelleentwiittausta 174 tykkäystäNäytä tämä ketju -
3) Magic numbers everywhere. if (something > 5) ... What is this 5? Give it a name and put it somewhere. I see this so often, this number has context, show it.
3 vastausta 23 uudelleentwiittausta 213 tykkäystäNäytä tämä ketju -
4) One class for everything. Similar to one function for everything. If you can categorize the actions within the class, then you can make classes out of those categories. Not great to maintain a 6000 line class.
1 vastaus 11 uudelleentwiittausta 121 tykkäystäNäytä tämä ketju -
5) Inconsistent formatting style. Reading through code is a strain mentally, not only do you have to parse what each line is doing, you need to parse the structure. If it's inconsistent it makes it harder to parse. What style doesn't matter, just make it the same everywhere.
4 vastausta 15 uudelleentwiittausta 143 tykkäystäNäytä tämä ketju -
6) Comments everywhere. // Increment value by one i++; My issue with comments is that now you have 2 meanings for everything. The line has a meaning and the comment. And they must match, or else there is trouble. (continued)
7 vastausta 10 uudelleentwiittausta 118 tykkäystäNäytä tämä ketju -
6b) Add a comment when something needs explaining, when reading the code by itself would not make sense. But you can also just make a function that describes that action if it's complex enough, no comments needed then.
5 vastausta 12 uudelleentwiittausta 124 tykkäystäNäytä tämä ketju -
7) Performing complex actions in if statements if (myFoo->Action(aBar + aBaz->GetStuff(18))) The only time you should be placing direct actions in if statements is if you want to block the execution with an && Otherwise put that into a variable and then ask the question.
4 vastausta 12 uudelleentwiittausta 131 tykkäystäNäytä tämä ketju -
8) Stringly typed if (a == "foo") {...} else if(a == "bar") {...} Unless you are doing actual string data parsing, you should be using classes, enums or at least numbers for determining what is what.
8 vastausta 11 uudelleentwiittausta 112 tykkäystäNäytä tämä ketju -
That is what I have found so far. At least the most common things. I see most the above things in every single review. If you have any you want to add yourself, please do! :D <3 Learn something every day!
15 vastausta 8 uudelleentwiittausta 182 tykkäystäNäytä tämä ketju
Not to toot my own horn, but I'm kind of proud that I do none of these things, and make sure to fix them when I encounter them at my day job!
-
-
Vastauksena käyttäjälle @TheMogMiner
No tooting taken. Knowing you have done steps to better yourself is so great. It's a sign that you are taking learning more seriously!
0 vastausta 0 uudelleentwiittausta 0 tykkäystäKiitos. Käytämme tätä aikajanasi parantamiseen. KumoaKumoa
-
Lataaminen näyttää kestävän hetken.
Twitter saattaa olla ruuhkautunut tai ongelma on muuten hetkellinen. Yritä uudelleen tai käy Twitterin tilasivulla saadaksesi lisätietoja.