编程术语_伟大的编程术语烘烤

编程术语

by Preethi Kasireddy

通过Preethi Kasireddy

伟大的编程术语烘烤 (The Great Programming Jargon Bake-off)

Imperative vs. Declarative. Pure vs. Impure. Static vs. Dynamic.

命令式与声明式。 纯与不纯。 静态与动态。

Terminology like this is sprinkled throughout programming blog posts, conference talks, papers, and text books.

这样的术语遍布编程博客文章,会议演讲,论文和教科书中。

But don’t be turned off by this jargon. Let’s jump right in and break some of these concepts down, so you can understand what all these developers around you are talking about.

但是,不要被这种术语关闭。 让我们直接进入其中,分解其中一些概念,以便您了解周围所有这些开发人员在谈论什么。

静态打字与动态打字 (Static vs. Dynamic Typing)

This is about when a type information is acquired — either at compile time or at runtime.

这与在编译时或运行时获取类型信息的时间有关。

You can use this type information to detect type errors. A type error is when a value is not of the expected type.

您可以使用此类型信息来检测类型错误。 类型错误是当值不是预期的类型时。

静态类型检查 (Static Type Checking)

The process of verifying the type safety of a program based on analysis of a program’s source code. In other words, type checking happens at compile time, allowing type errors to be detected sooner.

基于对程序源代码的分析来验证程序的类型安全性的过程。 换句话说,类型检查在编译时进行,从而可以更快地检测到类型错误。

动态类型检查 (Dynamic Type Checking)

The process of verifying the type safety of a program at runtime. With dynamic type checking, type errors occur at runtime.

在运行时验证程序的类型安全的过程。 使用动态类型检查,在运行时会发生类型错误。

强打字与弱打字 (Strong vs. Weak typing)

It’s important to note strong vs. weak typing doesn’t have a universally-agreed-upon technical meaning. For example, even though Java is statically typed, every time you use reflection or a cast, you’re deferring the type check to run time.

重要的是要注意强类型与弱类型没有统一的技术含义。 例如,即使Java是静态类型的,但每次使用反射或强制转换时,都将类型检查推迟到运行时。

Similarly, most strongly-typed languages will still automatically convert between integers and floats. Hence, you should avoid using these terms because calling a type system “strong” or “weak” by itself does not communicate very much.

同样,大多数强类型语言仍将在整数和浮点数之间自动转换。 因此,应避免使用这些术语,因为仅将类型系统称为“强”或“弱”就不能很好地沟通。

强类型 (Strongly Typed)

In a strongly typed language, the type of a construct does not change — an int is always an int, and trying to use it as a string will result in an error.

在强类型语言中,构造的类型不会更改int始终是int ,尝试将其用作string将导致错误。

弱打字 (Weakly typed)

Weak typing means that the type of a construct can change depending on context. For example, in a weakly-typed language, the string “123” may be treated as the number 123 if you add another number to it.

弱类型意味着构造的类型可以根据上下文而改变。 例如,在弱类型语言中,如果将字符串“ 123”添加到另一个数字,则可以将其视为数字123。

It generally means the type system can be subverted (invalidating any guarantees) because you can cast a value of one type to another.

通常,这意味着可以颠覆类型系统(使任何保证无效),因为您可以将一种类型的值转换为另一种类型。

可变与不可变数据 (Mutable vs. Immutable data)

不变的数据 (Immutable data)

When an object is not modifiable after it has been created, you can say it’s “immutable” which is a fancy word for “unchangable.” This means you’ll instead allocate a new value for every change.

当对象创建后不可修改时,您可以说它是“不可变的”,这是“不可更改”的奇特词。 这意味着您将为每个更改分配一个新值。

可变数据 (Mutable data)

When you can modify an object after its creation, it’s “mutable.” When you have a reference to a mutable object, for instance, the contents of the object can change.

创建对象后可以对其进行修改时,它就是“可变的”。 例如,当您引用可变对象时,对象的内容可能会更改。

纯函数与不纯函数 (Pure vs. Impure functions)

纯功能 (Pure functions)

A pure function has two qualities:

纯函数具有两种性质:

  1. It relies only on the input provided — and not on any external state that may change during its evaluation or in between calls.

    它仅依赖于提供的输入,而不依赖于评估期间或两次调用之间可能更改的任何外部状态。
  2. It doesn’t cause any semantically observable side effects, such as modifying a global object or a parameter passed by reference.

    它不会引起任何语义上可观察到的副作用,例如修改全局对象或通过引用传递的参数。
