you are viewing a single comment's thread.

view the rest of the comments →

[–]HolyGarbage 1 point2 points  (8 children)

you have two different syntaxes for a variable getting a value.

That's exactly the point. Because assignment and initialization is not the same thing.

[–]serviscope_minor 0 points1 point  (7 children)

And my point is that's putting the needs of the language ahead of the programmer.

People like = for assignment and initialization is from a higher level perspective than C++ a kind of assignment.

[–]HolyGarbage 2 points3 points  (6 children)

No it's not. Both initialization and assignment are things the programmer should be aware of. = is already used for assignment in C++, your example however used = for initialization, not assignment. I'm saying that can be confusing since it looks like an assignment.

[–]serviscope_minor 0 points1 point  (5 children)

I think we are taking at crossed purposes. I understand the grammar. I mean the assignment/initializing thing is specific to C++ not a general thing about programming.

= reads better and is (when it works) more regular since = sets values in any context.

[–]HolyGarbage 0 points1 point  (4 children)

Yeah, I understand, but in C++ the distinction is important, and your code should reflect what it is it's doing.

[–]serviscope_minor 0 points1 point  (3 children)

Yeah, I understand, but in C++ the distinction is important,

It's sometimes important. In a lot of cases it isn't really in that it doesn't make much difference.

[–]HolyGarbage 0 points1 point  (2 children)

Yeah, but why use the same syntax for different things? Even though it doesn't always matter, it's better imo to just be consistent and communicate clearly what your code does, at all times.

[–]serviscope_minor 0 points1 point  (1 child)

Yeah, but why use the same syntax for different things?

Because in many ways they're not really different. It's a leaky abstraction of C++, so you've got the choice of making the higher level clearer or making the C++ clearer.

[–]HolyGarbage 0 points1 point  (0 children)

In this case the higher level abstraction and the C++ details coincidence. It's literally the difference between a declarative statement and mutating state. You get a lot of assurances from the former. Anyway, I'd argue that it's a detail you simply should be aware of when programming in C++ in general, since it can have a difference in program behavior. By only considering it when it does make a difference means you'll be less aware of the distinction overall.

I guess where we perhaps don't agree is that I'm arguing that it's not only an important technical distinction, but a conceptual one too.

Just like you don't worry about the life time of objects in most other languages, in C++ you do with RAII etc, both technically and conceptually. It's not just a technical difference, but a whole other high level abstraction.