People-oriented program design

Source: Internet
Author: User

 

To make software more user-friendly, we must replace people to do a lot of things. The more software does,ProgramThe design becomes more and more complex. As programs become increasingly complex, programer is obligated to make programs as simple as possible.

Of course, this simple is not simplifiedCodeReduce the amount, but use wisdom to make the code "complex but not messy.

Yes, it's an art!

Why is the code "complex and not messy" required "? This should start from the perspective of code usage.

Code, to put it bluntly, is a language in which people interact with computers. It uses two objects: computers and people.

The role of language is to transmit information, and the most fundamental principle of language is to facilitate understanding.

As a computer language, especially the popular advanced computer languages, can be read and understood by computers, and powerful development tools will tell you at any time. Whether these languages can be understood by living humans is what people do.

Some people firmly believe that the code is written to the computer and other problems are ignored. This is simple, but it is very dangerous. Because the Code does not only run on computers, but also plays an important role in reading the code. At least, you need to debug the code yourself ......

In fact, since the object-oriented language is available, it is very easy to implement complicated and non-chaotic code. It is not only easy, but also elegant.

Language is the same, and designers give it too many features of human language when designing a computer language. Therefore, to design an excellent program, we only need to understand what we usually say and express it directly in computer languages. This is definitely a great program.

How can we translate human languages into computer languages? Simply put, pay attention to the following two points:

    1. All nouns (pronouns) are translated into attributes.
    2. Translate all verbs into methods

Let's take a simple example and translate the phrase "I fuck your sister" in the most common words ". Simple four words, three titles (pronouns), one verb. Translated into a computer language:

 
Fuck (you. Girl) I. Fuck (you. Sister)

I behavior fuck, the object is the sister attribute of the object you. No matter who your sister attribute is, what is it. Of course, if your sister attribute is empty, that is, you do not have a sister, then the fuck method cannot be executed, and you should jump out directly. (** Add this section at 8.26 **)

How is it? Is it clear about the entire business logic?

Based on this idea, everything in reality can be armed with the idea of object-oriented.

Attribute design is relatively simple. Many people tend to be entangled in the design of methods in the program, such as large methods with too long code and stupid methods with too complicated logic. Next we will use a slightly more complex business to implement a people-oriented approach design.

For example, I woke up this morning and opened my eyes to start planning my schedule. Based on the natural mission of mankind and my personal sense of social responsibility, today I may have to do many things. First, I want to get up, wash, eat breakfast, go to work, work, eat, work, get off work, eat, maybe I want to go home from work to a supermarket to buy something, wait for a while after dinner (you can play cards, go online, watch TV), and finally go to bed. In this way, today is over. Therefore, my brain will immediately see the following "Today's plan" list:

    1. Get up
    2. Wash
    3. Dinner
    4. Go to work
    5. Work
    6. Dinner
    7. Work
    8. Off duty
    9. Shopping
    10. Dinner
    11. Leisure
    12. Sleep

If I design my plan today into a program, only 12 lines of code will be written in the "plan today" execution method, you can clearly understand what I want to do today. When you get up, you need to open the quilt with your hands or pedal. When you get up, you need to wear pants or underpants first, this is a problem that you will not consider when making the "Today's plan". It is also a problem that you do not need to consider in detail with the book. It is also a problem that people who read your code will not directly care about, these are the tasks of the sub-Business "get up" or the sub-business of the "get up" business. For example, my "get up" method is designed as follows:

    1. Stretch out
    2. Split quilt
    3. Sit up
    4. Clothes
    5. Sit down to bed
    6. Shoes
    7. Bed

Similarly, if you want to know how to get up, you can check the lines of code at a glance. Similarly, the process of wearing clothes is designed into the "wearing clothes" method, which is reasonable.

In addition, as for the rest time after dinner, I may play cards, access the Internet, or watch TV. The specific decision is to see my specific mood, so I arranged a "leisure" time during my plan. During this leisure time, I can get my mood status and execute different leisure modes according to different States.

However, the specific cards, surfing the internet, and watching TV are not the logic of the "casual" method, so they will be encapsulated into a separate method for processing.

In this way, the entire program logic is clear and the structure is clear. More importantly, it makes it easy for readers to understand. There will be no hard-to-understand "Big methods" or complicated "Stupid methods" for businesses ".

 

Finally, I strongly disagree with the use of numbers to restrict programs. I really do not like some people who come up with so-called "scientific" numbers as coding principles. For example, there are no more than three things that humans care about at the same time, no more than seven pieces of information that humans can handle at the same time, a principle that is too abusive, and 25 lines of page size. The human head is too different, there are too many special circumstances in the world, and the display resolution of various developers is also too different, so any fixed number used as the code of conduct, all are somewhat biased. It is really not recommended. (Unless you are a project manager and are developing project specifications)

 

 

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.