简体   繁体   English

有人可以解释这些编程术语:引用语义,非线性可变状态吗?

[英]Can someone explain these programming terms: reference semantics, non-linear mutable state?

Can you explain these terms for me: reference semantics and value semantics (and how they contrast) and non-linear mutable state. 你能为我解释这些术语:引用语义和值语义(以及它们如何对比)和非线性可变状态。 They are mentioned in the comments to the book review in this link http://lambda-the-ultimate.org/node/2849 这个链接的评论中提到了它们http://lambda-the-ultimate.org/node/2849

The book is of course "Programming: Principles and Practice Using C++" Many commentators are calling the book useless for teaching for ignoring reference semantics, I can almost guess what this means, but I am not 100% sure. 这本书当然是“编程:使用C ++的原理和实践”很多评论家都认为这本书对于忽略参考语义的教学毫无用处,我几乎可以猜到这意味着什么,但我并不是100%肯定。

I think they mean programming using references types (eg classes) is the way to go versus programming using values types (eg struct) 我认为他们的意思是使用引用类型(例如类)进行编程是使用值类型编程的方式(例如struct)

I doubt my understanding, because I doubt bjarne stroustup would do that, C++ is about classes ... so I think there is something deeper about the term reference semantics, something less than obvious at least to me 我怀疑我的理解,因为我怀疑bjarne stroustup会这样做,C ++是关于类...所以我认为术语引用语义有更深层次的东西,至少对我来说不是很明显

Also the terms linear and non-linear states were used, which seem intriguing, and which I dont understand. 此外,使用线性和非线性状态这一术语,这看起来很有趣,我不明白。

So if someone can explain those terms, that would be great 因此,如果有人能解释这些条款,那就太棒了

Don't read too much into those comments. 不要过多地阅读这些评论。 They're not that enlightning. 他们不是那么开心。

Basically, "reference semantics" means that you're using int* whereas value semantics mean that you're using int . 基本上,“引用语义”意味着您使用int*而值语义意味着您使用int "Achilleas Margaritis" is complaining that the book uses vector<int> and he thinks that in reality you usually have vector<int*> . “Achilleas Margaritis”抱怨说这本书使用了vector<int> ,他认为实际上你通常有vector<int*> (I obviously disagree). (我显然不同意)。

"non-lineair mutable state" seems to be what I call non-orthogonal state. “非线性可变状态”似乎就是我称之为非正交状态。 Eg you can set Foo.x to 7 and Foo.y to 8 unless Foo.z is 9. In particular, it seems to mean that the set of allowed mutations depends non-trivially on previous operations. 例如,除非Foo.z为9,否则你可以将Foo.x设置为7,将Foo.y设置为8.特别是,它似乎意味着允许的突变集合在以前的操作中非常简单。 That's true if you're managing char[] yourself, but the mutators of std::string behave far mroe reasonable. 如果你自己管理char[] ,那是正确的,但是std::string的mutators行为很合理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM