Jump to page: 1 27  
Page
Thread overview
Writing C in D
Mar 05, 2005
Derek Parnell
Mar 07, 2005
Walter
Mar 07, 2005
Matthew
Re: Writing C in D (C++ features)
Mar 07, 2005
Walter
Mar 09, 2005
Matthias Becker
Mar 09, 2005
pragma
Mar 09, 2005
Matthew
Mar 10, 2005
Walter
Mar 10, 2005
Matthew
Mar 10, 2005
Walter
Mar 10, 2005
Matthew
Mar 10, 2005
Walter
Mar 10, 2005
Matthew
Mar 10, 2005
Walter
Mar 10, 2005
Matthew
Mar 10, 2005
Ben Hinkle
Mar 10, 2005
Roberto Mariottini
Mar 10, 2005
Walter
Mar 10, 2005
Matthew
Mar 11, 2005
Kris
Mar 11, 2005
pragma
Mar 11, 2005
Ben Hinkle
Mar 11, 2005
kris
Mar 11, 2005
Derek Parnell
Mar 11, 2005
Ben Hinkle
Mar 11, 2005
pragma
Mar 11, 2005
Derek Parnell
Mar 12, 2005
Walter
Mar 12, 2005
Matthew
Mar 12, 2005
Walter
Mar 07, 2005
Walter
Mar 07, 2005
Walter
Mar 09, 2005
Matthew
Mar 09, 2005
Walter
Mar 10, 2005
Ben Hinkle
Mar 10, 2005
Matthew
Mar 07, 2005
Matthew
Mar 07, 2005
Walter
Mar 07, 2005
Kris
Mar 07, 2005
Walter
Mar 08, 2005
Kris
Mar 08, 2005
Walter
Mar 08, 2005
kris
Mar 07, 2005
Derek Parnell
Mar 07, 2005
brad
Re: Writing C in D (OT)
Mar 07, 2005
Kris
Mar 08, 2005
John Reimer
Mar 08, 2005
Rob Grainger
Mar 09, 2005
Walter
Mar 09, 2005
Martin M. Pedersen
Mar 09, 2005
Walter
Mar 09, 2005
Martin M. Pedersen
Mar 10, 2005
Walter
Mar 10, 2005
Ben Hinkle
Mar 10, 2005
Matthias Becker
Mar 10, 2005
Walter
Mar 11, 2005
Matthias Becker
Mar 05, 2005
Georg Wrede
Mar 07, 2005
Walter
March 05, 2005
One aspect of D that is nice (or at least flexible ?)
is that you can write programs in ancient C style...

Without using objects, and without using exceptions,
garbage collection and other such modern facilities :-)


All you need to do is provide hooks for a few required
aspects of Phobos, such as GC and assert / OutOfMemory.

> import std.c.stdio;
> import std.c.stdlib;
> 
> int main(char[][] args)
> {
>     printf("Hello, World!\n");
>     return EXIT_SUCCESS;
> }
> 
> extern (C) void _d_OutOfMemory()
> {
>     fprintf(stderr,"Out of memory!\n");
>     exit(1);
> }
> 
> extern (C) void _d_assert(char[] filename, uint line)
> {
>     fprintf(stderr,"%s:%u: failed assertion\n",
>             cast(char *) filename, line);
>     exit(1);
> }

And such "C" code should compile with the regular
D too (with regular asserts and exceptions and GC) ?


A no-GC patch for Phobos (0.110) can be found here:
http://svn.dsource.org/svn/projects/bindings/trunk/
(coded by James Dunne, as posted on this NG earlier)

Of course, you would then have to 'delete' things
yourself - or face the wrath of the memory leaks...
(or to really get in the spirit, use malloc/free)


But you *can*. If you want to. (no flames, please)

--anders
March 05, 2005
On Sat, 05 Mar 2005 11:29:33 +0100, Anders F Björklund wrote:

> One aspect of D that is nice (or at least flexible ?)
> is that you can write programs in ancient C style...
> 
> Without using objects, and without using exceptions, garbage collection and other such modern facilities :-)
> 
> 
> All you need to do is provide hooks for a few required aspects of Phobos, such as GC and assert / OutOfMemory.
> 
>> import std.c.stdio;
>> import std.c.stdlib;
>> 
>> int main(char[][] args)
>> {
>>     printf("Hello, World!\n");
>>     return EXIT_SUCCESS;
>> }
>> 
>> extern (C) void _d_OutOfMemory()
>> {
>>     fprintf(stderr,"Out of memory!\n");
>>     exit(1);
>> }
>> 
>> extern (C) void _d_assert(char[] filename, uint line)
>> {
>>     fprintf(stderr,"%s:%u: failed assertion\n",
>>             cast(char *) filename, line);
>>     exit(1);
>> }
> 
> And such "C" code should compile with the regular
> D too (with regular asserts and exceptions and GC) ?
> 
> 
> A no-GC patch for Phobos (0.110) can be found here:
> http://svn.dsource.org/svn/projects/bindings/trunk/
> (coded by James Dunne, as posted on this NG earlier)
> 
> Of course, you would then have to 'delete' things
> yourself - or face the wrath of the memory leaks...
> (or to really get in the spirit, use malloc/free)
> 
> 
> But you *can*. If you want to. (no flames, please)