功能不纯 (Impure functions)

Any function that does not meet those two requirements for a pure function is “impure.”

任何不满足纯功能的这两个要求的功能都是“不纯的”。

懒惰评估与急切评估 (Lazy Evaluation vs. Eager Evaluation)

懒惰评估 (Lazy evaluation)

Lazy evaluation does not evaluate function arguments unless their values are required to evaluate the function call itself.

延迟求值不会求值函数自变量,除非需要其值来求值函数调用本身。

In other words, expressions are only evaluated when evaluating another expression which are dependent on the current expression.

换句话说,仅在评估依赖于当前表达式的另一个表达式时才评估表达式。

Laziness allows programs to calculate data structures that are potentially infinite without crashing.

惰性允许程序计算可能无限的数据结构而不会崩溃。

渴望评估 (Eager evaluation)

Eager evaluation — also known as strict evaluation — always fully evaluates function arguments before invoking the function. In other words, an expression is evaluated as soon as it is bound to a variable.

急切的评估(也称为严格评估)始终在调用函数之前全面评估函数参数。 换句话说,将表达式绑定到变量后立即对其求值。

声明式与命令式 (Declarative vs. Imperative)

声明式编程 (Declarative programming)

Declarative programs express a set of operations without revealing how they’re implemented, or how data flows through them. They focus on “what” the program should accomplish (by using expressions to describe the logic) rather than “how” the program should achieve the result.

声明式程序表达了一组操作,而没有透露它们是如何实现的,或者数据如何流过它们。 他们专注于程序应完成的“工作”(通过使用表达式来描述逻辑),而不是程序应如何实现的结果。

One example of declarative programming is SQL. SQL queries are composed of statements that describe what the outcome of a query should look like, while abstracting over the internal process for how the data is retrieved:

声明式编程的一个示例是SQL。 SQL查询由描述查询结果外观的语句组成,同时抽象化内部过程以获取数据:

SELECT EMP_ID, FIRST_NAME, LAST_NAMEFROM EMPLOYEESWHERE CITY = ‘SAN FRANCISCO’ORDER BY EMP_ID;

Here’s an example of declarative code:

这是声明性代码的示例:

命令式编程 (Imperative programming)

Imperative programming focuses on describing how a program should achieve a result by using statements that specify control flow or state changes. It uses a sequence of statements to compute a result.

命令式编程着重于描述程序应如何通过使用指定控制流或状态更改的语句来获得结果。 它使用一系列语句来计算结果。

Here’s an example of imperative code:

这是命令式代码的示例:

有状态与无状态 (Stateful vs. Stateless)

A state is a sequence of values calculated progressively, which contains the intermediate results of a computation.

状态是逐步计算的值的序列,其中包含计算的中间结果。

有状态的 (Stateful)

Stateful programs have some mechanism to keep track of and update state. They have some memory of the past, and remember previous transactions that may affect the current transaction.

有状态程序具有某种机制来跟踪和更新状态。 他们具有过去的记忆,并记住可能影响当前交易的先前交易。

无状态 (Stateless)

Stateless programs, on the other hand, doesn’t keep track of state. There’s no memory of the past. Every transaction is performed as if it were being done for the very first time. Stateless programs will give the same response to the same request, function, or method call — every single time.

另一方面,无状态程序无法跟踪状态。 没有过去的记忆。 每笔交易都好像是第一次完成一样。 无状态程序每次都会对相同的请求,函数或方法调用给出相同的响应。

功能与面向对象 (Functional vs. Object-Oriented)

功能性 (Functional)

Functional programming is a paradigm that places a major emphasis on the use of functions. The goal of functional programming is to use functions to abstract control flows and operations on data, and to avoid side effects.

函数式编程是主要强调函数使用的范例。 函数式编程的目的是使用函数抽象化数据上的控制流和操作,并避免产生副作用。

So functional programming uses pure functions and avoids mutable data, which in turn provides referential transparency.

因此,函数式编程使用纯函数,并避免了可变数据,从而提供了参照透明性。

A function has referential transparency when you can freely replace an expression with its value and not change the behavior of the program. Said a bit differently: for a given input, it always returns the same results.

当您可以用表达式的值随意替换表达式而不更改程序的行为时,该函数具有引用透明性。 说的有点不同:对于给定的输入,它总是返回相同的结果。

