What is "context (context) in programming?

Source: Internet
Author: User
Recently read Flask's documentation, read a lot about context (contextual) terminology, such as application context, request context, etc., access to data but not understood? Is there a better explanation?

Reply content:

Each program has many external variables. Only a simple function like add does not have an external variable. Once your program has an external variable, the program is incomplete and cannot be run independently. In order for them to run, you need to write some values to all of the external variables in one. The collection of these values is called the context.


For example, in C + + lambda expression is inside, [is written here is the context] (int a, int b) {...}.

Context is the snapshot of environment. You can't find it because the context is not a specific thing, the context in different places to express different meanings, to perceptual understanding.

In fact, the context of the text is a meaning, in a popular point, I think the environment is better.

....
Lin shouted, "Ah also!" ”
....

Q: This sentence Lin "Ah also" expressed Lin what kind of heart?
Answer: Ah, your mother's head!

See, an article, to you excerpt a paragraph, not before, you do not understand, because there is context, is the language environment exists, a word of what, to be inferred through the context (the context of the article).

subroutine to the program, the process of the operating system, and even the application of a screen to the app, is a truth.

The program executes the partial arrival subroutine, the subroutine obtains the result, uses some results before the program (including but not limited to the external variable value, external object and so on);

App Click a button to enter a new interface, but also to save the screen you are jumping over the information, so that you can click back to the right to jump back, if not sure will not jump back correctly.

Look at these are the context of a typical example, understand the environment can be, (and context, although called context, but the program is generally only the above, just called the pleasant call context. The process interrupt is on the OS, but it doesn't make any difference to the other incoming object parameters without telling the main question.

However, the context is often used to describe several features:
    1. The part (component) that is passed into the context requires frequent access to the context's data and call function. The context has a strong reliance on the implementation of the foundation based on the context.
    2. The context is required by the majority (component), and in the software implementation part of the context, a single instantiation occurs under a scene and is then called by multiple partial (component) instance objects. Local globals occur.
    3. The context will hold a lot of state data.
    4. Coder habits, name selection difficult under the gluing products.

In addition to the context of the Chinese translation is who thought out, stand out I promise not to hit you. Other languages do not know.
The complete expression in Scheme should be the context of E in E, where E is an expression and E is a subexpression of the expression.
If there are subexpression 2 in (+ 1 2 3), then 2 has a context in (+ 1 2 3).
In Scheme, the context is a process (that is, a function).
Constructing this function is simple, the first step is to dig out the expression, with the hole (hole) occupy the position.
(+ 1 ~ 3), ~ denotes void.
The second step is to wrap the result of the previous step with a lambda to get the function.
(Lambda (~) (+ 1 ~ 3)). That is, 2 in the (+ 1 2 3) context.
Similarly (+ 2 3) the context in (/(+ 2 3) 4) is a function (lambda (~) (/~ 4)).

The context has a nature and the original expression is obtained when the context is invoked with the original subexpression.
(Lambda (~) (+ 1 ~ 3)) 2);; + = (+ 1 2 3)
(Lambda (~) (/~ 4)) (+ 2 3));; = (/(+ 2 3) 4)

Because the context has this nature, it is convenient to use the context to explain the concepts of fixed points (Y-combinations) and continuations. In linguistics, semantics (semantics) does not include context, and pragmatics (pragmatics) takes into account the influence of context on semantics.

In programming, that is, some programming artifacts (such as functions) need to take into account the compile/run environment at that time in order to understand its semantic/operational results. There is no doubt about understanding the concept of stateless. Based on the session, each processing module's communication requires a session recognition identifier and a content container exchange, which is the context. Generally want to have an object to save the state, can not think of a good name and then called the context of the simple is a state, when interacting with other modules, other modules after the execution of the notification, through the context you can know before the interaction of your module is a kind of state , then you can do the corresponding processing according to this state.
  • 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.