0
Which of the two you guys recommend for my code to be more convenient for those who will read my code in the future.
int grade = 75; if (grade < 75) { Console.WriteLine("Failed"); } or int grade = 75; const int fail = 75; if (grade < fail) { Console.WriteLine("Failed"); }
5 Respostas
+ 2
Second one is more reusable. First one is more readable and easy to understand.
I would pick the second one because reusability is more important.
+ 2
it depends. If you got a huge project and you do the 2nd for everything (if-else, for, while etc...) the code will became really huge and probably will be a mess with so many variables. But if do the 1st always and later want to change something you maybe need to edit a lot lines of code that takes time and maybe forgot to change something.
So choose wisely.
+ 2
The second code is better because the reader will not be wondering what the magic number 75 is.
+ 1
In the first code , if you want to change the value of fail variable you must get inside if statement and change it. This sounds easy but in programming its not a good tactic to change variables into statements. Variables must be declared outside of statements in order to change them easily.
0
What do you mean by reusable?