Some examples languages that emphasize functional programming include Haskell, Lisp, Clojure, and Elm. But you can use functional programming concepts in most languages, including JavaScript.

强调函数式编程的一些示例语言包括Haskell,Lisp,Clojure和Elm。 但是您可以使用大多数语言(包括JavaScript)使用函数式编程概念。

面向对象 (Object Oriented)

The Object Oriented programming paradigm places major emphasis on the use of objects. This results in programs that are made out of objects that interact with one another. These objects can contain data (in the form of fields or attributes) and behavior (in the form of methods).

面向对象编程范例主要强调对象的使用。 这将导致程序由相互交互的对象组成。 这些对象可以包含数据(以字段或属性的形式)和行为(以方法的形式)。

It’s a style of partitioning (or encapsulating) the state of a program via objects to make analyzing the effect of changes tractable [1].

这是一种通过对象对程序状态进行分区(或封装)的样式,以使分析变更的结果变得容易处理[1]。

Moreoever, object-oriented programs uses inheritance and/or composition as their main mechanisms for code reuse. Inheritance means that a new class can be defined in terms of existing classes by specifying just how the new class is different. It represents an “is-a” relationship (e.g. a Bird class which extends an Animal class). Composition, on the other hand, is when classes contain instances of other classes that implement the desired functionality. It represents a “has a” relationship (e.g. a Bird class has an instance of a Wing class as it’s member).

此外,面向对象的程序使用继承和/或组合作为代码重用的主要机制。 继承意味着可以通过指定新类的不同之处来根据现有类定义新类。 它表示“是”关系(例如,扩展动物类的Bird类)。 另一方面,组合是当类包含实现所需功能的其他类的实例时。 它表示“具有”关系(例如Bird类作为其成员具有Wing类的实例)。

Polymorphism is also an important mechanism for code reuse in object oriented programming. It’s when a language can process objects differently depending on their data type or class.

多态性也是面向对象编程中代码重用的重要机制。 这是一种语言可以根据对象的数据类型或类对对象进行不同处理的时候。

Some examples languages that emphasize object oriented programming include Java, C++, Ruby. Again, you can apply these concepts in most languages, including JavaScript.

强调面向对象编程的一些示例语言包括Java,C ++,Ruby。 同样,您可以将这些概念应用于大多数语言,包括JavaScript。

确定性与非确定性 (Deterministic vs. Nondeterministic)

确定性 (Deterministic)

Deterministic programs always return the same result any time they’re called with a specific set of input values and the same given state.

确定性程序每次以一组特定的输入值和相同的给定状态调用时,总是返回相同的结果。

不确定的 (Nondeterministic)

Nondeterministic programs may return different results each time they’re called, even with the same specific set of input values and initial state.

不确定性程序每次调用时都可能返回不同的结果,即使使用相同的特定输入值集和初始状态也是如此。

Nondeterminism is a property of any concurrent system — that is, any system where multiple tasks can happen at the same time by running on different threads. A concurrent algorithm that is mutating state might perform differently on each time, depending upon which thread the scheduler decides to execute.

非确定性是任何并发系统(即,在不同线程上运行可以同时发生多个任务的系统)的属性。 根据调度程序决定执行哪个线程,正在改变状态的并发算法在每次执行时可能会有所不同。

For example:

例如:

declare Xthread X=1 endthread X=2 end

The execution order of the two threads is not fixed. We don’t know whether X will be bound to 1 or 2. The system will choose during the program’s execution, and it’s free to choose which thread to execute first.

两个线程的执行顺序不固定。 我们不知道X是绑定到1还是2。系统将在程序执行期间进行选择,并且可以自由选择首先执行哪个线程。

Another example of non-determinism:

非确定性的另一个示例:

! 大功告成 (Phew! We’re done.)

As always, your feedback and input is really important to me. I read and consider every single comment, so please don’t shy away from responding!

与往常一样,您的反馈和意见对我来说非常重要。 我阅读并考虑了每条评论,因此请不要回避!

Finally, you can also check out the Prezi presentation I built for this article.

最后,您还可以查看我为本文构建的Prezi演示文稿

[1] Thank you to Kent Beck for his input on this.

[1] 谢谢肯特·贝克在这方面的投入。

翻译自: https://www.freecodecamp.org/news/programming-mental-models-47ccc65eb334/

编程术语

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值