Poll: Would you like to try const-by-default or not?
eao197
eao197 at intervale.ru
Mon Jun 11 05:06:06 PDT 2007
On Sun, 10 Jun 2007 18:46:40 +0400, Jarrett Billingsley
<kb3ctd2 at yahoo.com> wrote:
> 1) C++ style const, where you mark anything that should be const as such.
I vote for this.
> 2) Parameters are const-by-default, and must be marked mutable otherwise.
> Locals, fields etc. are still mutable by default.
As for me this option seems strange in some cases. For example:
class Logger {
// Non-const methods.
void fatal( char[] message );
void error( char[] message );
...
}
class ExecutionContext {
// There an instance of Logger is not const.
Logger logger_;
this(
// But there an instance of logger is const.
Logger logger )
{
logger_ = cast(Logger) logger;
...
}
}
I easily can understand code like:
class ExecutionContext {
mutable Logger logger_; // or ref Logger logger_;
this( mutable Logger logger ) { ... }
}
or
class ExecutionContext {
const Logger logger_;
this( const Logger logger ) { ... }
}
when type declarations for fields and parameters are the same.
--
Regards,
Yauheni Akhotnikau
More information about the Digitalmars-d
mailing list