The basic programming skills are passed by, and the basic skills are passed

Source: Internet
Author: User
Tags comparison table

The basic programming skills are passed by, and the basic skills are passed
Spark is written in scala, and storm is developed by clojure. docker adopts go, and various programming languages emerge one after another. But they are actually all vests. As a programmer, we need to understand the essence of these similarities, by analogy. the basic logic control in the program-jump. The Assembly Language has long had the command to jump after the conditions are met. The so-called jump is to tell the machine to work there. just like an operator in the past, the C language has a goto statement, which is the most direct explanation of redirection. if there are too many goto in the program, I'm afraid no one can understand it. in C, if... else statements become more popular. When the conditions are met, the goto statement can be used to execute code in a certain range repeatedly. What the while and break statements do is not to add new functions, but to improve the program's accessibility and ease of writing. The for statement only makes the while statement with increasing values more concise, while the foreach statement is to facilitate the compilation of code that processes all elements in an object.
A function is a program design mechanism that treats a part of the Code as an organic whole for the convenience of understanding and reuse of the program, and then splits it out and names it. The function generates a return statement that enables the function to return to the original memory address of the program execution after calling the function. The function is used to name the operation to indicate the memory position at the operation start. Stack is a data structure that stores multiple values. It is a powerful tool for managing function operations. After understanding the stack, you can explain the function behavior during the runtime.
Recursive call is a method used by a function. It refers to the process of calling the current function again within the function. When multiple nested data structures cannot be implemented using the for statement, recursive call is required.

In a program, there are two main methods to convey error handling:
1) The returned value of the function is used to convey the error information. The caller determines the returned value for corresponding error handling.
2) pre-set the error handling code to jump to the corresponding error handling code when an error occurs.

Method 1 has two problems: Error omission and error handling, which lead to reduced code readability.
In method 2, append error types and enable error initiation are inherited by the modern exception handling mechanism.

Try becomes a modifier for ease of understanding. The expression of the trigger exception is to throw an exception. In handle T, the keyword of the error to be executed is finally. C ++ uses the resource acquisition and Initialization Technology to implement a similar mechanism by automatically calling the destructor. Generally, when function call parameters are insufficient, an exception occurs when the array is out of bounds. Fail First, that is, exception handling is preferred. Check exceptions are troublesome.


The whole program shares a reference table, that is, the scope of use of global variables. scope refers to the valid range of names. The dynamic scope stores the original value of the variable at the function entrance and writes it back to the variable at the exit. The static scope distinguishes their respective comparison tables by function to avoid global pollution. Generally, a program will have an overall comparison table (built-in), a file-level comparison table (global), and a function-level comparison table (local ).

A type is an additional type of data that people append to the data. It is initially used to add the data type information and tell the compiler how to handle it. Then, the user-defined type is the same as the object-oriented type, as a result, it is generated as a function type, and then evolved into an interface, resulting in generics and templates.

The type information and numeric values are regarded as dynamic types. The same type of design method is used in the memory to support type inference. For example, python is all PyObject. From the memory and when to use perspective, the type will be clearer.

What stores multiple elements can be understood as a container. The data in the container is stored in the memory, and the storage method varies with the container. Arrays are stored sequentially, and linked lists store relative addresses at the same time. Therefore, if many elements are inserted frequently, the linked list is more suitable.

In order to briefly express the relationship between computing time and data volume, the O notation is generally used. O (n) is the order of n, O (1) is the constant order of magnitude, and the read time of elements in the tree (equilibrium) is O (log n ).

Extensive and profound strings, moles code at the entrance of beiyou. Later on, various character sets were encoded. Comments were used in the program to specify the encoding method. unicode brought about unification.

Generally, strings in a language contain their own lengths. Strings in c do not know their own lengths. They are the most primitive strings. NUL (\ 0) is a special character that indicates string termination. Whether Unicode is 16bit or 32bit is specified by the option during compilation.

The parallel processing of a single cpu is actually a time-based alternate processing. The alternate methods include:
1) Collaborative multitasking-Alternate at appropriate nodes, based on trust, all processing will be processed alternately after appropriate intervals
2) preemptible multitasking-after a certain period of time, it can be terminated unilaterally without the assistance of terminating the program.

Preemptible multitasking has race condition, or is known as thread security. The race condition is set to three conditions:
1) Two processing shared Variables
2) At least one processing will modify the variable.
3) one process is not completed, and the other process will be involved.

As long as one of the three conditions is not met, you can write a thread-safe program.

Avoidance 1: without shared memory, there are no race conditions, such as using independent processes and actor models.
Avoidance 2: const in C ++, val in scala, and immutable in Java
Third, do not intervene. If you use a thread in coordination mode, such as coroutine, you can also use the identifier indicating inaccessibility-lock, mutex, and semaphore, which is actually a status card in use. The use of locks includes deadlocks and combinations that cannot be combined. They can only be solved by the transaction memory.

Object-oriented interpretation has at least two completely different meanings:
1) class is a function used to create user-defined types. Object-oriented is a program design that uses user-defined types and inheritance.
2) The program design that transmits messages to each other through objects in different States is object-oriented.

Objects are models of the real world. classes have different meanings in different languages. There is no general explanation. Classes are not indispensable except Java.

The following describes how to set up a model for variables and functions:
1) module, which combines the correlated functions and puts the initialization process into the package, that is, the constructor, such as perl
2) place functions and variables in a hash, such as javascript
3) closures are collected through namespaces. They are a technique for creating transactions of the object nature. A development expression that contains a free variable, combined with the constraint environment of the free variable, implements a closed state.

The existence of a class is only a rule agreed upon to make it easier to write programs. Class initially has the meaning of classification, also indicates the type, and has the function to explain, the concept is complex. C ++ and Java classes mainly play the following roles:
1) Overall Generator
2) Description of feasible operations
3) unit of code reuse

Three inherited implementation strategies:
1) Generalization and specialization: The subclass is the specialization of the parent class.
2) shared part extraction: extract the shared part from multiple classes as the parent class
3) Implementation of Difference: inherit as a way to achieve Reuse

To ensure the simplicity of understanding, it is necessary to prevent excessive hierarchy of inheritance trees. Ryth's replacement rule: the condition that a class T object must be established, and the object of the class T subclass S must also be established.
Solutions to multiple inheritance problems:
1) Multi-inheritance is forbidden in Java, and is replaced by delegation and interface.
2) search in order, for example, using C3 linearity in python
3) Mixed Processing
4) trait considers that the class has the opposite effect as a reuse unit and an instance generator, and makes the reuse Unit Special, set a smaller structure (feature = method combination ).

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.