Write code and write articles

Source: Internet
Author: User

Write code and write the article very similar, all use computer work, all code word. Judging a piece of code is not good, can be evaluated is the code format, style and algorithm, the following from these aspects to see how similar writing code and writing article.

Format

In the writing code mainly refers to indentation, space, blank line, alignment and other text layout forms, this is the most easy to reach a good indicator of code, a lot of IDE environment is a key automatic format. A good code format is like a good article, beautifully formatted, with clear passages. The format of the code is beautiful form beauty, is the external beauty.

/* * Examples of poor formats * */ function Swap (A, b)           {var           c=A;  A=b;          b=c;      } /* * Good Format example * */
function Swap (A, b) {    var c = A;     = B;    b=c;}
Style

Writers have a style of writing, code also has the code of the wind, coding style contains more things, such as naming style, such as the implementation of the way.

Code wind in fact and style is very similar, such as Lu Xun's prose poems < weeds > first article, called < Autumn Night >. The first paragraph reads as follows: "In my back garden, you can see two trees outside the wall, one is JuJube, and one is JuJube tree." "Then a different style to describe it can also be:" My home after the walls of two jujube trees outside. ”

To exclude the deep meaning that needs to be expressed, both of these words express the two jujube trees in my backyard, and the purpose is the same. Can not be adopted vocabulary statement is not the same, even if the style is different. In the code, the code wind is so formed, the same functional requirements, different people to write, the code is basically not exactly the same, because everyone has their own code wind, the code wind is reflected in the name of the variable, the loop statement of preference (for or while) and so on and so on.

To give a different code wind example:

/* * Array summation * */
function sum_for (arr) {    var sum = 0;      for (var i = 0; i < arr.length; i++) {        + = arr[i]    ;    } return sum;} function Sum_while (arr) {    var sum = 0, i = arr.length;      while (i--) {        + = arr[i]    ;    } return sum;}
Algorithm

Writing an article will have an outline of a skeleton. Writing code is the same, but we call it algorithm, the algorithm determines the whole code of the direction, is a tragedy or comedy. If you want to write an article, because you have a good idea to express to your readers, but because of your lack of words, idioms are still wrong, written articles will always be text. The same writing code sometimes does not convey the words, because the syntax rules of the FOR statement is not clear, the processing process will have the expected results inconsistent results, this time we call it a BUG . The algorithm is a piece of code of Soul thought, as an article, despite the style of the plain, but deep thinking, ingenious ideas, thought-provoking, profound influence. Good algorithms also have this charm, code wind level, but the use of a wide range, such as fast sorting, such as dynamic planning, a good algorithm can even be immortal, such as good novels are translated into national languages, good algorithms will be implemented in various programming languages. The programming language is ultimately a tool of expression, a tool for expressing the algorithms in our hearts. If the code only pursues the format and style (code wind), regardless of the algorithm design, then it will be like writing articles only the pursuit of typesetting and rhetoric but no thought, reading will be empty and powerless. So the algorithm is like the code of the soul, is an intrinsic beauty.

The world of Reality

The reality of the world is different from the ideal world, but write code once again in the spirit of writing articles, many of our programmers are also copy and paste, referring to third-party libraries, their own parts of the organization is only a small part, the bottom of the development of programmers in the industry also always accounted for a small part. Most of the work in the editorial work is also the editor reprint, the original editor is also less and less.

At last

Although the above paragraphs I put the algorithm is boast and boast, highly respected, but if you and I are not created the great algorithm of the kind of ordinary people, that is, we can only in the code format and code style more efforts of friends. We obscure the code of the wind or less write some, do programmers to be kind! The above is purely entertainment ~ ~ welcome you to provide more interesting similarities.

Write code and write articles

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.