0

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

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.

I think they mean programming using references types (e.g. classes) is the way to go versus programming using values types (e.g. 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

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

Ali
  • 21
  • 3
  • 2
    In C++, classes and structs are basically the same. Their difference certainly has no relation to reference vs. value semantics. – juanchopanza Jul 23 '12 at 13:44
  • You do notice that "the book is worthless" was written 6 months *before* the book was published? How did they know? – Bo Persson Jul 23 '12 at 14:26

1 Answers1

2

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. "Achilleas Margaritis" is complaining that the book uses vector<int> and he thinks that in reality you usually have vector<int*>. (I obviously disagree).

"non-lineair mutable state" seems to be what I call non-orthogonal state. E.g. 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. That's true if you're managing char[] yourself, but the mutators of std::string behave far mroe reasonable.

MSalters
  • 173,980
  • 10
  • 155
  • 350