Saturday, October 23, 2010

c language programming style



Chapter I: indentation

Tab is 8 characters, thus indentations are also 8 characters. There are many strange style, they indentation is defined as 4 characters (set to 2 characters!) Depth, which is like trying to PI defined as 3 as unacceptable.

The reasons are: the size of indentation is to clearly define the beginning and end of a block. Especially when you have spent in front of the computer more than 20 hours later, you will find a large indentation makes your program understanding easier.

Now, there are some people that use 8-character indentations makes the code from the right side close to the 80-character terminal screen width is difficult to be watching proceedings. The answer is, but your program has more than 3 indented time, you should modify your program.

In short, 8-character indentations makes the program easy to read, there is an additional advantage is that it can become nested layers you will program the time to give you a warning too. This time, you should modify your program .

Chapter II: The position of symbols

Another issue of C programming style is to brace treatment. Indentation with different sizes, there is little reason to choose one instead of another style, but there is a recommended style, it is the Kernighan and Ritchie's The classic book brings, it will start

Braces on the line last, and will end brace on the first line, as follows:

if (x is true) (we do y)
However, there is a special case: name function: brackets is the beginning of the next line on the first, as follows:

int function (int x) (body of function)
People of all unorthodox criticism this inconsistency, but all right-thinking people understand that: (1st) K & R is the ___ of the ___, and (Second) K & R, if not, see first. (:-))...... In addition, the function is special, need not be the same.

Note that the end of the bracket in its share of the line is empty, __ __ it apart with a statement as a continuation of the same symbol. Such as "while" in the do-while loop, or "else" In the if statement. as follows:

do (body of do-loop) while (condition);
And

if (x == y) (..) else if (x> y) (...) else (....)
Reason: K & R.

Also, note that this brace placement method reduces the number of blank lines, but no less readable. Thus, the screen size is limited, you can have more blank lines to write some comments the.

Chapter III: Naming System

C is a concise language, then the name should be simple. ASCAL with MODULE-2 and the language is different, C programmers do not use such ThisVariableIsATemporaryCounter the like are named. A C language programmer will be the named "tmp", which is easy to write, and not so difficult to understand.

However, when the mixed type of the name had to appear when the descriptive name of the global variable is necessary for the. Call a name "foo" is a function of overall annoying. Global variables (only you have to use it only when used), as a global function, requires a descriptive naming. If you have a function used to calculate the number of active users, you should be so named - "count_active_users ()"-- or other similar forms, you should not be named "cntusr ()".

There is a method known as the Hungarian name, it will function, the type of code to write the variable name in this way is a manifestation of defective brain --- the compiler knows the type but also to check it, but this will only confuse programmer. - Why know why Micro $ oft will produce so many "bugs" program has to!!.

Local variable names should be short and pithy. If you have a random integer loop counter, it is possible to have "i", if it can be made without any possible misunderstanding, then, to write "loop_counter" is inefficient. Again a, "" tmp "can be any temporary value function variables.

If you are afraid of confusing the name of your local variables, there is another issue, which is called

function-growth-hormone-imbalancesyndrome.
Chapter IV: Function

Function should be short and charming, but only for one thing. It should only cover one or two screens (80 * 24 1 screen), and only for one thing, and will do it well. (Is not that UNIX- style me, translators note).

A function of the maximum length and complexity of function, and inversely proportional to indentation. So, if you have written a simple but a function of the length of long, and you have already done a lot of different situations very small things, write a function is a little longer does not matter.

However, if you write a very complex function, and you have estimated that if most people reading this function, he may not know what to say to this function, this time using the descriptive name of a help function.

Another consideration is the number of local variables. They should not exceed 5-10, or you may be wrong. To re-consider this function, they split into smaller functions. The human brain can often be very easy to remember live in 7 different things, more than this number would cause confusion. you know you are very smart, but you may still want to know two weeks before to do.

Chapter 5: Notes

Notes is a good thing, but too many notes and dangerous, do not try to explain your area code is a comment on how how good: you should write better code, rather than spending a lot of time to explain those bad code.

