Book notes in code Daquan

Source: Internet
Author: User
Tags i18n
  • P7
    Focusing on building activities can greatly improve the productivity of programmers.
    I have a deep understanding of this in a recent project. It took us a long time to design. As a result, much of the next work was done in a pleasant mood. I think
    P28
    The example of the food chain is more convincing,In a healthy ecological environment, the Seagate eats fresh salmon, the salmon eats fresh qingyu, And the qingfish eats fresh water bugs. This is a healthy food chain.
    If the environment is polluted and the Water Bug is swimming in the polluted waters, the last part of the seagull and the food chain will not only eat the garbage from unhealthy salmon, but also the qingyu, the pollutants in the system.In software development, architects eat demand, designers eat architecture, programmers, and the last part of the software food chain to digest design.If we are contaminated from the beginning, we should not expect the programmer to be happy. The whole software will be radioactive and the whole body is defective, which will definitely lead to bad temper and nutritional disorder for programmers. In our small team, one person is assigned a number of roles, causing more damage. Therefore, the project was determined at the beginning whether it was successful.

  • P7
    Source code-the only accurate description of the software
    In fact, we don't have to be frustrated by the absence of accurate documents, do we?

  • P13Common Software metaphor
    Good metaphor allows us to think about more problems and embark on the correct path. We are in
    Writing code, growing a system or system accretion
    Or building software?
    There are different ways to do different software.

  • P24
    Avoid using the wrong method to make the right product
    We often emphasize testing in software development. Indeed, testing ensures quality. However, the test only ensures the Code with quality, but does not guarantee the design with quality.

  • P42Required Checklist
    In fact, we don't have to write a requirement analysis book or something based on our xuanke. Even in the brain and verbal communication, there is such a process. Dropping text is good, but not important. The key is not to do it.Yes
    No defines in detail all input of the system, including the source, precision, value range, and frequency of occurrence. Are all system outputs defined in detail, including purpose, precision, value range, occurrence frequency, and format? Defined?
    Minimum machine memory and remaining disk space? Is the system maintainability defined in detail, including changes to adapt to specific functions, changes to the operating environment, and changes to interfaces with other software?

    There are far more columns in the book than I listed here, so it is worth reading. Setting these settings is very important. I think reasonable game development involves a relatively stable planning scheme and completed art resources. Large
    Some changes are made in the next version. Planning and art will always work for the next version, and the program can be designed based on relatively stable requirements. In this way, even if the first version is not playable, it can also be discarded.
    Make the game a final success.

  • P46Data design
    I was confused about what to write in the project documentation? Some of the items listed here solve some of my doubts. If you choose to use an ordered access list to represent a group of data, it should explain why sequential access is better than random access. (Random access is often more efficient)During the building, this information allows you to gain insight into the ideas of architects. This insight is invaluable in the maintenance phase.
    Another more interesting example of P58 is that Beth wants to be a husband, Adbul.
    The original stew. Adbul
    Said, first sprinkle with pepper and salt, then go to the head to go to the end, and finally put it in the pot to cover the stew. Beth
    Then I asked, "Why should we start and end ?" Abdul
    I don't know. I keep doing this. I want to ask my mom. He called home and asked his mother if she had no idea. She had been doing this all the time and asked her questions. My mother made a call to her grandmother. Grandma replied, "I don't know why you have to go to the end. I did this because my pot is too small to fit.": d
    The architecture should describe the motives of all major decisions.

  • P48Internationalization and Localization
    I18n is often referred to as internationalization.
    The word is too long. There are 18 letters between I and N.
    Similarly, localization is usually abbreviated as l10n.
    . This job must be well planned during the framework period. We do not need it in the end.
    I18n or support l10n is enough, in the end with UTF-16 or UTF-8
    Or ASCII
    String. Whether to embed strings in the code, encapsulate them into a class, or put a configuration file. Our current project was finally taken into consideration, and later we spent a lot of energy restructuring. Fortunately, no problems are found.
    It's too late. Otherwise, the cost will be higher. We should solve the problem as early as possible. Don't be afraid to make wrong decisions. what's even more terrible is that after we realize the error, we are afraid that the cost of correcting the error is too high.
    A drag. Code bugfix
    We all know that we should do it right away, but design mistakes are easy to let go and we will continue to do it.

  • P51Over-engineering
    It is not easy to grasp this problem. On the one hand, we want the system to be robust. If the components of the system only meet the Robustness Requirements to the minimum, the overall requirement is usually not met.Software Robustness does not depend on the weakest link, but is equal to the product of all weak links.The architecture should point out that programmers prefer over-engineering to be cautious, or simply do something that can work. Some things should not be too energetic, and we have also made this mistake. In particular, some parts that will probably need to be reconstructed from the very beginning will be wasted.

  • P62Select Programming Language
    I once thought that C ++ is omnipotent.
    There are also programmers. However, it is undeniable that the expressiveness of each language is different. The book has a table on this page. If
    If the expression capability of C is 1, C ++ and Java are 2.5. Perl
    But there are 6
    . This is one of the reasons we chose to write logic scripts for the game. In addition, the degree of familiarity with the language has a great impact on the efficiency of programmers. Therefore, we cannot independently view the expression ability of the language itself. P63
    For example, programmers with a group of FORTRAN backgrounds use C ++
    Write a new system, and the result is written in a disguised form of C ++
    . They distort C ++ to simulate FORTRAN.
    And ignore the C ++
    Rich object-oriented capabilities. Here we have a ready-made example:
    C ++ programmers use C ++/C to write Lua
    The results can be imagined. Now I am still telling him to understand it.
    Lua. Lua
    Not C.

  • P68Programming into a language
    Note: Here is into instead of in. The book uses a VB
    As shown in the following example. Now we use C ++
    Build a system, C ++
    There is a very troublesome thing, that is, the survival of a single piece. One
    Singleton
    I believe there are a lot of questions about when to create and whether to analyze the structure.
    C ++
    Programmers have a headache when building a large system. As far as I know, my colleagues from other projects in our company still have a headache. This time, I made an agreement to prohibit code of any module from constructing static objects. That is to say
    The object construction process and main
    The automatic destructor after the function is disabled. Then we have a complete set of single-piece management methods for use. This problem has been well solved. We have never worried about the problem when a single piece is constructed or why it is analyzed in advance.

  • P78Importance of management complexity
    We are doing software to combat the complexity of the problem. Three problems need to be noted: solving simple problems with complicated methods; solving complicated problems with simple but wrong methods; and solving complicated problems with inappropriate and complex methods.

  • P80High fan-in and high fan-out
    High Cohesion and low coupling are easily valued. However, high fan in and low fan out are sometimes ignored. We should try to use a large number of classes at a low level as much as possible.
    Fan-in)
    Each class should use as few other classes as possible (under 7 ).

  • P83Minimize connections between subsystems
    The examples in the book are very relevant. A general rule is that if
    If the system uses B and C, then C will not use
    . The system layer design diagram should be a non-circular diagram.

  • P91
    Encapsulation not only allows you to see complex concepts in simplified models, but also does not allow you to see details of complex concepts.
    The importance of hiding information is unquestionable. So we are not only using
    C ++ private
    Hide information. The interface method is also used, so no design details are exposed in the header file. In addition, Any programmer who does not meet the current situation will not be satisfied with his previous code. However, reusing old and unsatisfied code is not a bad thing. What we need to do is to hide old things when reusing them.

  • P99Expected changes to varying degrees
    Good Designers should be sensitive to future changes. I have learned this step by step. Before making a decision, think about the consequences of making a mistake. It is important to estimate the cost of future changes to make appropriate designs. It is inappropriate for the system to be over-designed to adapt to every change. A good feeling is needed to design it.

  • P101Coupling type
    Loose coupling is what every system designer pursues. However, the standards are often inaccurate. A simple example is not necessarily appropriate. In my earliest design, the system encapsulated the coordinates into a file called
    Point. In the future, all parameters will be transmitted to point *, instead of X, Y.
    . This makes sense. However, this does increase coupling. Because every class needs to know
    Point
    . In many cases, it is more appropriate to PASS Parameters Using simple types. (Pass to the end
    Point * or X, Y still depends on the actual amount)
    Too many parameters will also increase coupling. From this perspective, X, Y
    Is two parameters, point *
    Is a parameter. There is no absolutely unique criterion for the degree of coupling. The description and summary in the book are worth reading.

  • P103View common design patterns
    The greatest benefit of designing patterns for programmers is the increased convenience of communication. The depth of a person's thinking depends on the vocabulary of the language he uses for thinking. Design Patterns can also be introduced to programmers
    . In fact, even if you haven't read the design patterns book, as long as you are an experienced programmer, most of these estimates have been taken into consideration. However, give a name to the design pattern,
    It can accelerate communications between partners. However, you must be aware of a trap, that is, pattern. It is dangerous to force code to use a certain mode.

  • P106Avoid mistakes
    Failure experience is more important than success experience. Today, online game development is particularly preferred. Our game is successful because we have learned lessons and are careful when it fails. Our Code may not be of much higher quality, but what many colleagues in the industry have done has learned from others' successful experiences but failed because they lack the lessons learned from failure.

  • P111
    Top-down and bottom-up design methods
    Many people agree with the top-down design method to gradually break down the problem and conquer it separately. I like the design method below. First, we have done the absolutely necessary modules, and then we will consider how to build them. However
    In practice, we often do it from the bottom up and think from the top down. Here is a very incisive summary of the advantages and disadvantages of the two methods. I particularly agree with the final conclusion,These two methods are not mutually exclusive-you will benefit from mutual collaboration between them.

  • P114
    Developers do not regard prototype code as code that can be discarded.
    This problem is very serious. I have seen it many times. Prototype is really a good method, but you must understand that some code is written to discard it later.

  • P118Use a digital camera
    The design document does not have to be written in detail as a standard document. What is important is that we have designed and kept it, rather than writing beautiful documents (invest money ?) Digital cameras seem to be a good thing, so you can put the draft
    The graffiti on the paper is retained. I always think that pencil is the best partner of designers. Even though there is an electronic whiteboard, expensive items are not required by all developers.

  • P131Do not make ADT dependent on storage media
    This has long been realized. It is better not to have readfromfile in the class.
    , Writetofile
    This method. However, these methods are often added for convenience. The final result is that dependency files always cause more inconvenience than convenience. Likewise, the dependency file name is inappropriate. Sadly, some mistakes are often not enough. It is easy to realize that this is not good. It is another thing to put an end to it.

  • P143Private
    Inheritance to implement the "has a" relationship

    Private
    The main reason for inheritance is that the outer class can access the inner class
    Protected member. Based on my own experience, let the class have protected
    Members are not a good thing. I just learned C ++
    Many classes have a large number of protected
    But now, only private and public are left. Even though
    Protected
    But I believe that those can be removed through improved design. I don't like dogmas. If there are dogmas, they won't be used.
    Protected, I will dislike it. But in terms of implementation, my feelings will be rejected.
    Use of protected.

  • P174For more than 200
    For a line-of-code subroutine, no research has found that it is more cost-effective and/or error-rate-effective.

    This is what everyone knows, but I have made mistakes myself. A few years ago, I wrote a text-and-text mixed-line function for the westward journey. Different texts can be displayed simultaneously in chats or other screen texts.
    Color, status, effect, and animation Icons can also be displayed. At that time, there were some reasons for the efficiency. I wrote a function of hundreds of rows. In the next few years, I have had a headache for this function many times.
    Only three bugs
    . It wasn't until these modules were completely rewritten in the fantasy westward journey project. I have seen thousands of sub-programs in some places, which is terrible. Not all programmers can really realize this
    How terrible is this.

  • P176Use const in C ++
    Keyword to define input parameters

    Correct and full use of const is a qualified C ++
    One of the criteria for judging programmers.

  • P176
    Do not use the parameters of subprograms as working variables.
    Do not use input parameters as work variables because of efficiency. The compiler will help you optimize them. If this is done, at least within our company
    Codeview is to be severely warned.

  • P210
    Make sure that the error messages remain in the Code are friendly.
    When I read this section, I think of a story that my colleague told me: his former colleague was fired out of swearing because of his boss (a programmer) the error message of a module is scolded during code debugging.

  • P220
    Create a subroutine through the pseudo-code programming process
    Not all codes must have pseudocode before they are written. In older programming methods, a frame chart is required before programming. I have also learned this method, but I never feel natural. If the pseudocode has a box
    Box, maybe I will not use it. However, I still use this method most when implementing complex algorithms. An additional benefit is that you have comments first and then deleted unnecessary ones. Instead of adding code first.
    Annotations.

  • P238Data cognition Test
    Haha, I got 28 points (or 27.5)
    And is not framed by the author's trap.

  • P240
    Implicit variable Declaration is one of the most dangerous features for any language.
    In our early years, we used Lua's 4th
    The version of the script was written, and the results suffered from this problem several times. Good news
    Lua added resumable after version 5th.
    There is a way to avoid this problem. Define
    _ Newindex's method. Test in the Lua package
    Directory, which can be found in Pil.

  • P2440 xdeadbeef is recommended for Rob Pike
    This constant fills the memory, because it is easy to recognize in the debugger.

    In fact, it is interesting to use 0xbadf00d. Unfortunately, it is 7.
    Letters. A friend used this as the net name and I had a meal. : D

  • P246
    Shorten variable survival time as much as possible
    This is a simple but practical principle. P248
    We should also avoid using global variables because they have the longest survival time. Using global variables and not using them is the difference between easy-to-write and easy-to-read code. It is also the "convenience" and "intellectual
    Rational concept. This section also describes the concept of quantization, the span of variables. Repeat a temporary variable to increase the survival time and span, so it has a bad taste. This
    I talked about it again in p255.

  • P253Binding time
    Generally, the later the variable is bound, the better the flexibility. The binding time here is a good summary. They are:

    • Bind when encoding (use magic number)
    • Bind during compilation (use named constants)
    • Binding when loading (reading the registry, configuration files, etc)
    • Bind an object during instantiation (read when creating an object)
    • Instant (read at each operation)

    The later the binding, the more flexibility, the more coupling.

  • P256Avoid giving the Code an implicit meaning
    Here is an example that I used to do the same thing, variable
    Pagecount
    When it is not negative, it indicates the number of printed paper. Otherwise,-1
    Indicates An error occurred. This should be avoided when it is called "hybrid coupling" in the technical field. Pagecount
    A boolean string
    Type. If you really want to save space for a variable, I think
    Union may be better.
    1. Union {
    2. Int pagecount;
    3. Struct {
    4. Unsigned int unused: 31;
    5. Unsigned int pageerror: 1;
    6. };
    7. };

