模糊推理 控制 易于实现_代码“易于推理”是什么意思?

模糊推理 控制 易于实现

by Preethi Kasireddy

通过Preethi Kasireddy

代码“易于推理”是什么意思? (What does it mean when code is “easy to reason about”?)

You’ve probably heard the expression “easy to reason about” enough times to make your ears bleed.

您可能已经听过“易于推理”的表达,足以让您的耳朵流血。

The first time I heard this expression, I had no idea what the person meant by it.

第一次听到这种表达时,我不知道这个人是什么意思。

Does it mean functions that are easy to understand?

它是否意味着功能易于理解?

Does it mean functions that work properly?

这是否意味着功能正常工作?

Does it mean functions that are easy to analyze?

它是否意味着易于分析的功能?

After a while, I’d heard “easy to reason about” in so many contexts that I figured it was just another semi-meaningless developer buzzword.

一段时间后,我在很多情况下都听到“容易推理”,以至于我认为这只是另一个无意义的开发人员流行语。

…But is it really meaningless?

…但这真的没有意义吗?

The truth is, the expression does have a significant meaning. It captures a fairly complex idea, which makes decoding it a bit tricky. Trickiness aside, having a high-level understanding of what “easy to reason about” code looks like absolutely helps us write better programs.

事实是,该表达确实具有重要意义。 它捕获了一个相当复杂的想法,这使其解码起来有些棘手。 除了棘手的问题外,对“易于推理”的代码看起来有高层的了解绝对可以帮助我们编写更好的程序。

To that end, this post will be dedicated to dissecting the expression “easy to reason about” as it relates to the technical conversations we have as developers.

为此,本文将专门剖析“易于推理”的表达方式,因为它与我们作为开发人员进行的技术对话有关。

了解程序的行为 (Understanding your program’s behavior)

Once you’ve written a piece of code, you typically also want to understand the program’s behavior, how it interacts with other parts of the program, and the properties it exhibits.

一旦编写了一段代码,您通常还希望了解程序的行为,程序与程序其他部分的交互方式以及所显示的属性。

For example, take the piece of code below. This should multiply an array of numbers by 3.

例如,采用下面的代码。 这应该将数字数组乘以3。

How can we test that it works as intended? One logical way is to pass a bunch of arrays as input and ensure that it always returns the array with each item multiplied by 3.

我们如何测试它是否按预期工作? 一种逻辑方法是传递一堆数组作为输入,并确保它总是返回每个项目乘以3的数组。

Looks good so far. We’ve tested that the function does what we want it to do.

到目前为止看起来不错。 我们已经测试过该功能可以完成我们想要的功能。

But how do we know it doesn’t do what we don’t want it to do? For instance, with careful inspection, we can see that the function mutates the original array.

但是,我们如何知道它没有做我们希望做的事情? 例如,通过仔细检查,我们可以看到该函数对原始数组进行了变异。

Is that what we intended? What if we need references to both the original array and the resulting array? Too bad, I guess.

那是我们想要的吗? 如果我们需要同时引用原始数组和结果数组该怎么办&

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值