In my eyes, clean code is simple and easy to understand code. Not over-designed, with as few template files as possible and clear semantics. So, does this mean that the less code, the cleaner it is?
I don't think so. Most of the time, less code tends to be more semantically ambiguous and harder to understand (and therefore harder to maintain). When I was working and testing meta filtering with jBehave, I wrote code similar to the following:
Obviously, the method is shorter and the code is less. For us, using such a class may allow us to see at a glance what changes have taken place in this method while we work. But what if there is a new person joining the project, and this guy has never used jBehave before? For him, a longer code can actually get more information, even if he doesn't know how jBehave works, what a "meta filter" is, and what minus means - but at least he can understand what we want to achieve. When I tried to explain my opinion, other developers agreed with me but said that the same effect can be achieved by adding comments. Yes, I totally agree, adding comments definitely works. It's just a matter of style. I personally don't like comments, but in this case, maybe comments are a better choice because we can use them to explain the connection between the meta filter code and the jBehave layer file. So, the code becomes this:
Of course you can say that such a small example is not worth mentioning. However, I think the style of a project is very important. You can also find a common style by discussing specific examples. Maybe other developers will consider whether his code will confuse new colleagues and add comments instead of shortening the method to one line of code. in conclusion Clean code doesn't always mean less code. So, you need to weigh the trade-offs between writing more small methods and reducing the number of lines of code. I will discuss coding style in another post later. Which solution do you prefer and why? Please leave your comments. |
<<: Microsoft and Touch Technology invest heavily in Windows Game Contest
>>: Moore: Moore's Law will be valid for another 10 years
Let me share with you some of my practical commun...
Douyin is a very popular self-media video APP now...
This article was reviewed by Dr. Tao Ning, Associ...
In our city, subway lines that run day and night ...
In recent years, mobile Internet has developed ra...
Are you a good APP operator ? How many users does...
I have been in the Internet circle for 6 years an...
In most cases, people tend to think in a positive...
Chris Red Pill Awakening Member 3.0 New Content R...
Staying up late, working overtime, and being unde...
If marketing were a science, I'd rather be a ...
After much anticipation, Xunlei iOS version is fi...
Copywriting cannot create the desire to buy a pro...
Recently, OnePlus released this year's flagshi...
In recent years, the competitive and cooperative ...