Maybe this is not a better solution.

  • P298
    Determine internationalization/localization strategies as soon as possible during the life cycle of the program
    We have had a hard time explaining this question. In addition, MS
    Advocate _ T ()
    Macros are not necessarily an excellent solution. To support Unicode
    UTF-8 is a good choice, though not always the best. UTF-8
    When the number of Chinese characters exceeds 50%, consider the storage space.

  • P301The safer method is to use strlcpy () or
    Strcpy_s ()

    It is a pleasure to see that this sentence is listed in the comments. It can be seen that the translator has used his mind. Similar annotations, I have seen them in Hou Jie's translation. However
    The behavior of strlcpy and strncpy is different, strcpy
    It can often be simply replaced by strncpy, but strlcpy
    But it does not have this effect. However, I also tend to use strlcpy, which is the same
    Strcpy is as efficient and indeed safer. Strncpy
    An error occurs when the parameter is null.

  • P305Set Enum
    The first element of is left as an invalid value.

    This is the first skill this book has ever encountered before. I always define invalid values as the last one.
    Enum
    Value, or is defined as a very large special number. The reason here is very good, because some variables without proper initialization are often
    0. Using 0 as an invalid value makes it easier to catch errors.

  • P309Monty Python is in the 20th Century
    Classic English TV series, Python
    The language is named.

    It's interesting that I didn't know how the python name came from before.

  • P329Simplify complex pointer expressions
    When I go to school, I often write
    P-> q-> r-> S. Data
    This type of expression, after I work, is pitted several times by this expression,Use Extra pointer variables to improve code clarity(P327)
    It also became my creed. In addition, p329
    IntroductionDraw a pictureIs also frequently used.

  • P330
    Allocate a reserved memory Reserve Area
    The memory needed to ensure the emergency processing of program crashes is a concise method.

  • P364Abuse case language
    It is really bad habit to mix different control structures together. But sometimes it can bring a higher efficiency. We don't need it, but we can't understand it. This reminds me of an example he mentioned on the train when I went on a business trip with my colleague:
    1. Int n = (count + 3)/4;
    2. Switch (count % 4 ){
    3. Case 0: do {
    4. Dosomething0 ();
    5. Case 1:
    6. Dosomething1 ();
    7. Case 2:
    8. Dosomething2 ();
    9. Case 3:
    10. Dosomething3 ();
    11. }
    12. While (-- N> 0 );
    13. }

