const. I hate const in Javascript, because it's not const at all - but final. In Kotlin, this'd be val instead of var - but even then, this is a fixed binding, and not an invariant.
So you can cook the turkey, for sure, you just can't change which turkey you're cooking.
In C++, on the other hand, const Turkey turkey means an invariant Turkey. const Turkey * turkey means a pointer to a constant Turkey. In either case, you couldn't call Turkey::cook(), but you could call Turkey::price() const, since that's a const method. But in the latter case, you could assign (or "rebind") turkey to point at a different instance. To prevent that, we can say const Turkey * const turkey, which is getting to be a mouthful. C++ also has references, which are non-rebindable pointers with easier syntax: const Turkey & turkey is equivalent to that last double-const pointer example.
And now I'm reminded why I prefer to code in Python or JS. Listening to the C++ version hurts my brain. A fragile Front-End guy and I'm thankful to not be doing C++
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
const
. I hateconst
in Javascript, because it's notconst
at all - butfinal
. In Kotlin, this'd beval
instead ofvar
- but even then, this is a fixed binding, and not an invariant.So you can cook the turkey, for sure, you just can't change which turkey you're cooking.
In C++, on the other hand,
const Turkey turkey
means an invariant Turkey.const Turkey * turkey
means a pointer to a constant Turkey. In either case, you couldn't callTurkey::cook()
, but you could callTurkey::price() const
, since that's a const method. But in the latter case, you could assign (or "rebind")turkey
to point at a different instance. To prevent that, we can sayconst Turkey * const turkey
, which is getting to be a mouthful. C++ also has references, which are non-rebindable pointers with easier syntax:const Turkey & turkey
is equivalent to that last double-const pointer example.All these headaches might be a good reason to learn Functional Programming... 🤔
And now I'm reminded why I prefer to code in Python or JS. Listening to the C++ version hurts my brain. A fragile Front-End guy and I'm thankful to not be doing C++