I agree with you that this is also a strength of D.

Sometimes, OOP-everything is just overkill.

-- 
Derek Parnell
Melbourne, Australia
5/03/2005 9:35:56 PM
March 05, 2005
Derek Parnell wrote:

>>One aspect of D that is nice (or at least flexible ?)
>>is that you can write programs in ancient C style...
[...]
>>But you *can*. If you want to. (no flames, please)
> 
> I agree with you that this is also a strength of D.
> 
> Sometimes, OOP-everything is just overkill. 

With a better standard library (or perhaps a 3rd party one),
it shouldn't be that hard to use D as a "native Java", either...

D has more features in common with Java than what eg. C++ has,
and should actually be pretty straight-forward with some docs.


Like many others, I think that C++ is a more "complete" language.
At least more mature, and with a lot more libraries and support ?

But it's also more complex, and lacks some things from Java / C#.
(like strings, garbage collection and unit tests, as Walter states)


And this is where D shines. As a "simpler C++", or C/Java crossover.
Buy maybe I'll get more respect for C++ after reading Matthew's book ?

--anders

PS. Some people make a religion out of hating OO programming,
    especially: http://www.geocities.com/tablizer/oopbad.htm
    And vice-versa... I'm finding *both* to be useful, myself.
    (since D supports both, this NG is not the place for a war)
March 05, 2005
Anders F Björklund wrote:
> One aspect of D that is nice (or at least flexible ?)
> is that you can write programs in ancient C style...
> 
> Without using objects, and without using exceptions,
> garbage collection and other such modern facilities :-)
> 
> 
> All you need to do is provide hooks for a few required
> aspects of Phobos, such as GC and assert / OutOfMemory.

I think it is absolutely necessary to have this feature
as standard issue!

We don't certainly _want_ folks to en masse start doing
non-gc programming or ancient C style. But there are
some things even I (as an example of a long time D guy)
would feel uncomfortable doing with gc and stuff. (May
the fears be warranted or not.)

And, to the one guy at the office who fervently opposes
D, one could always say you don't _have_ to use GC.

This sould be documented, too. (Heh, _after_ the hairy
sections in the paper manual, so women and children do
not find it.)
March 07, 2005
"Anders F Björklund" <afb@algonet.se> wrote in message news:d0c4jb$fth$1@digitaldaemon.com...
> Like many others, I think that C++ is a more "complete" language.

I don't really understand why. As a *language*, what does C++ have over D? Implicit function template instantiation. It's hard to find much else.

> At least more mature, and with a lot more libraries and support ?

That, I'll concede. It certainly ought to be more mature, being over 20 years old <g>. And certainly, with all the companies doing C++ tools, there are more libraries and support.

> But it's also more complex, and lacks some things from Java / C#. (like strings, garbage collection and unit tests, as Walter states)

C++ is significantly deficient for the reasons you list. I'll add UTF and contracts as other areas where C++ falls short.



March 07, 2005
"Georg Wrede" <georg.wrede@nospam.org> wrote in message news:4229ED47.1050405@nospam.org...
> And, to the one guy at the office who fervently opposes
> D, one could always say you don't _have_ to use GC.

That's right. You can do all the allocation with C's malloc/free. In fact, the D version of Empire is pretty much a line by line transliteration from C. The two are nearly identical.


March 07, 2005
Walter wrote:

>>Like many others, I think that C++ is a more "complete" language.
> 
> I don't really understand why. As a *language*, what does C++ have over D?
> Implicit function template instantiation. It's hard to find much else.

D has some "simplified" versions of C++ features, like inout instead of
reference params, simplified const handling (storage instead of type),
etc, and I guess I'd have more examples if I had been using C++ more...
And this makes C++ more "complete" in that you can do more things,
but is also makes a lot harder and complex - at least at the start ?

