Architect Express 6.9-How to write good code

Source: Internet
Author: User

Read a lot of code, some people write more than 5 years of code, but the code is too bad to read directly to people. Someone wrote the code to make people read the feast for the eyes, why the gap between people so big?

It seems that how to write good code is a very worthwhile thing to say.

Key ideas:

  1. People write code that is intended for others to read, not to be executed by the machine. Writing code should be like writing a novel, making people read easily and happily.
    • During the lifetime of the software, the maintenance cycle accounts for more than 1, so don't look to avoid someone changing your code
    • If you change jobs, your code needs someone else to take over.
    • If your own code, 3 days later you can not understand
    • The bull's code always makes you want to put it down.
  2. Write code needs to pay attention to the level of consistency, not sesame and watermelon mixed together.
    • Stool, table, chair, molecule, bed, you think that's wrong.
    • Give another example of cooking:
      1. Wash vegetables
      2. Cut vegetables
      3. Pour oil stir fry
      4. The oil temperature slowly rises from 10 degrees to 60C, the gap between the oil molecules is getting bigger and the oil boiling up. There was a reaction between the oil molecule and the vegetable molecule.
      5. Out of the pot.
    • Each level is responsible for its own 7 sub-nodes below.
  3. Do not have too many comments, you note that you are afraid that others can not understand.
    • The more comments I take, the more serious I am, but one day the code changes and the comment hurts.
    • Only need to sketch into Doc's notes
    • Method names, arguments, and class names themselves are comments
  4. A team must have a consistent coding style, if someone can't unify, Maverick, then out.
    • I want to be free, I am the wind of the unruly, I will scrape away immediately
    • My cow, so I don't have to obey, sorry, really cow?
    • My previous company had no coding specifications, and that was silly of them.
  5. To have best practices, this can significantly improve code quality
    • Like effective Java.
    • such as "abc". Equals (XXX)

Have time to read refactoring, code encyclopedia, you will fall in love with coding, writing poetry general code.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Architect Express 6.9-How to write good code

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.