www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Initializers are Evil!

reply nazo <lovesyao gmail.com> writes:
I don't like initializer because need to remember two grammars.
dmd already support many literals so can replace initializers easily 
with expressions, I think.
Most script languages like Javascript don't have any initializers.
Why special-case initializers?

#Sorry for my poor English
Jun 21 2007
parent reply mandel <mandel mailinator.com> writes:
Initialization is a good way to prevent undefined behavior.
But you can also disable initialization when you assign void:
class Foo
{
 int number = void; //initialization disabled
}

nazo Wrote:

 I don't like initializer because need to remember two grammars.
 dmd already support many literals so can replace initializers easily 
 with expressions, I think.
 Most script languages like Javascript don't have any initializers.
 Why special-case initializers?
 
 #Sorry for my poor English

Jun 21 2007
parent reply nazo <lovesyao gmail.com> writes:
I think that this is better for disable-initialization:
class Foo
{
  auto number = int.void; //assign nothing
}

mandel さんは書きました:
 Initialization is a good way to prevent undefined behavior.
 But you can also disable initialization when you assign void:
 class Foo
 {
  int number = void; //initialization disabled
 }
 
 nazo Wrote:
 
 I don't like initializer because need to remember two grammars.
 dmd already support many literals so can replace initializers easily 
 with expressions, I think.
 Most script languages like Javascript don't have any initializers.
 Why special-case initializers?

 #Sorry for my poor English


Jun 21 2007
parent reply dennis luehring <dl.soluz gmx.net> writes:
nazo schrieb:
auto number = int.void


are there different types of void? int.void != float.void != double.void? why on earth should void be type-dependend? it isn't! and typeof(int.void) should be void? why change the auto semantic? ciao dennis
Jun 21 2007
parent nazo <lovesyao gmail.com> writes:
dennis luehring さんは書きました:
 nazo schrieb:
  >>auto number = int.void
 
 are there different types of void?
 int.void != float.void != double.void?

 why on earth should void be type-dependend? it isn't!

But module's type is also void. so I think that it is not good.
 and typeof(int.void) should be void?

compiler should optimize VoidExp for assign.
 why change the auto semantic?

 
 ciao dennis

Jun 22 2007