Two years of work in magic capital

Source: Internet
Author: User

Transferred from a high school blog

Http://user.qzone.qq.com/853436204/blog/1345288142

The following is my opinion only. If you have any objection, you are welcome to make a picture.

 

It was said that I was too tired last night, and I couldn't afford to lie down after I got home from work. When I got up and looked at the time, I suddenly found that it was already in February. Suddenly, we found that another year has passed. If I have been working as an intern for one year, I have been a young man of 2B for two years. Although it cannot be called an old dog, it is a bit of sentiment. In the past two years, we have experienced many things: Technical, personnel, and affairs. A lot. If I want to say it all, I'm afraid I can't stop talking about it for a long time. So let's talk about the simplest thing-writing code. Code is simple and hard to say. From the university to the present .. Pop .. It can be said that the change is not just speed. Many times, I feel that writing good code is not enough. Because there are too many notes. For various reasons, it is impossible to take full care of them in many cases. However, I can say that the following standards have been met, so I believe that I have a say in these standards.

 

1. robust. The robustness here is different from the industry term "robustness": after all, I am not so good at writing so powerful code. I am talking about Robustness: When writing code, we need to find ways to avoid low-level mistakes that we can easily make. I believe that everyone has some bad habits when doing things, and these bad habits may evolve into future hidden dangers. Changing these bad habits is obviously not something that is easy to do in the short term, and sometimes it will never change. For example, many people like bia ji during their meals. My countermeasure is to come up with a strategy to minimize the harm of these bad habits and mark those areas that are prone to bad habits. For example, the value assignment symbol "="
And the comparison symbol "=", I believe that some of the peers are particularly prone to errors, especially in the condition judgment, do not pay attention to the comparison symbol written as a value. That's what I like myself. The corresponding policy is to write constants in the condition judgment. Of course, I believe many of my peers know this strategy. I don't mean to take this for granted. Instead, I just want to say that this strategy is really easy to accept: At least I still like to confuse these two symbols, but every time I make a mistake, the system will prompt an error (the cool who writes code with Vi can ignore it ). It is no pleasure to reduce or even eliminate the risks brought about by this bad habit while not letting yourself suffer. Of course, there are other strategies: strategies for dealing with invisible characters, such as dynamic binding of Uncertain rules. I will not go into details. In short, using new strategies to reduce the risks caused by bad habits, in order to increase the robustness of the Code, at least simple and pleasant. 2. Simple. How can we say that this is in conflict with my ideas during college: in college, I think about various sharp algorithms, various powerful designs, and various magical ways of writing. For example, the most classic question is: use the least code to show when the next day of a given date is. At that time, I was a kind of worships to those cool people who thought they were masters and should be able to look at them. Then I came to the company with these ideas in exchange for various scolds... Later, I gradually found out that in enterprise development, I found that the code is just as good as possible. Although there are some factors that meet the requirements-as few as possible, the algorithm is good, and the design is perfect. But these are all met at the end. That is to say, there are still many prerequisites. For example, one of the questions I often asked was: "The code you wrote one day on your own,
How long does it take to understand it ". This is a very practical but often overlooked problem. Of course, I will not repeat what the answer to this question is, because the benevolent sees benevolence, the wise sees wisdom, the late sees shortcuts, And the dummies see the pen. Another question is, "Why do you have to write this ". This is a tough question-it is easy to be asked. For example, many people like multi-process, multi-thread, or build many frameworks (this sentence may have some obvious meanings. It should be better to change the context: many people like to install n security software in their own computers, what is 360, Kabbah, QQ manager or whatever, whether it is necessary or not ). However, I believe that some people have never asked themselves why when doing so. Someone may ask yourself, and comfort yourself with the result "so convenient" or "so steadfast. The result of this operation may be a security risk or nothing. Of course, as a fellow, I wish these people all met the latter. However, I think this is at least not a good habit of universality. After all, in practice, developers often face many resource restrictions: hardware performance (I believe this limit should be better now), cost restrictions, insufficient manpower, time constraints, maintenance difficulty, and so on. Under so many constraints, I think what developers should do is to select some among the many choices and then select the optimal solution among them. I believe that in whatever field, many of the best solutions are usually the simplest and most natural. Select to do this,
On the one hand, it can greatly reduce the simplicity of the code-for well-known solutions, anyone in the world can understand it as soon as they read it; on the other hand, it can greatly reduce your design time-at least you don't have to think about it yourself. There are also few risks, saving time. Of course, those who are engaged in performance optimization should detour. After all, I am not so sharp. These ideas are not suitable for you (not ironic ). Of course, all of the above are big aspects. After all, the framework or solution problems will only occur during global design. When it comes to coding, the word "easy" means: natural. That is to say: natural, is the best. For example, many people like to write multiple variable resets like this: a = B = c = d... f = 0; of course, this is not a problem, and it seems that the code is very small. However, we do not know that such a statement has at least one implicit meaning in it: these variables are equal. Of course, this sentence is nonsense: everyone is 0, of course, equal. However, our original goal was to reset these variables. Now, the first impression is that you make them equal, and then others finally see 0,
They both reach 0, and the reader concludes that they are all equal and equal to 0. Then, the reader concludes that they are all reset. Of course, this inference process is correct and does not take much time. But in this case, isn't it a bit overwhelming or even wrong? We will do what the purpose is. I believe this principle should not be wrong. Therefore, the above is written as "a = 0, B = 0, c = 0 .... f = 0 ": So much clarity-at least let the reader know at first glance: Oh, you are making these variables reset. Of course, it is very likely that the underlying optimization is implemented. The final Running code of the above two methods is the same, and the running results are certainly the same, but it clearly makes readers feel different-the code is not only to be run, but also to be maintained.
In short, simplicity is beauty. 3. concise. It seems that the code is simple and often bloated, which is in conflict with this point of view. In fact, the result of simple bloated is the result of our selection. You don't have to worry about it-fish and bear's paw. What I'm talking about is concise in other aspects. I believe that many of my peers are engaged in maintaining others' code. I also believe that many people do not know how many greetings and how many times the code author's family members have received when reading others' code. One of the common reasons is that the Code is like the old lady's cloth-smelly and long. I would like to ask: Have we considered this issue when writing our own code? For example, I liked CTRL when writing code.
C + ctrl V, or a function is like a piece of cake. I don't know what my colleagues think. At least I regret doing so now: the reader is a real fool, even if it is reading the code written by myself. Therefore, in my opinion, you should consider some concise rules when writing code: for example, do not appear twice for the same code segment, for example, do not call functions in a file more than two layers (I am talking about a file, cross-file call should be bypassed). For example, A function should not be displayed on more than one screen (if you say you have to stand up the long screen), for example... There are many similar experiences, even if it is not mission impossible,
And remember the Alamo. In this regard, the simple method is to always tell yourself to be concise when writing code. In the long run, you will come up with many experiences by yourself. I believe these experiences are reasonable and effective (at least I have tried them ). Of course, if one day you think it is good enough to search for relevant experience on the internet, I believe you will find that you already have a lot of experience. Just try and prove it! At last, I felt like: If you want to write good code, or even just qualified code, you must pay attention to a lot of things. The above three points are only part of my own experience. Due to the time limit (coming off work soon), I am too lazy to go into details, right when throwing bricks.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.