Home » Community » Forums » » A Postmortem of Game Programming with Digital Mars’ D Programming Language
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 A Postmortem of Game Programming with Digital Mars D Programming Language
Post Reply 
Nice to see another catching the D bug ;)

I still am not sure if D is ready for heavy development use though - lack of destructors and copy constructors for value types (i.e. structs) is especially painful, as it leaves us with manual management of critical resources (i.e. threads, files, sockets), a la C.

 User Rating: 1743   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I believe it is fairly well understood in the Delphi/Pascal community that the 'with' statement is a bad idea. While it does save a little typing, it also can cause serious issues and in my opinion it always hurts readability. The serious issues are rare, but they are a real pain to track down if you do ever get bitten by it.


Crown and Cutlass
Crown and Cutlass Development Blog


 User Rating: 1143   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by swiftcoder
as it leaves us with manual management of critical resources (i.e. threads, files, sockets), a la C.


see tango, alternative std library for D, it has all wrrapped up in quite OOP style. http://www.dsource.org/projects/tango





 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Complaint #4: The D run time errors are obscure.
Not really, I've found D to be much nicer to work with, regarding runtime errors, than C++. Make sure to compile with -g and without -release. You can get nice stacktraces with a patch to Phobos or Tango. See http://team0xf.com/index.php?n=Site.Download
There's also a nice debugger for D, DDBG: http://ddbg.mainia.de/releases.html


Derelict is not a 'game library'. It's a collection of bindings to various multimedia-related libs.


'D objects are all dynamically allocated - always.' - Nope. If you say:
scope foo = new Object;
Then it will be on the stack and destroyed at the end of the scope.

You could also make yourself a function template to alloc an object using malloc or whatever memory allocation you like.

Anyway, nice article :)


swiftcoder:
Threads, Files and Sockets are usually managed using classes in D, that can be RAII, when they are typed as 'scope'. You can also use scope guards to have more fine-grained control over the destruction of various objects.
But of course your concern about structs is valid, luckily D 2.0 will get dtors and something like copy ctors for structs :)

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Nice introduction article, though I'll stick to C++ for awhile longer :)
Just some thoughts:

template<class A, class B>
bool t_assert_equal(const A& param1, const A& param2, const string& name1, const string& name2) {
    if(param1 != param2) {
      printf(“Test %s == %s failed.\n", name1, name2);
      printf(“%s != %s\n", as_string(param1), as_string(param2) );
      return false;
    } else {
      printf(“Test %s == %s passed.\n", name1, name2);
      return true;
    }
}
#define assert_equal(param1, param2) assert(t_assert_equal(param1, param2, #param1, #param2))
So, now each parameter is evaluated once :)

As for the foreach, have a look at boost.foreach:
BOOST_FOREACH(int& i, my_list) i++;

For documentation I use doxygen. I personally don't see it as a plus with the compiler generating the documents, ymmv.

<edit>fixed error pointed out by Gage64</edit>

[Edited by - sirGustav on January 19, 2008 2:52:55 PM]

 User Rating: 1270   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by h3
swiftcoder:
Threads, Files and Sockets are usually managed using classes in D, that can be RAII, when they are typed as 'scope'. You can also use scope guards to have more fine-grained control over the destruction of various objects.

I am aware of all that, however, that only works for scopes. What if I need to return a socket from a function, and then have it live for a scope? That is not possible to implement currently.

Quote:
But of course your concern about structs is valid, luckily D 2.0 will get dtors and something like copy ctors for structs :)

The problem being, of course, that D 2.0 has been here for nearly a year now, and still no sign of those features. We do however have const correctness...

Sorry, my disenchantment is showing through . I followed D very closely for some time, but after D 2.0 was suddenly rushed out, with none of the major usability bugs (forward declaration of templates broken, no way to guarentee resource destruction, etc.) even looked at, and instead more CTFE and const stuff - of dubious use in application development, though I am sure useful elsewhere - I decided to take a sabbatical and wait for C++0X.



 User Rating: 1743   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by sirGustav
*** Source Snippet Removed ***
So, now each parameter is evaluated once :)


