Jump to page: 1 24  
Page
Thread overview
C and/or C++ in D
Jan 14, 2003
Ben Woodhead
Jan 14, 2003
Kwan Ting
Jan 15, 2003
Ben Woodhead
Jan 15, 2003
Ben Woodhead
Jan 15, 2003
Niall Douglas
Jan 15, 2003
Lars Ivar Igesund
Jan 16, 2003
Niall Douglas
Jan 16, 2003
Daniel Yokomiso
Jan 16, 2003
Burton Radons
Jan 18, 2003
Daniel Yokomiso
Jan 18, 2003
Burton Radons
Jan 18, 2003
Daniel Yokomiso
Jan 18, 2003
Sean L. Palmer
Jan 18, 2003
Burton Radons
Jan 19, 2003
Daniel Yokomiso
Jan 19, 2003
Sean L. Palmer
Jan 16, 2003
Daniel Yokomiso
Jan 15, 2003
Evan McClanahan
Jan 15, 2003
Niall Douglas
Jan 15, 2003
Ben Woodhead
Jan 15, 2003
Sean L. Palmer
Jan 16, 2003
Daniel Yokomiso
Jan 16, 2003
Sean L. Palmer
Jan 18, 2003
Daniel Yokomiso
Jan 18, 2003
Sean L. Palmer
Jan 19, 2003
Daniel Yokomiso
Jan 15, 2003
Niall Douglas
Jan 18, 2003
Walter
Jan 20, 2003
Evan McClanahan
Jan 15, 2003
Ilya Minkov
Jan 18, 2003
Walter
January 14, 2003
Hello Everybody

I have been reading this newsgroup for quite some time and I am starting to get worried. People have to stop looking at how am I going to do this c or C++ feature in D and start looking at it from what is the best why to do this.

The one comment I see a lot in this newsgroup is can you implement this feature from c or c++. If you want c++ the use it. I like C++ a lot. But its not a nice language (no affence to the creators). Its a very powerful language. Don't mistake the 2 things.

You are using c++ because its powerful, not because its a nice. You have learned to like c++, and you did that because of the power. When you started do you really think that you were saying stuff like "wow, this is the best way to handle strings, and I really like these pointers". You might like them now.

As it is I have see a few feature that (although needed/wanted by the c++ community) were not in the design that were put in (i.e. templates). I liked Walters original plan of not putting it in. Java does fine without it.

Please stop being c++ programmers using d. If you want one macro that has not been talked about yet. Don't worry its still in c++. Or if you want templates they are still in c++, or you want to remove string handling or dynamic arrays don't worry they are not in c++. There is only a small amount of c++ used by everything, so before you ask the question "Can you put this feature in" ask yourself a few questions:

1. Does anybody else actually use this? If its not in walters design then
chances are not everybody.
2. Is there another way to do this? There usually is.
3. Is the way that I want really a good way or is it just some *ugly* thing
that I got comformable with.

One possible way to do this, is instead of coming to the list with your c++ code and saying this is something that is needed, perhaps you should say "this is what I am trying to do and here is they way I would do it in c++, anybody have any ideas on how to do this in D".

Thanks, Ben


January 14, 2003
Hi, I've been reading the group for quite some time as well but haven't contributed coz my knowledge in programming is limited. So, here's go my first post in this group.

Ben, you've made a very valued point there. Of course with a new language, one should think in terms of the features of the new language and not that I did it this way before, how do I do it now. On the other hand, some features that are not use by everybody are still necessary if D is to be a successor to C and C++. One such example is templates which is pretty important for generic programming.

Kwan Ting
        - just some comments from me.

--
To everyone is given the key to the gates of heaven, but the same key opens the gate of hell.


January 15, 2003
In article <b01afa$16dn$1@digitaldaemon.com>, Ben Woodhead says...

>You are using c++ because its powerful, not because its a nice. You have learned to like c++, and you did that because of the power. When you started do you really think that you were saying stuff like "wow, this is the best way to handle strings, and I really like these pointers". You might like them now.

