www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Poll: Would you like to try const-by-default or not?

reply Dan <murpsoft hotmail.com> writes:
Another option is to not allow a default, and make everyone explicitly define
the storage class of their data; just like they have to specify the type
explicitly.

Once that's in order, letting "auto" handle both type and storage class
automatically unless otherwise specified might work?

Just my three pennies (inflation).
Jun 12 2007
next sibling parent "Craig Black" <cblack ara.com> writes:
I prefer const-by-default for function parameters.  More often than not, 
parameters should be const, so it makes sense to make them const by default.

I think the argument against const by default is that it is not orthogonal 
because function parameters would require a different syntax than other 
variable declarations.  I disagree with that argument because I think 
function parameters are different enough from other kinds of variable 
declarations to justify a different syntax.

-Craig 
Jun 12 2007
prev sibling parent reply Robert Fraser <fraserofthenight gmail.com> writes:
Dan Wrote:

 Another option is to not allow a default, and make everyone explicitly define
the storage class of their data; just like they have to specify the type
explicitly.
 
 Once that's in order, letting "auto" handle both type and storage class
automatically unless otherwise specified might work?
 
 Just my three pennies (inflation).

I don't like this idea at all. Both "default" ways would only break some existing code, this would break all existing code. In addition, it just seems needlessly verbose, and I'm sure I'm not the only one who hates having to type a pointless "var" in front variables in JavaScript or "my" in strict Perl (I know this would be for parameters, but it's the same general idea).
Jun 12 2007
parent "Bent Rasmussen" <incredibleshrinkingsphere gmail.com> writes:
 I don't like this idea at all. Both "default" ways would only break some 
 existing code, this would break all existing code. In addition, it just 
 seems needlessly verbose, and I'm sure I'm not the only one who hates 
 having to type a

I agree.
 pointless "var" in front variables in JavaScript or "my" in strict Perl (I 
 know this would be for parameters, but it's the same general idea).

I don't see var as pointless; in global scope it's optional; in function scope it depends on whether you want it to be local or not. It's certainly less verbose than having to add type annotations. C# will have var as well, but with type-inference and probably some support in Visual Studio to show show inferred types. That, coupled with intellisense, should be a nice productivity boost. An all-const approach with var for mutables would be interesting, if feasible... It reminds me of Single Assignment C (SAC), although I've never tried that. Bent
Jun 12 2007