Usually, the comments you explain your code is doing what, not how to do. Moreover, Yao tried to avoid Jiang comment inserted in a function of Ti in: If this function Que Shihen Fuza, you Xuyao in which a part of Note, you should look back to Chapter IV. You can write a short note to indicate or warn those you think are particularly clever (or very ugly) part, but you have to avoid too much. Instead, the written comments before the function, telling people what to do in it, and possibly why.

Chapter VI: You have caught them up.

Do not worry. You may have been accused of "GUN emacs" will automatically help you deal with C source code format, and you have seen it does so, however, the case of default, its role is somewhat different of man (in fact, they are easily knocked out of something than even ugly - ainfinite number of mnkeys typing into GNU emacs would never make a good program)

So, you can either do not use GUN emacs, or let it use sanervalules. To use the latter, you need to enter the following statement to your. Emacs file.

(Defun linux-c-mode () "C mode with adjusted defaults for use with the Linux kernel." (Interactive) (c-mode) (c-set-style "K & R") (setq c-basic -offset8))
This will define a Mx Linux-c-mode command. When you when hacking a module, how you will -*- linux-c -*- input in the beginning of two lines, this mode will automatically work. Moreover, You may want to join the following

(Setq auto-mode-alist (cons''("/ usr / src / linux .*/.* \. 銆栥? Ch $ ". Linux-c-mode) auto-mode-alist))
To you. Emacs file, so that when you / usr / src / linux and edit the file, it automatically switches to linux-c-mode.

However, if you do not let emaces to automatically handle file formats, not nervous, you still have the same thing: "indent."

GNU indent is also very rigid format, which is why you need to add a few lines of command options. However, this is also not too bad, because the creator of GNU indent formats also remember the authority of K & R, (GNU is not crime, they simply wrong in this matter guided by the people), you have to do is just enter the options "-kr-i8" (that "K & R, indented 8 characters).

"Indent" has a lot of features, especially when it recommended that you re-format your code, you should look at the help. But remember: "indent" is not a bad program style Souls Dan.







相关链接:



Specialist Animation Tools



VOB to ZUNE



VOB to WMV



Some Terms related to the domain name explained



Community 2.0 My Community I Call The Shots



Word file recovery simple



VOB to MP4



Icahn comeback MOTO dilemma



Cybersquatting: Business Down? Injury or DOWN?



Photoshop rendering realistic beautiful necklace



Review Games Simulation



09 'happy to steal food' in 2010 what we steal?



The New Second Generation Of New ID Card Readers



System Maintenance EVALUATION



States United States to transfer?



Trust by the Bank through the East, TongLINK / Q acclaimed



Premier SERVER Applications



Wednesday, October 6, 2010

Some tips on data collection



The face of research subjects or their number of ideas, we all want confirmation or a proof, which requires us to have rapid, timely and accurate grasp of information (doucument) and information (information) and information (intelligence) capabilities. Sometimes, its very confusing, often lost in the pile of information, the network, there seems to be no end of information, the so wanted to find a method of data collection, hoping to find what you want, mastery of knowledge, rather than letting it control I. The following ways and means I have recently considered, and now take the liberty of mention, we may as well explore the study.

1, the network search algorithm.

1) search engine method. Network Well, of course, the first use of network ah, so you can search engines is essential. Such a thing to check, you can google type in search terms, and then through a number of screening, may allow you to quickly understand and find what you want, or can not necessarily inspires you ah!