No 90% of people who use C++ do so because it's the industry standard. I personally would greatly prefer to use something non-OO and functional, but the tools for C++ are extremely mature so it tips the balance in favour. Also, of course, employers want to use the lowest common denominator of technology so they can easily replace their employees.

I have not met one single person who is happy with C++ - everyone has annoyances and gripes - much is through ignorance, low technical ability and poor understanding, but some are very real faults too eg; my earlier point about the exception handling system in C++ being fundamentally broken.

>As it is I have see a few feature that (although needed/wanted by the c++ community) were not in the design that were put in (i.e. templates). I liked Walters original plan of not putting it in. Java does fine without it.

I would *not* use Java as a baseline for anything, but then I personally hate the language :). Templates I think were "stolen" from Ada by C++ and while they're ok in C++, they really should go a lot further. Generic programming can only be 75% done using C++ style templates, so if D were adopting them, I'd go the full hog and make them completely substitutable ie; leave it to the compiler to determine where it's like a C macro and needs new code each time or whether some code can be centralised.

This approach would also mean we can get rid of the C preprocessor parameterised macros. Just make everything involving substitution templates.

>One possible way to do this, is instead of coming to the list with your c++ code and saying this is something that is needed, perhaps you should say "this is what I am trying to do and here is they way I would do it in c++, anybody have any ideas on how to do this in D".

I agree with what you're saying completely. However, I would say that C++ does have some very useful features which D could learn from. I personally use templates, multiple inheritence and exceptions wherever they produce a better project which is quite often.

However, one must be careful of wearing "C++ goggles" where if it's done some way in C++, that therefore must be the only way. That's hardly true, especially for C++ out of all languages. I would hope D will take the opportunity to improve on every single area possible over C++ and effectively become the superior choice for a C-style OO language which I think is its design goal?

Me personally: I think D should have inbuilt strings, dynamic arrays, hash tables, lists (linked and vector), fully flexible templates, recursively throwable exceptions and optional garbage collection (for this, new and delete allocate from the freestore, but "newgc" has its deletions managed by a GC algorithm). My rationale for including all that STL stuff is that very few programmers can improve significantly enough on those algorithms and even if they could, they could still always implement their own and use it manually.

The garbage collection debate to my mind is stupid (!) because you can support both very easily with slight syntaxical improvement eg; newgc. Internally you would allocate from two different heaps, one GC'ed and the other not.

Heh, I bet I get significant replies this time! :)

Cheers,
Niall


January 15, 2003
Hello

Templates have there uses, but they are something you have to get use to. There has to be an approach that allows for the same generality without the need for templates. Java has lived quite well without it, and it is being used for some big projects. Thanks for the responce.

Later, Ben

"Kwan Ting" <me@here.com> wrote in message news:b0284i$1uud$1@digitaldaemon.com...
> Hi, I've been reading the group for quite some time as well but haven't contributed coz my knowledge in programming is limited. So, here's go my first post in this group.
>
> Ben, you've made a very valued point there. Of course with a new language, one should think in terms of the features of the new language and not that I did it this way before, how do I do it now. On the other hand, some features that are not use by everybody are still necessary if D is to be a successor to C and C++. One such example is templates which is pretty important for generic programming.
>
> Kwan Ting
>         - just some comments from me.
>
> --
> To everyone is given the key to the gates of heaven, but the same key opens the gate of hell.
>
>


January 15, 2003
Hello

Thanks for the responce, you have some interesting points to think about. Some comments are included in the message.

"Niall Douglas" <Niall_member@pathlink.com> wrote in message news:b02iuk$25gs$1@digitaldaemon.com...
> In article <b01afa$16dn$1@digitaldaemon.com>, Ben Woodhead says...
>
> >You are using c++ because its powerful, not because its a nice. You have learned to like c++, and you did that because of the power. When you
started
> >do you really think that you were saying stuff like "wow, this is the
best
> >way to handle strings, and I really like these pointers". You might like them now.
>
> No 90% of people who use C++ do so because it's the industry standard. I personally would greatly prefer to use something non-OO and functional,
but the
> tools for C++ are extremely mature so it tips the balance in favour. Also,
of
> course, employers want to use the lowest common denominator of technology
so
> they can easily replace their employees.

