Abstract: In his multi-volume book "computer programming art", knuth demonstrated the skills and artistic nature of computer programming and discussed the relationship between computer programming and art in his Turing Award speech. This article Article Inspired by knuth's book, I further explained why computer programming should be an art and Code The main form of presentation art.
Image Source: accidentally in code
1. Introduction
"(Program (computers) = * Art )? So: What"
"Only about 5%ProgramMembers can create art when writing code. The other 95% must be for successful scientists, not artists ."
When talking about "art", people will naturally think of words like "beauty", "skill", and "inspiration, but it is rarely associated with the seemingly boring word "computer programming. Donald knuth, author of multiple books in the art of computer programming, successfully demonstrated the art of computer programming through his books. Later, he made a scientific discussion and interpretation of the art of computer programming in the Turing Award speech [1. He is not the first person to do this, but he is undoubtedly the most successful. Guido van rosum, a python designer, says:
"I agree with knuth's definition (or use) of the word 'art ). It is very closely related to creativity for me, and it is very important for my work. If there is no art in it (Computer Programming), it will not have any fun, and I will not continue to engage in it after 30 years ."
Writing beautiful programs requires inspiration and superb skills, like a poet writing poetry, painter painting, architect building, full of fun, challenge and beauty. Elegant programs are as intriguing as poetry, as eye-opening as famous paintings, and as magnificent as churches. Therefore, computer programming is also an art. Programmers are the artists who create this art.
2. Beauty of Programming
What kind of programs are beautiful programs? This question does not seem to have a complete answer. We are amazed by a cool demo or a dazzling video game. Doom and half life can be said to push 3D technology to the extreme, this kind of program can always give people a visual beauty, just like the beautiful oil painting in the hands of the painter, it's just the canvas of programmers on the computer screen. The paint brush is the keyboard. Linux is also a kind of beauty, an open beauty, an elegant design inherited from UNIX, powerful portability, and rich tools, this makes it look like a magnificent church designed by good architects. These benefits are obvious. There is also a kind of beauty, hidden behind the program, flowing inSource code. What is beautiful code? Maybe they look beautiful. Here is an amazing macro-defined C code set [2]: allows programs to create constants to make them look like images on the screen! The self-description capability of the program is greatly enhanced!
# define X) * 2 + 1
# define _) * 2
# define S (0
static unsigned short stopwatch [] =
{< br> S _ x _,
S _ x,
S _ x,
S _ x __,
S _ x __,
S x _,
S x _,
S x _,
S x _,
S x _,
S _ x __,
S _ x __,
S _ x ___,
S _ x ____,
S _ x ______,
S _
};
This kind of code can only be seen in Usenet or chaotic C code competitions, although it is not very useful, but it does make us feel that code-a bunch of regular symbols-can also create visual beauty. It may also be a skill used by the program --AlgorithmBeautiful, just like the Tower of Hanoi program, the fast sorting program, naturally uses recursion to make them look very compact and easy to read. This is of course also a kind of beauty, which can only be realized by programmers. There is also a kind of beauty, which is hidden behind the code. It is the beauty of program design ideas and the beauty that needs to be understood. UNIX brings us not only its powerful functions, but also its profound design philosophy [3]:
"Small is beautiful ." (Small is beautiful .)
"Let every program be good at doing one thing ." (Make each program do one thing well .)
"Everything is a file ." (Everything is a file .)
"Silence is gold ." (Silence is golden .)
"Make the operating system kernel small and lightweight ." (Make operating system kernels small and lightweight .)
These ideas are a golden rule in UNIX design. This kind of beauty will go through time and space and spread throughout the ages, making UNIX not only an excellent operating system, but also a computer philosophy.
People like beautiful things. Programmers cherish beautiful programs. We regard those who create beautiful programs as "hackers ". Paul Graham believes that hackers and painters are very similar [4]:
What hackers and painters share is that they are creators. Like the composer, architect, and writer, what hackers and painters try to do is also a good thing to create. They do not do research themselves, but it would be better if new technologies are found in the process of creating good things.
Good painters are artists, so good programmers-hackers-are also artists. This makes it easy to understand why many UNIX-kernel hackers keep artist-style scams.
3. Programming Skill
A clever program is like an implicit poem, which requires careful understanding and careful understanding. It's really "coming to the Summit, with a small view of the mountains "! Pi is the same, but only four simple lines of C code can print the first 800-bit PI program, which will open our eyes [5]:
IntA =10000, B, c =2800, D, e, f [2801], G;
Main (){
For(; B-c;) f [B ++] =/5;
For(; D =0, G = C *2; C-=14, Printf ("%. 4D", E + D/A), E = D %)
For(B = C; D + = f [B] * A, F [B] = D % -- g, D/= g --, -- B; D * = B );
}
Hackers do not stick to the rules. They constantly innovate and find a more clever way to solve the same problem. It was once popular to write such a program, which can print all its own code. Programmers try to find the shortest program. Although this is not very practical, it is very challenging. hackers take it as a pleasure. Let's see how weird the following program [6] is.
Char* F ="Char * f = % C % S % C; Main () {printf (F, 34, F, 34,10);} % C";
Main () {printf (F,34, F,34,10);}
A major attraction of computer programming is that it requires superb skills, which make us see the beauty and enjoy it. Moreover, I found that when the limit increases, the skill and pleasure will increase. To write such a program and print it on the screen ~ A number between 1000. This is also a piece of cake for a newbie, and a for loop is done. Okay, let's add a limit. No loop is allowed. Now you have to worry about it, but you still want to use recursion. That's good. We add a limit and do not use recursion. This may make it difficult for you. You may think it is impossible to have such a program. Let's look at the following program:
# Include <stdio. h>
# DefineA (x) x; X;
IntMain (Void)
{
IntN =1;
A (a (A (printf ("% D", N ++ ))));
Return 0;
}
We neither use loops nor recursion, but use macros! We are often surprised by the 64 K 3D animations launched by the famous warez organizations around the world. Such small programs often have unimaginable results. They apply 64 K limitations and the power of assembly to the limit, which is amazing. 64 K does not seem to limit its artistic nature, but has played a promoting role. In addition, when you have a good understanding of the system, you will have more fun. Because you can joke with the system with skills, cheat it, get it done, or even attack it. See the following program:
VoidMain (){
IntX;
X =0;
X =1;
Printf ("% DN", X );
}
Think about how to let the program skip the "x = 1;" sentence and print 0 on the screen? If you know about the system stack, you may give a program similar to the following [7]:
VoidFunction (IntA,IntB,IntC ){
CharBuffer1 [5];
CharBuffer2 [10];
Int* Ret;
Ret = buffer1 +12;
(* RET) + =8;
}
VoidMain (){
IntX;
X =0;
Function (1,2,3);
X =1;
Printf ("% DN", X );
}
It uses the stack changes when calling the function, changes the return address of the function, and skips the "x = 1;" sentence to directly execute the following printf! It successfully spoofed the system! If you change the return address to the first address of a pre-placed piece of code, you will hijack the system and let it run your piece of code. If that code is clever enough, you will be able to gain full control of the system! This is also the basic principle of buffer overflow. I think this kind of technique will make you very excited, no less as a poet intoxicated with your own poems. We have seen that the art is developed and formed.
4. the joy of Programming
The fun of computers is that if you have any good ideas, you can experiment immediately to get the results. Of course, you may not get the right answer immediately, but you have to sit down and stare at the computer screen, think about how to solve the problem, and verify your results through constant attempts. You can find the correct method to make the problem disappear suddenly. You can also change the angle to see a sudden flash: it turned out to be like this!
Programming is a Training of creativity. Good programmers do not follow the rules and do not use mediocre methods to solve problems. Instead, they find simpler methods based on their own opinions, because they can see the essence behind the problem. Then they will write new and beautiful programs to verify their methods. "It's hard to tell why it's so fascinating to think behind closed doors and find a pretty answer to a problem. However, if you have ever experienced finding a better method, you will understand that this is an incomparable feeling ." [8] this kind of feeling makes us happy as a child.
This feeling of "incomparable" flows inside the programmer, so that programmers are obsessed and crazy. The obsessed programmer gets the unspeakable pleasure of his artistic creations and gets addicted to it. The father of Linux talked about the fun of programming in his biography [8:
Programming brings people the initial excitement. It is a good explanation: You can use programming to control a computer. What you call a computer, what it does, is always accurate, and there is no complaint. This is interesting in itself.
It is much more fun than playing games like chess, because it allows you to set game rules on your own. What kind of rules do you set will export the results that match the rules.
In the computer world, you are the creator, and you have ultimate control over what happens. If you have a deep skill, you can be god-on a small level.
There is no doubt that outsiders will never realize it. After all, "the child is not the joy of fish ". The endless fun allows programmers to blur the joy of being an artist and start to enjoy their work.
5. Conclusion
Rob Pike sighed with pessimism: "That art disappears ." [9] but I think he will be happy when he sees books like the art of assembly language and the art of Unix programming. This kind of art has not disappeared and will continue to spread. We should not feel embarrassed for "art for art. As knuth said [1]:
"We have seen that computer programming is an art because it applies accumulated knowledge to the world because it requires skill and flexibility, especially because it creates beautiful goals. A programmer who vaguely realizes that he is an artist will enjoy what he does and will do it better ."
Perhaps we should raise our double-edged sword to fight for the holy cup of art. However, I like the plow head more than the sword.
6. Thank you
I am particularly grateful to Mr. Wang yagang for reading this article and giving me valuable advice. Without his guidance, I cannot complete this paper.
References
[1] donalde. knuth, programming as an art , ACM Turing Award Lecture, 1974.
[2] Peter van der Liden, Expert C Programming , Prentice Hall, 1994.
[3] Mike gancarz, Linux and the unixphilosophy , digital Press, 2003.
[4] Paul Graham, hackersand painters , O 'Reilly, 2004.
[5] international obfuscated cCode contest, http://www.ioccc.org.
[6] Eric S. raymond, jargonfile , http://catb.org/jargon/html/index.html.
[7] Aleph one, smashing the stack for fun and profit , http://insecure.org/stf/smashstack.html.
[8] Linus Torvalds anddavid diamond, just for fun , Harper service, 2001.
[9] robpike, systemssoftware research is irrelevant , http://herpolhode.com/rob/utah2000.pdf 2000.
http://kb.cnblogs.com/page/132089/