Pseudo-scientific definition of good code and pseudo-scientific definition of code
Master haomeng is devoted to his contribution and respects the author's Labor achievements. Do not repost them.
If the article is helpful to you, you are welcome to donate to the author, support haomeng master, the amount of donation is free, focusing on your mind ^_^
I want to donate: Click to donate
Cocos2d-X source code download: point I send
Game official download: http://dwz.cn/RwTjl
Game video preview: http://dwz.cn/RzHHd
Game Development blog: http://dwz.cn/RzJzI
Game source code transfer: http://dwz.cn/Nret1
How do you define the code? This article draws a pseudo-scientific answer by consulting 65 developers with the same question.
First, we believe that writing code is very important. Why? First, good code is more interesting and cost-effective than poor code. Second, if the code is good, it means that the product you are building may be better. Third, it is also very critical to write good code: after all, our job is to write code.
Method
Since these 65 developers are candidates for one of our positions, this means that most of these sample developers prefer to use Java or Scala skills and generally have 5 years of experience.
Unified question: "How to write the code? How do you define the code ?" In addition, during the interview, the same person (face to face or by phone) will carry out the survey for about one year from January 1, January 2014 to January 1, January 2015.
After sorting out the answers to these questions, you can divide them into 31 different classes, each group has at least two similar answers. For example, the following answers are classified as readable ones:
Readable.
- Human Brain can read.
- Self-explanatory.
- People can understand it.
- It is easy to understand.
- You don't have to know about it in 5 minutes.
- You can also read and understand this document.
- Readable, and can be understood by new developers.
- It is as readable as text.
- Easy to read, straight-line thinking.
Result
The answers from the 65 developers totaled 288 different pieces of content, with an average of 4.43 pieces per person.
Of course, the most common answer at present is that the Code must be readable (78.46%), and developers who say that good code should be easy to read and understand.
Then it is testable/tested (29.23%), which indicates that good code should be automated (or at least possibly executed ). 25% of respondents believe that good code should also be simple-but complicated, of course, it should also be able to work, meaning that it can normally execute functions as we wish. The first five items are: the code should be maintainable (21.54% ).
The strange thing is that we found two things about the same topic: Documentation and code comments. Some developers think that the Code should be self-documented (it does not need to be explained in the document), while some developers say they should focus on annotations in the code to describe the purpose of the code.
Others, such as Scalable/reusable, and appropriate naming rules, the importance of code decoupling or small methods-of course, this "small" concept is different in the eyes of Different developers: "10-15 lines" to "<50 lines" are different.
Discussion
The answer in the interview gave us a lot of interesting quantitative data that can be used for analysis, and some data is worth mentioning. The following are the answers to the largest number of likes. Some of them give us a smile, and some give us some reasonable evidence that is worth pondering:
- The test won't crash.
- Do not create things that are not needed.
- Anyone needs to write comments. You will naturally know it later.
- It makes sense when you see it.
- You need to understand the business purpose.
- What you need to do is not just write code.
- It does not need to be too independent.
- Poor code can also do a lot of things, but it is not good.
It is not surprising that developers attach importance to code readability and comprehensibility. However, it is surprising that the rest of the answers differ by at least 50%!
The following four are surprising ones:
- Maintenance: most of us have had the experience of maintaining other people's code (or maintaining our own code after a period of time), and it is very likely that we have had a very miserable time. Therefore, we expect more developers to compile maintainable code. Some people may assume that the code is readable, so it must be easy to maintain, so this one is ignored.
- Work: the purpose of writing code is to provide value to others. Writing workable code is one of our top priorities. So we are surprised why not every developer's answer includes this one.
- Tested/tested: I will not talk about the importance of the test here. I believe you have heard it several hundred times.
- Efficiency: in other words, the answer includes "efficient" developers, which is twice more than the developer who emphasizes "cannot optimize too early". As we all know, "premature optimization is the source of all evil.
Finally, we have summarized the Code definition:
"Good code is readable, understandable, and covers automated testing, but it is complicated and can do what we need to do ."
It sounds pretty good, right?
Master haomeng is devoted to his contribution and respects the author's Labor achievements. Do not repost them.
If the article is helpful to you, you are welcome to donate to the author, support haomeng master, the amount of donation is free, focusing on your mind ^_^
I want to donate: Click to donate
Cocos2d-X source code download: point I send
Game official download: http://dwz.cn/RwTjl
Game video preview: http://dwz.cn/RzHHd
Game Development blog: http://dwz.cn/RzJzI
Game source code transfer: http://dwz.cn/Nret1