Well, sometimes our code sucks. We may end up spending much more time coding and getting rejected much more times on our submissions. During your debugging, your bugs seem to appear ceaselessly and you code starts to become messed up. Finally, when you see the lovely "Accepted" verdict, you find your code filled with patches and temporary variables, and you never wanna read it anymore. This is what I've been doing over and over again, especially when my code is lengthy and complicated. And I guess some of you may have similar experiences. So, what is the reason behind it?
First, I suck at naming my variables. I don't like lengthy names like "SumOfAllPrimeNumbers" or meaningless names along the lines of "a1", "a2", "a3". When the variable is related to a value, I name it "val". When related to, say, the set of all prime numbers, it is named "all". If I can't find a way to name it, "tmp" will already be the thing I'd turn to. Obviously, the awkward thing is that I often end up having two variables with the same name. Consequent names will be like "val1", "all1", "tmp1", which are ridiculous. Therefore, I tried using names like "foo", "bar" to make my code great again, but to no much avail. Also, when I change the name of a variable in my code, like changing "all" to "All", I always have the temptation to use "all" instead of "All", which eventually makes the situation worse.
Second, I am always confused at whether I should replace some codes with a new function. Well, an obvious method is when two parts are similar, replace them with one function. However, awkwardness comes when two parts are partly similar. For example, in one part we calculate the sum of all numbers, while in the other part will calculate both the sum and the product of all numbers. If we replace them with one function, we end up either not calculating the product or calculating it when it is not required. Also, if we need to add some new codes to somewhere which you have already replaced the codes with a function, we'll have a hard row to hoe. Besides, expressions like "", "" are annoying, and I always hesitate at whether I should replace them with a new constant.
So, have you ever encountered any similar predicaments? What's your solution to them? Also, can you list more kinds of awkwardness in coding? Be free to leave comments down below.