The reason for c++ becoming the standard is related because of the power of the language. C was able to give you the power of asm in a much simpler way. That does not mean its a simple way, its just easier to work with them asm. C++ adds features to help make code maintainable and organized but keeps the power and most if not all of the speed. Being the most powerful language around for a long time means that if you want to do anything heavy then you will have to use c or c++. So hear we are, so people use c++ because its the standard and its the standard because of the power.

> I have not met one single person who is happy with C++ - everyone has
annoyances
> and gripes - much is through ignorance, low technical ability and poor understanding, but some are very real faults too eg; my earlier point
about the
> exception handling system in C++ being fundamentally broken.

I have not met a single person that is happy with anything on a computer, especially programming languages. And you are right, a lot has to do with lack of knowledge. But you know what, things that are intuative in the first place don't have problems with people not understanding them. :)

> >As it is I have see a few feature that (although needed/wanted by the c++
> >community) were not in the design that were put in (i.e. templates). I
liked
> >Walters original plan of not putting it in. Java does fine without it.
>
> I would *not* use Java as a baseline for anything, but then I personally
hate
> the language :). Templates I think were "stolen" from Ada by C++ and while they're ok in C++, they really should go a lot further. Generic
programming can
> only be 75% done using C++ style templates, so if D were adopting them,
I'd go
> the full hog and make them completely substitutable ie; leave it to the
compiler
> to determine where it's like a C macro and needs new code each time or
whether
> some code can be centralised.

Java is a different way of thinking. If you start with that language then you will be fine, but coming from C is not going to be fun. I will have to look at the ada templates to comment on the rest but it sounds interesting. All this generic programming could be a solution to a problem with the language. Fix the problem and remove the need for generic programming like templates. This approach worked for Java and walter also didn't think templates were needed.

> This approach would also mean we can get rid of the C preprocessor
parameterised
> macros. Just make everything involving substitution templates.
>
> >One possible way to do this, is instead of coming to the list with your
c++
> >code and saying this is something that is needed, perhaps you should say "this is what I am trying to do and here is they way I would do it in
c++,
> >anybody have any ideas on how to do this in D".
>
> I agree with what you're saying completely. However, I would say that C++
does
> have some very useful features which D could learn from. I personally use templates, multiple inheritence and exceptions wherever they produce a
better
> project which is quite often.

c++ does have some useful features, as does java and several other languages. It also has a lot of crap, and I have not dought that templates and multi-inheritence helps your project. Both could be needed to fix a problem with c++ but there is always a better way. :)

> However, one must be careful of wearing "C++ goggles" where if it's done
some
> way in C++, that therefore must be the only way. That's hardly true,
especially
> for C++ out of all languages. I would hope D will take the opportunity to improve on every single area possible over C++ and effectively become the superior choice for a C-style OO language which I think is its design
goal?

C++ goggles is what I am worried about. I also hope that D does take the usefull features of c++ and builds on that, as well as java. Although you don't like the language there are things in it that are nice. But I don't want to write c++ code in d.

> Me personally: I think D should have inbuilt strings, dynamic arrays, hash tables, lists (linked and vector), fully flexible templates, recursively throwable exceptions and optional garbage collection (for this, new and
delete
> allocate from the freestore, but "newgc" has its deletions managed by a GC algorithm). My rationale for including all that STL stuff is that very few programmers can improve significantly enough on those algorithms and even
if
> they could, they could still always implement their own and use it
manually.

Yes, my thoughts exactly. As far as new and delete. I think everything should be created on free stores. The program its self can be stored in conventinal memery, every variable goes in free stores. On the other hand I would not want to limit the ability to create linked lists or what ever.

> The garbage collection debate to my mind is stupid (!) because you can
support
> both very easily with slight syntaxical improvement eg; newgc. Internally
you
> would allocate from two different heaps, one GC'ed and the other not.

Thats interesting.

> Heh, I bet I get significant replies this time! :)

Ya a few, hope it makes sence, its late.:)
Goodnight,
Ben

> Cheers,
> Niall
>
>


January 15, 2003
Hello, I have a few questions. Perhaps someone can help me out.

