float init 0 request
claptrap
clap at trap.com
Sat Aug 15 09:58:07 UTC 2026
On Friday, 14 August 2026 at 17:26:04 UTC, Walter Bright wrote:
> On 8/14/2026 12:05 AM, Alexandru Ermicioi wrote:
>> Why not make it an error, a float that is not explicitly
>> initialized? Would be way better than implicit nan
>> initialization, right?
>
> Because then you wind up with:
>
> ```d
> float f = 0; // shut up the spurious compiler error message
> ...
> initialize(&f); // the actual initialization
> ```
> The 0 initialization is inserted to shut up the compiler, and
> it will take the reviewer a bit of time wondering why f was
> initialized to the wrong value.
>
> In other words, redundant/vacuous assignments are a code smell.
>
> It's a small point, but D is an elegant language, and requiring
> people to write smelly code is not elegant.
And yet that is exactly what you have the compiler doing,
inserting a spurious redundant assignment by default, it's just
as smelly.
More information about the Digitalmars-d
mailing list