digitalmars.D - Re: Poll: Would you like to try const-by-default or not?
- Dan <murpsoft hotmail.com> Jun 12 2007
- "Craig Black" <cblack ara.com> Jun 12 2007
- Robert Fraser <fraserofthenight gmail.com> Jun 12 2007
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
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
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
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