What is the purpose in generic programming?
What problems does it solve?
Is that problem a language problem?
How does Java live without it?

Ben

"Kwan Ting" <me@here.com> wrote in message news:b0284i$1uud$1@digitaldaemon.com...
> Hi, I've been reading the group for quite some time as well but haven't contributed coz my knowledge in programming is limited. So, here's go my first post in this group.
>
> Ben, you've made a very valued point there. Of course with a new language, one should think in terms of the features of the new language and not that I did it this way before, how do I do it now. On the other hand, some features that are not use by everybody are still necessary if D is to be a successor to C and C++. One such example is templates which is pretty important for generic programming.
>
> Kwan Ting
>         - just some comments from me.
>
> --
> To everyone is given the key to the gates of heaven, but the same key opens the gate of hell.
>
>


January 15, 2003
"Ben Woodhead" <zander@echotech.ca> wrote in message news:b02upv$2cm3$1@digitaldaemon.com...
> Java is a different way of thinking. If you start with that language then you will be fine, but coming from C is not going to be fun. I will have to look at the ada templates to comment on the rest but it sounds
interesting.
> All this generic programming could be a solution to a problem with the language. Fix the problem and remove the need for generic programming like templates. This approach worked for Java and walter also didn't think templates were needed.

You cannot have typesafe containers without language-supported generics. Not unless you want to cut-and-paste all your container code for every new type you wish to put into such a container.  Then duplicate all your algorithm code for every container type times the number of types contained therein.  The combinatorial explosion happens quickly.  People will write a non-typesafe container, or a braindead linear algorithm, rather than do all that work.  Non-typesafe containers lead to bugs in user code.  If they do make all those classes, they will be unmaintainable.  A bug in the original gets copied into all the subsequent classes.

Generics are a fundamentally good thing.  They allow you to reuse more code than OO does.  Write a template algorithm once, and use it on anything that supports the necessary interfaces.  It'd be good to explicitly specify those interfaces in the requirements somehow.  Self-documentation.

It would be super nice if D unified the type system so that one could write a template that would work on either a basic type or a user-defined type without modification.  C++ only goes about halfway with this.

Sean


January 15, 2003
In article <b02uv8$2cnb$1@digitaldaemon.com>, Ben Woodhead says...
>
>Hello, I have a few questions. Perhaps someone can help me out.

I might be able to. I disagree fundamentally with OO and through my arguments with OO gurus, I've learned a lot (though not been convinced I'm wrong!) :)

>What is the purpose in generic programming?
>What problems does it solve?
>Is that problem a language problem?
>How does Java live without it?

Firstly, I don't think Java does live without it. It's like operator overloading - Sun just removed it completely. Operator overloading, when used correctly, actually produces far more reliable, intuitive and thus bug-free code.

I'll just outline what it is for those not familiar with these things, then say why it was incorporated.

Now if for example I want a list object which maintains a list of another object, in Java I'd use a dual object approach - there'd be a list item object which would be the base class of all items to be placed in the list and then the list would manage those subclasses of the list item object.

Using templates, you specify the list object as taking one or more parameters ie; it's like a mould used to "stamp" out objects. So if I want a list of string objects, it's class list<string> and equally class list<class<string>> works too (a list of lists of string). The point is with templates you write the class guts once, and the parameters determine the actual implementation.

If you're familiar with C, then most use of parameterised macros can be replaced with templates eg;

#define ADD(type) \
static type Add ## type (type a, type b) \
{ return a + b; }

In templates becomes:

template<class type> type Add(type a, type b)
{ return a + b; }

The great problem I see with C++ templates is they are limited to type parameters. I'd personally like to see free-form parameters.

You may be asking what can templates let me do other approaches cannot? In Java, I don't think there are any - Java stores lengthy meta-data about all its data constructs so the language always knows what type some data is and thus how to work with it.

In a static system like C++, there is no knowledge of data type except at time of compilation - hence "new X" is useless unless X's type is immediately known. Templates are the way of implementing multi-type generic code without requiring a run-time system.

BTW if you're thinking fine, let's add a run-time system - well, that's why objective C failed in competing against C++. Nowadays you may get away with it, but TBH if you want a nice big helpful run-time system you'd use C# or Java.

