Crust in Hungarian nomenclature

zhaozj2021-02-16  45

Crust in Hungarian nomenclature

The Hungarian nomenclature is a naming specification when programming. Naming specifications are the most important places in program writing specifications, since ancient times, it is necessary to fight. What is the naming specification? Four words: name is smooth. It is divided into naming norms and bad naming specifications, which means that the famous naming namings and named naming nations are said to be named. Good dance shoes is to let dance shoes that don't feel their existing, and the bad dance shoes is to dance dancers. A bad naming specification has a much more creation than a good naming specification.

This article has to prove that the Hungarian naming method is a bad naming specification. The scope of this article is a static power type programming language. The analysis model of this article is C language and C language. The Huang Hungi is the abbreviation of the Hungarian nomenclature.

Cost of a Hungarian nomenclature

The manifestation of Huxiang is an additional name prefix to the variable name, such as NfoO, SZFOO, PFOO, CPFOO represents integer variables, string variables, pointer variables, and normallyte pin variables. It can be seen that Huather's type information of the variable is copied from a single location (declared variable) to multiple locations (using variables), which is redundant law. One of the costs of redundancy is to maintain the consistency of a copy. This cost is required to change the type of variable during writing and maintenance code. The cost of redundant methods is to take up extra space. A excellent writer will consciously follow a rule: the length of the code minimum organizational unit is suitable for 30 natural rows, if more than 50 lines should be reached. The writing space of a variable will add unnecessary difficulty to this method.

End Hungarian nomenclature

Here to prove that the benefits of Hungarian nomenclature are vague and cannot be expected.

Model 1: STRCPY (PSTRFOO, PCSTRFOO2) VS STRCPY (Foo, Foo2) What is the benefit of Huather here? I can't see it. No programmer will admit that you don't know the parameter type of the strcpy function.

Model 2: Unknown_function (nfoo) VS UNKNOWN_FUNCTION (FOO) What is the benefit of Huather here? I can't see it. For a function that does not know the type of determination, the programmer should go to the document of the function, which is a cost. The only benefit of using the Huxiang is to see the code, knowing this function requires an integer parameter, what is the use of this? The function is an interface, the type of parameters is only a small part of the interface. Important information such as functionality, export information, thread security, abnormal security, parameter legitimacy, etc. must also be checked.

Model 3: nfoo = nbar vs foo = What is the benefit of Hux Hung? I can't see it. The only benefit of using the Huxian is to see the code, you know that there is a copy action of a integer variable. It sounds no problem, you can sleep well. If he sees nfoo = szbar, it may wake up from the dream. And slow, will something really do? I want to be awakened to be a compiler. On the other hand, nfoo = nbar is just legitimate in the grammar. People who look at the code are truly concerned about the legality of semantics. The Huang Huang has no help. On the other hand, an excellent writer will consciously follow a rule: the temporary variable in the minimum organizational unit is preferably one or two, if more than three should be reorganized. Combined with the aforementioned first rule, it can be drawn that it is easy to understand, which is easy to understand, which is easy to understand. This is the built-in high quality of the code. A good naming norm is quite limited to the high quality of the internal construction, and the bad naming norms are larger than the high quality damage than people.

Implementation of the three Hungarian nomenclature

Here to prove that the Hungarian nomenclature is difficult to implement in the C language, it is not possible in the C language. Logically, after the conclusion of the benefits of Huather's income, the feasibility of the Huxiang will come to the feasibility of the Huxiang. However, in view of the death of the enemy that has caused the enemy that has caused the enemy, I still step on a feet. As many, the Huather is a redundancy of type systems, so the key to implementing Huxian is whether we can accurately copy the type system. This depends on the complexity of the type system.

Let's take a look at the C language:

1. Built-in type: int, char, float, double replication is N, CH, F, D? It seems that there is no problem. But who tells me how VoID said? 2. Combine type: Array, Union, Enum, Struct Copy is A, U, E, S? It seems to be more awkward. The difficulty here is not named for the primary type, but is named for the secondary type. AN represents an array? Sfoo, SBAR represents structural foo, structural bar? AUSFOO represents a joint structure foo array? Tired. 3. Special types: Pointer. Pointer should theoretically be a combination type, but in the C language can be considered a built-in type because C language does not have a very stringent area of ​​different pointer types. The following starting performance: pausfoo indicates the fed-structure foo array pointer? PPP indicates a pointer to the pointer of the pointer?

The nightmare has not ended yet, then look at the type system more rich in C language:

1.Class: If the Struct in the C language can also use the STRU to push the past, do not dream to use CLS to slit C Class Class. Strictly speaking, Class is not a type, but a tool for creating types, in C , the number of language built-in types, and the number of customized types created by Class Customer is completely ignored. STDVECTORFOO indicates the standard library vector type variable foo? Crazy thought. 2. Name the space: BoostFilesystemIitratorfoo, indicating the Boost space FileSystem subclass space traversal directory type variable foo? The programmer is going to collapse. 3. Template: Do you remember std :: map The exact name of the type? I can't remember, it seems to have more than 255 characters, or I will spare me. 4. Template Parameters: Template Const T & Max (Const T & A, Const T & B, BinaryPredicate Comp) Smart You, please use the Huxian T. God is laughing. 5. Type modification: Static, Extern, Mutable, Register, Volatile, Const, Short, long, unsigned nightmare plus modified? Still a nightmare.

Are you willing to make a dancer on a shackle?

转载请注明原文地址:https://www.9cbs.com/read-24336.html

New Post(0)