是“可变的” 与“可修改”一词相同 与字符串有关?

发布于 2024-07-14 17:33:26 字数 84 浏览 6 评论 0原文

当我们谈论字符串是可变的时,这是否与使用“可更改”或“可修改”一词同义,或者是否有一些额外的细微差别来解释为什么使用这个术语而不是“可修改”等更简单的词?

When we talk about strings as being mutable, is this synonymous with using the word 'changeable' or 'modifiable' or is there some additional nuance to explain why this jargon is used instead of a simpler word like 'modifiable'?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

烦人精 2024-07-21 17:33:26

我认为“可变”这个词是一个不错的选择。

如果你使用“可修改”,那就不太清楚了。 例如,如果您的字符串是堆分配类型,那么当您说您正在修改“字符串”时,并不清楚您是在更改堆上的数据(字符串的内容)还是字符串的堆指针。

然而,对我来说,“可变”表明字符串的实际数据正在改变。 我认为这是因为它与变异同根。 如果某些东西正在变异,它并不是从查看 A 变为查看 B(即:更改指针),而是变异自身,或者(迭代地)变成原来不是的东西。

I think the word "mutable" is a good option for this.

If you used "modifiable", it would be less clear. For example, if your string is a heap allocated type, when you say you are modifying the "string", it's not clear whether you're changing the data on the heap (the string's contents) or the string's heap pointer.

However, "mutable" suggests that the string's actual data is changing, to me. I think it's due to it being the same root as to mutate. If something is mutating, it's not changing from looking at A to looking at B (ie: changing a pointer), but rather mutating itself, or becoming (iteratively) something it was not originally.

白芷 2024-07-21 17:33:26

可变对象是在创建后可以修改的对象。 所以在某种程度上,它是“可修改”的同义词。 “可变”一词的意思是“有责任或可能发生变化或改变”。 我认为这听起来比“可修改”更好。

A mutable object is an object that can be modified after it has been created. So in a way, it is synonymous with "modifiable." The word "mutable" means "liable or subject to change or alteration." I think it sounds better than "modifiable."

不爱素颜 2024-07-21 17:33:26
  • 可变的
    • “承担责任或可能发生变更或变更。”
  • 可修改的
    • “稍微改变……的形式或品质;部分改变;”

相反

  • 不可变
    • “不可变的;不变的;不变的”
  • 不可修改
    • “无法在形式、特征或强度上进行修改”

在编程中,您更常听到“可变”和“不可变”这两个术语,而不是“可修改”和“不可修改”这两个术语。 但我认为可以肯定地说,无论哪种方式都具有相同的含义。

但是在罗马时......所以您应该使用可变和不可变,因为它们是更常用的术语(至少根据我的经验)。

至于为何做出这样的选择? 我问我的岳母(她很爱说话:-),从非编程的角度来看,“可变”比“可修改”更短……对我来说,这似乎是一个足够的理由。

  • mutable
    • "liable or subject to change or alteration."
  • modifiable
    • "to change somewhat the form or qualities of; alter partially;"

conversely

  • immutable
    • "not mutable; unchangeable; changeless"
  • unmodifiable
    • "incapable of being modified in form or character or strength"

In programming you more often hear the terms mutable and immutable than you do modifiable and unmodifiable. However I think it is safe to say that either way has the same meaning.

But when in Rome... so you should use mutable and immutable as they are the more commonly used terms (at least in my experience).

As to why that choice? I asked my mother in law (she is up on words :-) and from a non-programming point of view "mutable" is shorter then "modifiable"... seems likely enough of a reason to me.

三生路 2024-07-21 17:33:26

是的,可变是指在创建后可以更改的对象,而不可变是指不能更改的对象。 可变的字面意思是“变异的能力”,我认为这完全符合可变对象的行为方式。

Yes, mutable is the term for an object that is capable of being changed after it is created, whereas immutable refers to an object that cannot change. Mutable literally means "ability to mutate" which I think fits perfectly with how mutable objects behave.

酒与心事 2024-07-21 17:33:26

特别是与字符串相关,在可变字符串中,如果将第一个字符从“A”更改为“B”,您仍然在内存中处理相同的字节; 其中之一刚刚采用了不同的值。 对于不可变字符串,即在 Java 中,将在内存中的新位置创建一个新对象,因为原始对象无法更改。

可变是一个合适的词来描述这一点,它的优点是不包含现实世界的含义或解释,这会导致精确使用变得困难。

Specifically in relation to strings, in a mutable string, if you change the first character from 'A' to 'B', you're still dealing with the same bytes in memory; one of them has just taken a different value. With immutable strings, i.e. in Java, a new object would be created at a new location in memory, because the original one cannot be changed.

Mutable is a decent word to describe that, and it has the advantage of not being loaded with real-world meanings or interpretations that would make it difficult to use precisely.

萌面超妹 2024-07-21 17:33:26

由于您没有指出您所谈论的具体上下文(因此,如果这是范围蠕变,请原谅我)...

.NET 中的字符串特别是不可变的,而不是可变的。 一旦它们被创建,就这样了。 他们永远不会改变。 如果尝试进行更改,则会创建新字符串,并释放旧字符串以进行垃圾回收。

And since you didn't point out the specific context you're speaking of (and so please forgive me if this is scope creep)...

Strings in .NET specifically are immutable, not mutable. Once they're created, that's it. They never change. If change attempts are made, new strings are created and the old ones get released for garbage collection.

彻夜缠绵 2024-07-21 17:33:26

以下是使用 java 作为示例的可变/不可变的非常简单的解释:

Mutable

  • 可以在不重新分配内存的情况下进行更改
  • a StringBuffer api 文档 是标准字符串类的可变版本

  • <要更改 String 类的标准值,您需要重新分配内存

我从未真正听说过使用术语“可修改”。

Here is a pretty simple explanation of mutable/immutable using java as an example:

Mutable

  • can be changed without reallocating memory
  • a StringBuffer api documentation is a mutable version the standard string class

  • to change the standard value of the String class you need to reallocate memory

I have never really heard of using the term modifiable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文