C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Compact Initialization Syntax

From: Tiago Freire <tmiguelf_at_[hidden]>
Date: Sun, 8 Jun 2025 22:01:22 +0000
I concur with the previous 2 points.
float{} already has a meaning, so it could be problematic.
And the amount of times I've initialized multiple variables in the same declaration in the past 5 years is almost none existent, I've pretty much stopped doing that as part of good standard practices.



________________________________
From: Std-Proposals <std-proposals-bounces_at_[hidden]> on behalf of Jeremy Rifkin via Std-Proposals <std-proposals_at_[hidden]>
Sent: Sunday, June 8, 2025 10:27:27 PM
To: std-proposals_at_[hidden] <std-proposals_at_[hidden]>
Cc: Jeremy Rifkin <rifkin.jer_at_[hidden]m>
Subject: Re: [std-proposals] Compact Initialization Syntax

Hi,
Is this really so bad?

float a = 0;
float b = 0;
float c = 0;
float d = 0;
float a1 = 0.1f;
float b1 = 0.1f;
float c1 = 0.1f;
float d1 = 0.1f;

Jeremy


On Sun, Jun 8, 2025 at 3:08 PM Smith, Jim via Std-Proposals <std-proposals_at_[hidden]<mailto:std-proposals_at_[hidden]>> wrote:
Hi All,

I suggest the following:

float{} a, b, c, d; // Initializes all variables to zero
float{0.1f} a1, b1, c1, d1; // Initializes all variables to 0.1

Rationale:

    - Conciseness: This approach reduces redundancy, making the code more compact and readable by eliminating the need to repeat initialization values for each variable.

    - Consistency: When initializing multiple variables with the same value, it streamlines the process, avoiding repetitive declarations.

    - Clarity of Intent: The use of {} makes it immediately clear that each variable is being initialized to a specific value, without the clutter of individual assignments.

    - Cleaner Declarations: Especially in cases with many variables, this approach allows for a cleaner, more organized declaration without compromising on clarity.


Best regards,
James S.

--
Std-Proposals mailing list
Std-Proposals_at_[hidden]g<mailto:Std-Proposals_at_[hidden]>
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-06-08 22:01:26