P374Do not use
For Loop

  • The truth has long been understood, but it is never followed
    I think it's still lazy.

  • P376Only one thing in one loop
    I also mentioned this in my book about performance. In fact, merging a few things in a loop may not necessarily achieve higher performance.

  • P377
    Avoid code that depends on the final value of the loop subscript
    It is still a long-known truth, but a mistake is made again.

  • Limit 4For loop variable scope
    The Semantics in VC is different from that defined in C ++. MS
    One solution is recommended:
#define for if (0); else for 
 

  • P397
    If programmers who work for me use recursion to calculate factorial, I would rather replace
    Well said. If my new colleague is in C
    The language uses recursive computation of the Fibonacci series. I guess I will also give some advice.

  • P399Make the Code not contain GOTO
    The goal is not the goal, but the result. The goal is focused on eliminating Goto.
    The above is useless.

    P408
    If the programmer knows that there is a replacement solution and is willing to use it
    Goto can be used.

  • P408
    The field of software development has developed to restrict the use of code by programmers.
    In this example, the number of rows or labels that can be used to call subprograms is an old one.
    Basic. But at that time, basic
    It is too simple. It is imperative to expect such a function. You need to expand it yourself when you cannot.
    Basic Interpreter.

  • P429
    Finally, find a good solution and avoid causing a disaster, instead of trying to find the best solution.
    I would like to add, if you know a better solution but cannot completely avoid a disaster, please comment out this better solution.

  • P442
    This suggestion (write the constant in the equal expression before to avoid putting
    = Incorrect =
    Is in conflict with the suggestions arranged by the number axis. I personally prefer to use the number axis sorting method to let the compiler tell me whether there are any assignment statements that I have no intention of writing.

    I also don't want to write constants in front, but I still don't know the reason.

  • About the remaining 400
    Page
    : Code Daquan is indeed a good book, although up to nine hundred pages, but there is no nonsense. Read notes only do this
    Cloud wind has even finished reading the last page of the book. The lack of the last half of the Reading Notes is not as good as the first half of the book. On the contrary, I think some of the chapters below will inspire me more. Only, after
    It took me half a month to read a half book. When I got up in the morning, I was too lazy to break down some text on the machine. For those who like this reading note, it is recommended to buy a book titled code Daquan nai
    Read all.

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.