I'll let the C++ experts fill in their own pet peeves about D 1.0.
(as I've said before, my own experience is with C and with Java)

>>But it's also more complex, and lacks some things from Java / C#.
>>(like strings, garbage collection and unit tests, as Walter states)
> 
> C++ is significantly deficient for the reasons you list. I'll add UTF and
> contracts as other areas where C++ falls short.

Currently D also falls a little short on contracts and unittests,
compared to e.g. Eiffel and Java for instance, but it is definitely
on the right path there! And doxygen fills up for the "missing Javadoc"

Anyway, I have never really liked C++. With D, maybe I won't have to ?
Although if I started a complex project today, I would probably use C++
(if C or Java wasn't enough). Just hoping that tomorrow, I can use D...

--anders
March 07, 2005
"Anders F Björklund" <afb@algonet.se> wrote in message news:d0gu9k$1n20$2@digitaldaemon.com...
> Walter wrote:
>
>>>Like many others, I think that C++ is a more "complete" language.
>>
>> I don't really understand why. As a *language*, what does C++ have over D? Implicit function template instantiation. It's hard to find much else.

    const

    references

    bool

    namespaces

    compile-time testing (none of that hideous runtime generic comparison filth)

    TMP

    macro pre-processor

    'using'

    operators that look like operators

    compilers that warn

    proper cast operators, and the ability to fill the gaps in the spectrum with user defined types

    support for shims (implicit template instantiation coupled with ability to manipulate names in global/specific
namespaces)

    lack of GC

    ability to produce extremely small applications (i.e. supports extremely low coupling, and allows one to dispense
with C/C++ Runtime Library)

    etc. etc. etc.

(For the record, I'm writing std.openrj right now, in 100% D, and enjoying it for the most part. But it is *not* unalloyed tra-la-la-ing in wonderland ...)

Matthew



March 07, 2005
Matthew wrote:

>>>I don't really understand why. As a *language*, what does C++ have over D?

>     bool

D has 'bool' now, right ? A built-in type that only holds true/false.

Or did you mean boolean semantics with for instance conditionals ?
I know that D has the same booleans as C99 has, but not what differs
the D bool alias from the C++ bool keyword/type ? I *do* know what
differs D bool from Java boolean, and that language's semantics...

>     macro pre-processor
>     compilers that warn

Some people thinks lacking these is a Good Thing only. (I don't, but)

>     lack of GC

Unless you disable GC yourself in Phobos, that is...

>     ability to produce extremely small applications (i.e. supports extremely low coupling, and allows one to dispense with C/C++ Runtime Library)

Can't you do this in D too, by dispensing with Phobos ?

>     etc. etc. etc.

I'll add these too:

	AltiVec vector types
        (http://developer.apple.com/hardware/ve/model.html)

	inline PPC assembler
        (you can of course put that in separate .s files now)

	debugging (with name demangling and all line numbers)

	doxygen (without filters/hacks to make the code parse)


But there is nothing stopping D from getting these, too...
Except that there are only 24 hours in each day, of course. ;-)

--anders
March 07, 2005
"Anders F Björklund" <afb@algonet.se> wrote in message news:d0gu9k$1n20$2@digitaldaemon.com...
> Walter wrote:
> >>Like many others, I think that C++ is a more "complete" language.
> > I don't really understand why. As a *language*, what does C++ have over
D?
> > Implicit function template instantiation. It's hard to find much else.
>
> D has some "simplified" versions of C++ features, like inout instead of reference params,

A C++ reference parameter gives no clue whether it is in, out, or inout. The situation is such that Microsoft went ahead and invented IDL (Interface Description Language), the sole point of which is to add that missing bit of information. IDL is irrelevant for D.

Looking at how references actually work in C++, they are loaded up with special rules that make them behave as if they were storage classes rather than types. D just goes ahead and makes them what they naturally want to be. I don't see anything incomplete about it.

> simplified const handling (storage instead of type),

As has been debated here many times <g>, const as a type modifier in C++ is so semantically weak it is fairly useless. (Many disagree.) C and C++ are the only languages I've ever heard of that use const as a type modifier. Java and C# show no signs of adopting it. The C++ community has not convinced the larger programmer community that const as a type modifier has a place.

> etc, and I guess I'd have more examples if I had been using C++ more...
> And this makes C++ more "complete" in that you can do more things,
> but is also makes a lot harder and complex - at least at the start ?

I'd argue that C++ is less complete, since it relies so heavilly on STL to do things that are built in to most languages. Doing a general purpose foreach with C++ is fiendishly difficult. It's for free in D.

> I'll let the C++ experts fill in their own pet peeves about D 1.0. (as I've said before, my own experience is with C and with Java)


« First   ‹ Prev
1 2 3 4 5 6 7