Self-expressing code-trace the essence of code

Source: Internet
Author: User

We are studying self-expressionCodeFirst, you must understand the nature of the Code.

Before studying the nature of the Code, let's take a look at the development of music devices:
Phonograph> tape> Cd> MP3
No matter how the device changes, one thing that remains unchanged is that these devices are used to record Acoustic information-whether in the form of recording plastic or magnetic media.

How is code developed?
Tape drilling-> assembly language-> basic-> advanced language (c)-> object-oriented language (C ++)...->
Generally,Programming LanguageThe main function is to build a translation mechanism between humans and computers to convert the code written in a language that humans can understand into binary code.

However, in addition, code has a more important role to be ignored-code is a way of communication between people-this is more important than establishing a communication mechanism between people and computers. Because the importance of this role is not enough, the quality of code reading is not high.

Some programmers are happy to write code that others cannot understand, while others are proud to read their code without writing comments. We advocate the latter.

Code that can be self-expressed without comments becomesSelf-expressive Codes).

Self-expressing code undoubtedly brings great convenience to code understanding.

The following are three different writing methods in a game:

Scene. Fight (hero, enemy, fist); // I don't know who is playing

Hero. Fight (enemy, fist); // you can know who is playing

Hero. Fist. Hit (enemy); // The role of hitting is a fist, not a hero.

 

In order to be able to write more understandable code, we should improve the ability from the following aspects:

1. Supplement theoretical knowledge

In the Chapter "lack of theoretical knowledge", I have mentioned the lack of theoretical knowledge. I will discuss how to add more details later.

2. Improved design capabilities:

First, clarify the relationships among various objects, such as inclusion, combination, dependency, inheritance, and implementation.

This is the main factor. This is the cause of poor readability of many codes. For example, if the MVC hierarchy is not known, the Code UI and logic processing are mixed. I recommend that you take a look at Android.Source codeOpenwnn Japanese input method code in, which combines UI display and logic processing, leading to the obstacle of code reading.

For details, refer to here
Http://source.android.com/source/downloading.html

Second, master the design skills

A. Dependency Injection)
For example, dynamic dependency loading through configuration files like spring
B. domain specific language)
For example, state machines like OpenGL
.

Third, learn advanced ideas
You can learn advanced design technologies, such as groovy, Scala, and Ruby, to understand their high design philosophy, and apply the design concepts to your own projects.

3. Learning programming languages

Through the annotation, exception, reflect and so on of Java, you may no longer think that you have a deep understanding of Java. Learning constantly is the way to master more skills.

4. Better programming habits.

Code style improvement
Code Structure Improvement
Code naming improvements
Improvements in code comments

5. Learning programming tools

If someone says that he can use NotePad to write a powerful system, you must not think that he is cool. Maybe he is really cool, but there is nothing worth praising. This is like a person who has mastered special functions. It's just his own thing.
The act of ignoring the powerful functions that have been integrated in programming tools is like a waste of gold.
Let powerful tools exert their power.

6. Improve English proficiency

English is indeed a barrier, but if you have targeted improvement, the effort is not as difficult as taking level 4 or 6 exams. After all, programming requires a small number of English words.

These will be explained in subsequent chapters.

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.