Second week homework

Source: Internet
Author: User
Tags uppercase letter

    • How many kinds of naming methods are present? Please give me an example

1. Pascal's nomenclature (that is, the Pascal name method).

Naming rules:

The variable and function names are used to increase the readability of variables and functions when they are linked together by two or more than two words.

The word is not separated by a space break or a connection number (-), the bottom line (_), the first letter is capitalized, and the first letter of the subsequent word is also capitalized, for example: FirstName, LastName. The initials of each word are named in uppercase letters, known as the Pascal Nomenclature, and are derived from the naming conventions of the Pascal language, also known as the "big hump-type nomenclature" (Upper Camel case), a subset of camel-cased.

In programming

The Pascal nomenclature is to capitalize each word at the time it is named, such as:

Program code public void DisplayInfo ();

String UserName;

Both use Pascal's nomenclature.

In C #, the name of Pascal and the name of the camel are mostly.

In the coding conventions in C #, you should use the Pascal nomenclature, such as score, name, and internal, when naming public member variables, private member variables (private), protected member variables (protect), or internal member variables ( Status is a valid member variable name.

1 "Pascal nomenclature" can be regarded as a naming convention, and there is no absolute and mandatory, in order to increase recognition and readability. Once you have chosen or set a naming convention, you should keep the formatting consistent when you write the program.

2. Camel name Law I. Basic concepts

Camel-like nomenclature (also called Hump nomenclature), as its name CamelCase implies, refers to the mixing of uppercase and lowercase letters to form the names of variables and functions. Programmers in order to their own code can be easier to communicate between peers, so more than a unified readability of the better way to name. For example: Some programmers like all lowercase, some programmers like to underline, so if you want to write a variable of my name, they often use the wording of myname, my_name, myname or myname. Such a naming convention is not suitable for all programmers to read, and the use of the Camel name method to express, can increase the readability of the program. For example, the following is the same function that is named with the camel-named method and the underscore method, respectively:

Printemployeepaychecks ();

Print_employee_paychecks ();

The first function name uses camel-named notation-each logical breakpoint in the function name is marked with an uppercase letter, and the second function name uses the underscore method----each logical breakpoint in the function name is marked with an underscore.

Camel-style nomenclature has become more and more popular in recent years, and it is used quite a lot in environments such as many new libraries and Microsoft Windows. On the other hand, the underscore is popular after the advent of C, in many of the old Programs and UNIX environment, it is very common use.

Two. Application Overview

Camel-style nomenclature (camel-case) is a set of naming conventions (conventions) when a computer program is written.

Camel-style nomenclature is when a variable name or function name is a unique identifier consisting of one or more words, the first word starts with a lowercase letter, the first letter of the second word is capitalized, or the first letter of each word is in uppercase letters, for example: MyFirstName, Mylastname, such a variable name looks like camel peaks as one after the other, so named.

The term camel-named (camel-case) is a camel that comes from the widely used case-and-write format in Perl, and the cover picture of Programming Perl (O ' Reilly), a bestseller of Larry Wall.

The naming rules of camel-like nomenclature can be regarded as a convention, and there is no absolute and mandatory, in order to increase recognition and readability.

Small Hump method

The variable is usually identified by the small hump method. The Hump method means that in addition to the first word, the first letter of the word is capitalized. Such as

int mystudentcount;

Variable Mystudentcount The first word is all lowercase and the first letter of the following word is capitalized.

Large Hump method

Compared to the small hump method, the big hump method capitalized the first letter of the initial word. Commonly used for class names, function names, properties, namespaces. Such as

public class Databaseuser;

3. Hungarian nomenclature

I. Principles

The Hungarian nomenclature is a naming convention when programming. The basic principle is: variable name = attribute + Type + object description, where each object name requires a clear meaning, you can take the full name of the object or part of the name. Naming is based on the principle that easy memory is easy to understand. It is very important to ensure the consistency of the name.

Example

For example, if the name of the form is a form, then the Hungarian nomenclature can be abbreviated as FRM, then the full name of the variable should be frmswitchboard when the form variable is named switchboard. This makes it easy to see from the variable name that switchboard is a form, and similarly, if the variable type is a label, it should be named Lblswitchboard. It can be seen that the Hungarian nomenclature is very easy to remember, and makes the variable name very clear and understandable, thus enhancing the readability of the code, convenient for each programmer to communicate with each other code.

History

It is said that this nomenclature was invented by a Hungarian programmer named Charles Simonyi, who later spent several years at Microsoft, and the nomenclature spread through Microsoft's various products and documentation. Most programmers use this nomenclature, no matter what software they use to develop them. The starting point of this nomenclature is to combine variable names by: The Order of attribute + Type + object description, so that programmers have a visual understanding of the types of variables and other properties when they make variables, the following is the HN variable naming convention.

Two. For example

Hwnd:h is a type description, representing a handle, WND is a variable object description, representing the window, so the HWND represents the window handle;

PFNEATAPPLE:PFN is a type description that represents a pointer to a function, Eatapple is a variable object description, so it represents a function pointer variable that points to the Eatapple function.

G_cch:g_ is a property description that represents a global variable, and C and CH are count types and character types, together representing the variable type, where the object description is omitted, so it represents a global variable that counts the characters.

Above is the general rule of the HN nomenclature.

Note: In Java often appear non-conforming to the requirements of the naming place (because now in Java development, in the naming process will often appear the nonstandard naming, I believe you will often appear such naming problems, so the Java common naming method listed as follows)

Name of package (all lowercase, defined by domain name)

The Java package name is made up of lowercase words. However, due to the Java object-oriented programming feature, each Java programmer can write their own Java package, in order to guarantee the uniqueness of each Java package naming, in the latest Java programming specification, the programmer is required to add a unique prefix to the name of the package they define. Because domain names on the Internet are not duplicated, programmers generally use their own domain name on the Internet as the only prefix for their packages.
Example: Net.frontfree.javagroup

Name of the class (capitalize the first letter of the word)

By convention, the Java class name usually begins with an uppercase letter, and if the class name consists of multiple words, the first letter of each word should be capitalized such as Testpage, and if the class name contains a word abbreviation, each letter of the word should be capitalized, such as: Xmlexample, One more naming technique is that because a class is designed to represent an object, you should choose a noun when you name the class.
For example: Graphics

Name of method (first letter lowercase, letter start uppercase)

The first word of the name of the method should begin with a lowercase letter, and the following words begin with a capital letter.
Example: DrawImage

Name of the constant (all uppercase, often underlined)
The names of the constants should all use uppercase letters and indicate the full meaning of the constant. If a constant name consists of multiple words, you should use underscores to split the words.
Example: Max_value

Name of the parameter

The naming conventions for parameters are the same as the naming conventions for methods, and to avoid confusion when reading a program, make the name of the parameter as clear as possible if the parameter name is a single word.

Javadoc notes

java in addition to our common annotation approach, the Java language Specification defines a special kind of annotation, which is what we The Javadoc comment, which is used to record the API in our code. Javadoc comments are a multiline comment that begins with/** and ends with a comment that can contain some HTML tags and specific keywords. The advantage of using the Javadoc annotation is that comments written can be automatically converted to online documents, eliminating the hassle of writing program documents separately.  

                         ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                                                            ,         &N Bsp                          ,         &NB Sp                          ,         &NB Sp   2016-03-12  17:41:30

Second week homework

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.