This makes the macro useless because the assert(0) will not output the correct location of the error (but it's possible to work around that problem so your suggestion is still good).



OOP Articles | C++: A Dialog (free book) | Thinking in C++ (free book) | Google Books - Free preview for many books


 User Rating: 1661   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I set out to fix the twice-eval problem of macros, and broke another.
Changing as little as possible in his code wasn't such a good idea after all ;)
Thanks for pointing out the problem though, it's fixed now as far as I can see, if it's not I blame it on all the late nights :)

 User Rating: 1270   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Thanks for a nice article!

I can't remember it being that hard to install dmd, though. All the paths in sc.ini are relative to dmd.exe, so you can install to any path without spaces in it. Just make sure to unzip the dmd and dm directories in the same subdir, or dmd won't find the linker.

This setup works for me:
c:\prog\dm
c:\prog\dmd


 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Hi, nice article, I like this kind of writing.

Some comments:

One useful website for information on D is the wiki.

About installation, dsss is a very useful tool. It includes rebuild, which is a build utility automatically resolving dependencies, like bud does. dsss can also download and install via the net, it's a software package manager.

I agree with the author that C's macro system is still nicer for such a thing as assertions. It's possible to some extent in D, but just much uglier than it needs to be. For debugging however, try compiling with the -g switch and use ddbg. It's a powerful debugger, integration is possible with codeblocks and descent, the D plugin for Eclipse.

Macro's, or rather a sanitized version of them (ast-macro's), are scheduled to be included in the unstable branch of the D language. This will get rid of the verbosity of mixins and will conclude the safe alternatives D has been incorporating for the preprocessor. fwiw, here is a hack to implement assertions with line numbers:
template decimalDigit(int n)
{
  const char[] decimalDigit = "0123456789"[n..n+1];
} 

template itoa(long n)
{   
  static if (n < 0)
     const char[] itoa = "-" ~ itoa!(-n);  
  else static if (n < 10)
     const char[] itoa = decimalDigit!(n); 
  else
     const char[] itoa = itoa!(n/10L) ~ decimalDigit!(n%10L); 
}

char[] location()
{
    return `__FILE__ ~ "(" ~ itoa!(__LINE__) ~ ")"`; 
}

char[] Assert(char[] cond)
{
    return `assert(`~ cond ~`, "` ~ cond ~ ` at " ~ mixin(location()) );`;
}

/+ usage:
void main()
{
    int a = 12;
    int b = 14;

    mixin(Assert("a == b"));
}
+/





 User Rating: 1283   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Is it still a postmortem if you didn't actally write a game?

 User Rating: 1893   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Quote:
Original post by Promit
Is it still a postmortem if you didn't actally write a game?

"Postmortem" was used here to describe the act of him reflecting on his experience with D, not to imply that he made a complete game with D. The actual title of the article was just "Game Programming with Digital Mars D Programming Language" but I didn't want people thinking this was a how-to on making a game with D either.

________________

Drew Sikora
President, Programmer - Blade Edge Software
Executive Producer, Newsletter Editor - GameDev.net
Community Relations, Live Events Mngr - Game Institute
IGDA Chapter Advisor - New Jersey


 User Rating: 2077   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Some time back, I wrote a keyword index for the D spec. It can be found on the wiki.

Additionally, bud is not really actively maintained anymore. (The last commit to its source control was over a year ago.) A replacement tool is DSSS. In addition to being an intelligent make utility like bud, it also provides automatic net installation of dependencies, more intelligent handling of object files and libraries, and a few other things. Even if you don't want the extra features, its core "rebuild" utility provides functionality analogous to bud's, plus the smarter object file handling.

(The object file issue occurs when two source files have the same name but are in different packages. With the naive approach to naming object files, it is very easy for one object file to obliterate the other. Rebuild will include the package name in the object file's name, thus resolving the name conflict.)

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Enjoyed the article a bunch! It was good to see the intro from a c++ user's POV.

 User Rating: 1075   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

What is also worth notice, first book about D in English was published this year. Really well written will surely help newcomers to learn D, but also can be used by moderate expirianced and expert D coders to refresh some parts of language.

More you can find on: http://www.dsource.org/projects/tango/wiki/LearnToTangoWithD

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Very interesting, well-written and informative article. Thank you.

Aren't us C++ cavemen supposed to be getting auto in C++0x? Don't know if this is still in date.

 User Rating: 1817   |  Rate This User  Send Private MessageView ProfileView JournalView GD Showcase Entries Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: