www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - variable declaration question

reply Traveler Hauptman <th barrett.com> writes:
Sorry if I didn't read enough for this question...

Why are class declarations redundant?

Foo a = new Foo(2,3);

Why not

Foo a(2,3) = new;

Or

new Foo a(2,3),b(22,33);
Sep 20 2005
next sibling parent Chris Sauls <ibisbasenji gmail.com> writes:
Traveler Hauptman wrote:
 Sorry if I didn't read enough for this question...
 
 Why are class declarations redundant?
 
 Foo a = new Foo(2,3);
 
 Why not
 
 Foo a(2,3) = new;
 
 Or
 
 new Foo a(2,3),b(22,33);
 
Well, one (cheap/obvious) reason is this: you can declare an Object variable without creating an instance right away, so combining the decleration and instantiation syntaxes is unneccessary and possibly troublesome. Another (equally cheap/obvious) reason is that you can instantiate an Object outside of a decleration, such as passing a fully-formed dummy object to a function, or assigning later to an array or whatnot. So in short, a line like: Is /three/ things happening, any of which can happen with full independance. One, the decleration of a variable of type Object. Two, the instantiation of an object of class Object. Three, the assignment of a referance to an object to an Object variable. -- Chris Sauls
Sep 20 2005
prev sibling parent reply "Ben Hinkle" <bhinkle mathworks.com> writes:
"Traveler Hauptman" <th barrett.com> wrote in message 
news:dgptqk$1tha$1 digitaldaemon.com...
 Sorry if I didn't read enough for this question...

 Why are class declarations redundant?

 Foo a = new Foo(2,3);

 Why not

 Foo a(2,3) = new;

 Or

 new Foo a(2,3),b(22,33);
There have been threads on this before so you can check the archives for pros and cons of various ideas. My own personal favorite (outlined in http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/28198) is := for declare and init. On an off-D-topic, I've added := to TinyCC together with some other C experiments I've been wanted to try out (in particular I've been wondering about having to choose between Box, templates and Objects when trying to write generic code so I'm experimenting with fat-pointers as an alternative). See http://www.cxlang.org or the Google group http://groups.google.com/group/CXlang for what little info I put up so far. I haven't packaged up the compiler yet since I want to get dynamic dispatching working first so right now all that is available are some random thoughts on various goals.
Sep 21 2005
parent reply James Dunne <james.jdunne gmail.com> writes:
Ben Hinkle wrote:
 "Traveler Hauptman" <th barrett.com> wrote in message 
 news:dgptqk$1tha$1 digitaldaemon.com...
 
Sorry if I didn't read enough for this question...

Why are class declarations redundant?

Foo a = new Foo(2,3);

Why not

Foo a(2,3) = new;

Or

new Foo a(2,3),b(22,33);
There have been threads on this before so you can check the archives for pros and cons of various ideas. My own personal favorite (outlined in http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/28198) is := for declare and init. On an off-D-topic, I've added := to TinyCC together with some other C experiments I've been wanted to try out (in particular I've been wondering about having to choose between Box, templates and Objects when trying to write generic code so I'm experimenting with fat-pointers as an alternative). See http://www.cxlang.org or the Google group http://groups.google.com/group/CXlang for what little info I put up so far. I haven't packaged up the compiler yet since I want to get dynamic dispatching working first so right now all that is available are some random thoughts on various goals.
Sounds very cool. Try to get some support for synchronization and threads into the language! Could you clarify what exactly you mean by dynamic dispatching? As I understand it, you can define any C function to extend a Cx "class"? Am I asking too many questions? TinyCC is awesome. I was experimenting with that a couple months ago. I hacked around with it and added the ~ operator to the C language. The only thing that put me off of TinyCC at the time (for any serious language fork development) was the lack of support for Windows compilation. I believe, in the latest version, there is Windows support.
Sep 21 2005
parent "Ben Hinkle" <ben.hinkle gmail.com> writes:
 Sounds very cool.  Try to get some support for synchronization and threads 
 into the language!
ok - though don't hold your breath. I'm still just poking around.
 Could you clarify what exactly you mean by dynamic dispatching?
Just the generic sense of run-time binding: http://en.wikipedia.org/wiki/Dynamic_dispatch
 As I understand it, you can define any C function to extend a Cx "class"?
Well - I think of it as being able to add methods that aren't mentioned in the class definition. That is, the set of methods of a data type aren't defined by the type author. The type author only defines the methods that have knowledge of the internal implementation of the type. But the complete set of methods is known at link-time or run-time.

 Am I asking too many questions?
to declare them in the class file so that's just postponing the implementation of the method to somewhere else. What I'm after is adding to a type methods that the original type author had no idea existed.
 TinyCC is awesome.  I was experimenting with that a couple months ago. I 
 hacked around with it and added the ~ operator to the C language.  The 
 only thing that put me off of TinyCC at the time (for any serious language 
 fork development) was the lack of support for Windows compilation.  I 
 believe, in the latest version, there is Windows support.
The Windows version works great under mingw. That's the environment I've been using. The tcc code is a little ... hard to follow but it's amazing how small the whole project is. This one 9000 line file contains the preprocessor, compiler and linker.
Sep 21 2005