2) Core site
Daily access to the Internet, it should form for their own professional direction the core site, with these sites, you can often look to maintain their own knowledge and information sensitivity. For example, a number of professional organizations or government professional organizations, civil society website, Guoyan Wang (http://www.drcnet.com), Economic Information Network (http://www.cei.gov.cn/), etc. .

2, the traditional resource discovery
I think the network's early look, basic access to the subject of general knowledge, then a very important and very effective way to be from the traditional books, journals and other resources to start, for orientation and will issue a query. Orientation is to find a particular type of topic it belongs to the core journals, core journals from the article, you can find new research directions and the extent of the trade; SDI is the refinement of the search, you can find articles relating to the topics , has a strong reference, reference of the literature.

It also can author, cited those and other aspects of search and reverse lookup.

3, research
If you have been a pre-data collection and analysis, it is best to practice to the next step to investigate what will be the subject of what the actual situation, data, news, development trend, etc. These and the fact that the information closest to Any other method is not available.

4, the daily accumulation of
On the information sensitivity of the culture, should be a cumulative process, in order to achieve this objective, we have in everyday work, study and life, develop on the data sorting, and the absorption of good practice. Good media is that we absorb nutrients hotbeds, such as TV: cctv in the "dialogue", "economic and a half hours", etc., flat: "21st Century Business Herald", "Economic Observer", "financial" and so on.

5, the use of extraordinary measures
Information and data collection time, and some are not using the means of retrieval can be achieved, but through some sense, not part of the information obtained by means of retrieval. For example, good ideas and ideas with colleagues or to students through the exchange of "brainstorming" method to get people to talk about and so on. In addition, such as information obtained can also use a wide variety of relationships, for example, U.S. scientists showed that: a package handed from one person to another random person hands where up to only six individuals, which is often lamented "This is really a small world" reasons.

Attachment: commonly used search engines

Miscellaneous:
http://www.google.com,
http://www.directhit.com,
http://www.infind.com,
http://www.metafind.com,
http://www.altavista.com

Search Engine:
http://www.findwhat.com, a provider of products and services information web site
http://www.meta-list.net, a new mailing list search engine
http://www.infojump.com, a magazine and articles on search engine
http://search.yesky.com, SAN FRANCISCO it search engine, to provide information technology professional information

Intelligent Search Engine:
A money search (http://www.goyoyo.com),
Network Code (http://www.wander.com)

Multimedia and image search:
http://www.ditto.com
http://www.freefoto.com

Featured Site Search:
http://www.about.com, a trades experts in search engine
http://www.refdesk.com/index.html, reference information, search engine

Search engine search engine:
http://www.searchenginecolossus.com, it collected around the world search engine, directory, alphabetical by country.
http://www.searchpower.com, the world's largest search engine directory
http://www.searchenginehuide.com, Search Engine Guide

Integrated search engine:
http://www.profusion.com
http://www.1blink.com
http://www.all4one.com
http://www.mamma.com
(Metasearch) http://www.metasearch.com
(Digisearch) http://www.digiway.com/digisearch/
(Fusion) http://locra.compapp.dcu.ie/fusion/
(Cyber411) http://www.cyber411.com
(Metacrawler) http://www.metacrawler.com/
(Savvysearch) http://savvy.cs.colostate.edu:2000/
(Highway61) http://www.hignway61.com
(Dogpile) http://www.dogpile.com
(SSearch Spanie) http://www.searchspaniel.com
(MetaFind) http://www.metafind.com
(Inference Find) http://www.infind.com
(Internet Sleuth) http://www.isleuth.com
(Debriefing) http://www.debriefing.com/
(Super Seek) http://www.w3.superseek.com/superseek
(Ask Jeeves) http://www.askjeeves.com/
(IBM infomarket Service) http / / www.infomarket.ibm.com/
(HotOIL) http://www.dstc.edu.au/cgi-bin/RDU/hotOIL/hotOIL
http://www.chinabusiness.org/search.htm

Preference for professional search engine:
As the Internet search engine and can not cover all Internet sites, and different search engines have different emphases, so many search engines can select the appropriate professional search engine queries.
http://search.cnet.com
http://www.easysearcher.com
http://www.search.com







Recommended links:



MTS to AVI



Who Is Knocking The Door Of Opportunity?



Pipeline



Export and the introduction of the REGISTRY



modesty aside the samsung s3550 shark 3 is Really



Direct Marketing Manager: your direct sales beyond



Premier Audio CD Players



Collection Ftp Operation Of Common Sense



DIVX to Zune



Easy TO use Remote Computing



Focus DreamWeaver MX 2004



DAT To 3GP



PhotoShop new tricks: Paintings in Paintings



Do For Others To Do The Wedding Dress Carriers Should Be Out Of The "influence" The Edge