One other point is that Java's solution to the above problems would require more code than in C++. Using abstract base classes to generalise objects to some collection class is fine but it really needs multiple inheritance to be useful.

I think the most productive future for D would be to remain as a primarily static system, though I wouldn't mind seeing optional dynamic features like ObjC has.

Cheers,
Niall


January 15, 2003
Ben Woodhead wrote:
> Hello, I have a few questions. Perhaps someone can help me out.
> 
> What is the purpose in generic programming?
> What problems does it solve?
> Is that problem a language problem?
> How does Java live without it?

Many and various, and it doesn't, really.  They've just been added ti the language spec for forthcoming versions, I believe.  Generic programming is simply a way of defining a datastructure or algorthm to work with an type or set of types.  Google, there are better descriptions out there.

Evan

January 15, 2003
In article <b02upv$2cm3$1@digitaldaemon.com>, Ben Woodhead says...

>The reason for c++ becoming the standard is related because of the power of the language. C was able to give you the power of asm in a much simpler way. That does not mean its a simple way, its just easier to work with them asm. C++ adds features to help make code maintainable and organized but keeps the power and most if not all of the speed. Being the most powerful language around for a long time means that if you want to do anything heavy then you will have to use c or c++. So hear we are, so people use c++ because its the standard and its the standard because of the power.

I disagree. There are far more powerful languages out there than C++ eg; Haskell, even Python. I think the main reasons had to do with C++ offering a direct upgrade path for legacy C code.

This then begs the question why Objective C didn't win since it also offered backwards compatibility? It's a dynamic system, not static like C++ and thus came with a runtime library. I'm still not quite sure why C++ won because in my mind it was the technically inferior choice, but I'm guessing it had to do with: (a) perceived efficiency (b) an excellent early translator to C (CFront from AT&T) (c) the perception that ObjC was too "out there" coming from NextSTEP as it did

>Java is a different way of thinking. If you start with that language then you will be fine, but coming from C is not going to be fun.

Well that's certainly one way of putting it. I wouldn't agree that if you start with it you're fine - most people I know who did that were bowled over by other OO languages eg; Schema or Smalltalk because Java is just so horribly limited. I find it like programming with my nose only with both hands tied behind my back :)

> I will have to
>look at the ada templates to comment on the rest but it sounds interesting.

Err, this is vague memory talking! I could be entirely wrong!

>All this generic programming could be a solution to a problem with the language. Fix the problem and remove the need for generic programming like templates. This approach worked for Java and walter also didn't think templates were needed.

You absolutely need templates for any static system like C++ and I think D? They also make quite a lot of programming easier, and I can't see not having them without multiple inheritance being all that viable. You need one or the other for large projects IMHO.

>c++ does have some useful features, as does java and several other languages. It also has a lot of crap, and I have not dought that templates and multi-inheritence helps your project. Both could be needed to fix a problem with c++ but there is always a better way. :)

Well I've always been lucky in being able to use everything the language gives me without shooting myself in the foot. One of my early C projects was "pointer nation" because I was basically writing assembler. Ran fine, but not a single other soul could dare alter a line and expect it to continue working - and thus, with hindsight, that was a bad project.

>C++ goggles is what I am worried about. I also hope that D does take the usefull features of c++ and builds on that, as well as java. Although you don't like the language there are things in it that are nice. But I don't want to write c++ code in d.

Out of interest, what's nice in java? The VM is the sole thing I can think of personally.

>Yes, my thoughts exactly. As far as new and delete. I think everything should be created on free stores. The program its self can be stored in conventinal memery, every variable goes in free stores. On the other hand I would not want to limit the ability to create linked lists or what ever.

Ooo - just had another idea. How about a freestore overload stack? Basically, I'd like an object and everything it calls to use a specific heap so that on destruction I can ignore deleting all my child objects and just delete the heap (and thus all child allocations)? This would greatly improve performance. C++ can do this, but generally you need to chop the code into threads so you can base the seperate heap on thread local storage.

Cheers,
Niall


« First   ‹ Prev
1 2 3 4