Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!


Forgot your password?
Programming IT Technology

Walter Bright Ports D To the Mac 404

jonniee writes "D is a programming language created by Walter Bright of C++ fame. D's focus is on combining the power and high performance of C/C++ with the programmer productivity of modern languages like Ruby and Python. And now he's ported it to the Macintosh. Quoting: '[Building a runtime library] exposed a lot of conditional compilation issues that had no case for OS X. I found that Linux has a bunch of API functions that are missing in OS X, like getline and getdelim, so some of the library functionality had to revert to more generic code for OS X. I had to be careful, because although many system macros had the same functionality and spelling, they had different expansions. Getting these wrong would cause some mysterious behavior, indeed.'"
This discussion has been archived. No new comments can be posted.

Walter Bright Ports D To the Mac

Comments Filter:
  • by master_p ( 608214 ) on Sunday February 22, 2009 @11:18AM (#26948589)

    I don't think D will ever have the high performance of C++, because D objects are all allocated on the heap. The D 'auto' keyword is just a compiler hint (last time I checked) to help in escape analysis. D has structs, but one has to design upfront if a class has value or reference semantics, and that creates a major design headache. Avoiding the headache by making everything have reference semantics negates the advantages of struct.

    D is a mix of C and Java, with the C++ template system bolted on top. It is no way C++. D is not what a veteran C++ programmer excepts as the next generation C++.

    • by Anonymous Coward on Sunday February 22, 2009 @11:25AM (#26948635)

      http://www.digitalmars.com/d/1.0/memory.html#stackclass - Objects in D are not always allocated on the heap. Also, you've clearly never used templating in D if you think it is the C++ template system bolted on top ;)

    • by ardor ( 673957 ) on Sunday February 22, 2009 @11:36AM (#26948681)

      The GC is the way to go for complex application. The reason is simple: the GC has a global overview over all memory usage of the application (minus special stuff like OpenGL textures). This means that the GC can reuse previously allocated memory blocks, defragment memory transparently, automatically detect and elimitate leaks etc.

      Somewhat less obvious is that a GC allows for by-reference assigments being the default. In C++, by-value is default. a = b will always copy the contents of b to a. While this is OK for primitive stuff, it is certainly not OK for complex types such as classes. In 99.999% of all cases, you actually want a reference to an object, and not copy that object. But, as said, the default behavior of assignment is "copy value".

      This is a big problem in practice. The existence of shared_ptr, reference counting pointers etc. are a consequence. We could redefine the default behavior as "pass a reference of b to a", but who will then take care of the lifetime of b? Using a GC, this last question is handled trivially; when the GC detects 0 references, b is discarded.

      Now, once you have by-reference as default, things like closures get much easier to introduce. Neither D nor C++ have them at the moment, but C++0x requires considerably more efforts to introduce them. Functional languages all have a GC for a reason.

      D did another thing right: it did not remove destructors, like Java did. Instead, when there are zero references to an object, the GC calls the destructor *immediately*, but deallocates the memory previously occupied by that object whenever it wishes (or it reuses that memory). This way RAII is possible in D, which is very useful for things like scoped thread locks.

      They also simplified the syntax, which is one of the major problems of C++. Creating D parsers is not hard. Try creating a C++ parser.

      Now, what they got wrong:
      - operator overloading
      - const correctness
      - lvalue return values (which would solve most of the operator overload problems)
      - no multiple inheritance (which does make sense when using generic programming and metaprogramming; just see policy-based design and the CRTP C++ technique for examples)
      - crappy standard library called Phobos (getting better though)
      - and ANOTHER de-facto standard library called Tango, which looks a lot like a Java API and makes little use of D's more interesting features like metaprogramming, functional and generic programming

      • by physicsnick ( 1031656 ) on Sunday February 22, 2009 @02:26PM (#26950059)

        >> D did another thing right: it did not remove destructors, like Java did. Instead, when there are zero references to an object, the GC calls the destructor *immediately*, but deallocates the memory previously occupied by that object whenever it wishes (or it reuses that memory). This way RAII is possible in D, which is very useful for things like scoped thread locks.

        First of all, Java does have destructors. It's called finalize().

        Second of all, calling destructors on a modern GC are extremely costly. Sure, your example implementation of destructors seems simple, but it is only possible in a reference counted garbage collector, which is so primitive as to be nearly useless.

        Modern Java GCs are generational copying collectors. They have a young heap, where objects are allocated, and an old heap, where objects are moved when they survive an allocation. Object retention is done by tree search from a root node.

        This means you can do fun things like allocate a linked list, then drop the reference node. When a collection happens, anything living is rescued from the young heap, and then it's simply wiped clean. No computation is performed regardless of how large it is or how many links it has, because there's no such thing as deallocation on the young heap. When you drop that first link, it's like the VM doesn't even know it's there anymore; the whole list just gets overwritten on the next pass over the heap.

        If, however, you write a destructor for your links (or in Java, finalize()), the destructor then needs to independantly keep track of all of your destructable objects. It needs to remember that they're there so it can call their destructor when they do not survive an allocation. Furthurmore, if you impose your hard requirement of calling the destructor immediately, then the implementation of such a collector is impossible for your language. Even a primitive mark sweep collector, or anything not reference counted is impossible.

        This example is discussed in detail here:

        http://www.ibm.com/developerworks/java/library/j-jtp01274.html [ibm.com]

        You should familiarize yourself with modern garbage collectors. I don't know much about D, but if D really is tied down to a reference-counting collector due to its destructor requirements, that makes it extremely unnatractive as a language. Here is more information on various collector implementations:

        http://www.ibm.com/developerworks/java/library/j-jtp10283/ [ibm.com]

        • Re: (Score:3, Informative)

          by Wolfier ( 94144 )

          > First of all, Java does have destructors. It's called finalize().

          I'm sure you know their differences. Java's finalize does NOT make RAII possible, because it's not run deterministically.
          RAII requires controlling the order of execution of destructors.

          Not being able to perform RAII with it makes finalize() almost totally useless.

  • Now he's done it. Kicked off the alpabetical arms race. He himself averted it once by the Operator Gambit of + and ++. The crisis was defused.

    It was stumped again this decade by what came to be called the Jungle of Earthly Delights Diversions (Python, Ruby, et al). But now he's broken the dam to the last redoubt, the alphabet. There are only so many letters! It is a limited supply! We've feared this since the mid-nineties. Who will save us now?

  • D -- wha? (Score:5, Insightful)

    by ansak ( 80421 ) on Sunday February 22, 2009 @11:58AM (#26948811) Homepage Journal

    I think the fact that this post has been up for almost an hour and has only 33 follow-ons shows what the software community thinks of D.

    One has to acknowledge that Back in The Day, Walter Bright did all of us a great service in producing the first PC-based C++ compiler (Zortech) which effectively forced Borland and Microsoft to take the language seriously.

    Unfortunately, for all of us, he seems to be better at invention than collaboration but that doesn't devalue the contribution he made (structurally) to get us to where we are.


  • why all the hate? (Score:5, Insightful)

    by Bobtree ( 105901 ) on Sunday February 22, 2009 @12:02PM (#26948841)

    The griping and misinformation here is so atrocious that I'm simply embarrassed to be reading Slashdot today.

    Digital Mars D is a wonderfully designed language and I'm in the process of giving up a lifetime of C++ for it.

    I'm not here to defend D or enumerate it's growing pains or evangelize it, but if you don't take it upon yourselves to be well informed, please don't repeat your biased gibberish to the rest of us.

  • by Kuciwalker ( 891651 ) on Sunday February 22, 2009 @12:24PM (#26949007)
    Seriously, name me a piece of commercial or open-source software with significant market share written in D. Library support is about 10000% more important than actual language design.
  • Fabulous, he ported a language to the MAC. Ok groovey...

    The bit about having to make adjustments to the library code is news why?

    Not all OS's support everything in the world, that is just the way it is. If you implement a certain function or macro one way on one platform does not in any way mean that you will be able to implement exactly the same on another platform.

  • Qt bindings (Score:3, Interesting)

    by SwedishPenguin ( 1035756 ) on Sunday February 22, 2009 @01:12PM (#26949411)

    I really like D, and would give up C++ for it, but the one thing I feel is really missing is bindings for Qt. :(

  • D is nice, but... (Score:4, Interesting)

    by Hangeron ( 314487 ) on Sunday February 22, 2009 @03:30PM (#26950559)

    Programming in D is nice, but the situation is a bit annoying.

    1. Tango vs Phobos. Phobos is the official standard library, but it seems most use Tango. Phobos is also pretty low level compared to Tango.
    2. The reference compiler dmd is 32bit only, gdc is outdated and abandoned, and ldc is still alpha status and has missing features. Ldc is quite promising though.
    3. D2 is maybe the biggest issue. It has very useful features, such as partial C++ compatibility, but D2 is a moving target and practically no library supports it. It's also unknown when or if ever D2 will become stable. I haven't seen much discussion about it in the newsgroup either.

"The number of Unix installations has grown to 10, with more expected." -- The Unix Programmer's Manual, 2nd Edition, June, 1972