Old code farmer how to write code that makes you satisfied

, a friend of mine asked me this question on micro-blog today:

@ old code agricultural plots, recently for the purpose of learning to write a management system, more and more feel behind, in front of the code is written. "Senior, I want to make the code a little better. Can you talk about your experience and give me directions?"

I’m back in just to write a few sentences, realized 140 words difficult to put my ideas clear, the spirit of the spirit you can fond of teaching others I decided to give my answer, write a blog.

The first thing

needs to say is that I’m writing this blog. It doesn’t mean I think my writing is so good. As a matter of fact, I am aware of my level. As a programmer for application systems, and those who do frame work as a system, they are not at one level. And even at the application level, my level is probably only two or three, just because I love programming, so I’ve been working hard, but anyway, I can be satisfied with the job I like. So I slightly tampered with the question to "feel in front of the code is written." the key, the friend asked "how to make the code written in a little better" to "how to write their own satisfaction code".

well, my own experience is to write code like writing, began writing before is the key. I remember when I was in high school, a Chinese teacher taught me the experience, at least 1/3 of the time spent to conceive, careless repeated thoughts, each paragraph, the main context, rhetoric, etc.. These elements are figured out, you can go to write.

I think writing code is the same. Thinking is the key. Assuming that the technology platform, framework, tools, and so on have been identified, then spend more than 1/3 of the development time to consider all the data structures and their relationships before starting to write. For example, you need to define several classes, what is the relationship between classes and classes, what attributes each class has, what kind of methods each class provides, and so on, which are the core. These data structures should be considered as thin as possible, such as functional implementation may be no problem, but the performance is not satisfactory, which shows that your data structure design needs to be improved. These details should be considered over and over again until they feel very attentive. On this basis, the details of the implementation, the test case, and the readability of the code should be written, and the code that satisfies you should be written. Details are as follows:

1. data structure and core algorithm

on the importance of data structure, the great God Linus Torvalds said, in this case, I feel very much agree with: "Bad programmers worry about the code. Good programmers worry about >"

Leave a Reply

Your email address will not be published.Required fields are marked *