2012年5月4日星期五

grossiste vetement chineconvenience

1.1variablescope 1.1.1 several common types ofvariable scope ( SCOPE ) or visibility refers to the variable in the program within the visible and can be referenced range .For example :1 grossiste vetement chine,global variables in all files are visible ,his scope is all documents ;2,static to define global variables ,only in the definition of its source file visible ,his action domain is the source file ;3,function within the local variables ,only in its function scope visible ;4,some variables ,only one piece of code segment ( visible in curly braces enclose a section of code ) ;void test_fun ( ) {int test_i = 0 ;test_i = 10 ;if ( test_i != 0 ){int test_count = 15 ;test_i = test_count ;} test_i = test_count ;/ / here will compile error ,because test_count only in if braces effectively .
} 1.1.2variables usingadvanced topics below most of the content from the code .1.1.2.1 enables variable reference localization code this book introduces the attack window concept :between the same variable multiple reference points between the code can become aggressive window ,in this window to add the code ,may not modify the variables .
In general ,to a variable reference localization ,namely reference points as possible together is always a good practice .The main advantage is to improve the readability and maintainability of .
If the variable reference points are concentrated ,is reading the code, as long as the attention to this piece of code you can ,otherwise ,the reader need to jump in the code .How to measure the variable reference concentration ? Code referred to a variable span concepts :all references to variables between the number of lines of code .
Void test_fun ( ) {int test_i = 0 ;int test_j = 0 ;test_i = 10 ;/ / and the first reference intervals of 1 lines of codeif ( test_i != 0 )/ / and second reference intervals of 0 lines of code{int test_count = 15 ;test_i = test_count ;/ / and third reference intervals of 1 lines of code} } test_i spans a total of 2 .
The average test_i span is 2 / 3.1.1.2.2 shortenedlifetime of variables variables on survival time of &mdash ;&mdash ;a variable duration across the statement number .It is from the first to the last cited references ,spanning between the number of lines of code .
Span show variable reference concentration ,survival time showed variable experience statement .As shown above ,test_i survival time is 6 statements .The low survival time benefits :1,reduce the attack window ,is not easy to make a mistake .
2 ,to make your code more accurate understanding ( improve readability ) 3,reduce the initialization error .Finally, an obvious advantage of easy program restructuring, if a program is split into a number of small procedures ,short survival time more valuable .
With the span and the survival time of global variables ,will find the global variable span and survival time were long &mdash ;&mdash ;this is to avoid the use of global variables good reason .
1.1.2.3 to reduce the scope of the general principles of 1,before the loop begins to initialize the change cycle in the use of the loop variable ,but not in the loop is at the beginning of these variable initialization subroutine .
In 2 ,until the variable will be used again for its assignment .The declaration and definition in use before .In 3 ,the relevant sentences together .Reduced variable span and survival time .
In 4 ,the relevant sentence group successful extraction of separate subroutine .Put a long subroutine split into smaller ,separate subroutine can narrow the scope of variables .At the beginning of 5,use the most restrictive visibility ,then according to the need to expand the scope of variables .
When the variable scoping shilly-shally ,should tend to select the variable can have the smallest scope :first variable restriction to a particular cycle ,and is restricted to a subroutine ,followed by class private variables, protected variables ,then the packet ( ) visible ,the last resort case put it as global variables .
On the variable scoping attitude ,is up to the programmer to &ldquo ;&rdquo and &ldquo ;convenience ;intellectual manageability &rdquo ;.The larger the scope ,writing code more convenient .
But to write programs more difficult to understand ,read ,debugging and maintenance .1.1.3 conclusion 1,global variables in all files are visible ,his scope is all files .In 2 ,static to define global variables ,only in the definition of its source file visible ,his action domain is the source file .
3 ,function within the local variables ,only in its function within the visible .4 ,some variables ,only one piece of code segment ( visible in curly braces enclose a section of code ) .
5 ,try to make the variable reference localization .6 ,try to shorten the lifetime of variables .7 ,try to reduce the scope of variables .1.1.4 extended reading code tenth chapter general issues in using will teach you how to make better use of variables .
Source by the beats by dre relate article:

没有评论:

发表评论