On Wednesday, 11 May 2022 at 18:18:18 UTC, Walter Bright wrote:
>On 5/11/2022 3:48 AM, IGotD- wrote:
>C# went the other way, no const parameters at all. Maybe because it doesn't make much sense because there is a lot of runtime violations of const underneath. Anyway, I like the C# aproach better because it is simpler for the programmer.
It's not simpler for someone trying to read the code. Function documentation almost never says "by the way, this getValue
function also tweaks the database."
Good documentation will. Really const doesn't help with making code more readable either. I avoided using const in D cause it just got in the way more than it was helping. The most useful feature for const to exist in C++ was that it allows you to do const T&
which will allow you to pass anything to that function, rvalue or lvalue without making a copy. D doesn't do this though. I think C# did the right call in excluding it, it would have just added complexity without much benefit.
Another problem is that all this badging tend to get out of hand and it breeds more badges until it doesn't mean anything. For example what will happen if D adds a mutable attribute?
It already has a mutable attribute - nothing!
I think he means a mutable attribute that allows you to modify a value even if the object is const. Like C++'s mutable.