The D language

Started by
90 comments, last by Nitage 17 years, 9 months ago
Quote:Original post by smr
One major plus to D however is that even though the default paradigm for instance destruction is non-deterministic, you can use the auto attribute to use RAII. I _hate_ .NET's method - IDisposable - which essentially forces you back into managing your resources manually. Isn't that why we created garbage collectors in the first place?

No. Garbage collection was never intented for managing resources, it is meant for managing memory. One of the biggest mistakes you can make is assuming that deallocation and disposal are one and the same, even though in many cases they are coupled together. In general, you want resource management to occur quickly and deterministically, whereas memory deallocation can be delayed to a nondeterministic point in time as it should not directly affect the logical operation of your program.
Advertisement
C++ could be a better language, if its evolution weren't that painfully slow. There are so many nice features in the pipe that I want to have now, not in 2009...
Quote:Original post by Polymorphic OOP
No. Garbage collection was never intented for managing resources, it is meant for managing memory. One of the biggest mistakes you can make is assuming that deallocation and disposal are one and the same, even though in many cases they are coupled together. In general, you want resource management to occur quickly and deterministically, whereas memory deallocation can be delayed to a nondeterministic point in time as it should not directly affect the logical operation of your program.


You're right. My mistake. I should have been referring to non-deterministic finalization. I too suffer from the problem of coupling these two things together in my brain. I've corrected my original post.
Quote:The only way he will truely learn something new and actually broaden his view on problem solving is by learning languages based on completely different programming paradigms.


The nice thing about D is that while it follows similar programming paradigms as C++, you find yourself working more on solving your own problems rather than dealing with deficiencies in the language. So rather than thinking about low-level implementation details (what containers to use, what memory management scheme to use, worrying about getting headers and cpp files synchronized, worrying about virtual methods), you just program your damn program and most of the time, it's almost trivial to implement.

A prime example is the STL collection in C++. STL attempts to augment C++'s rather anemic data abstraction abilities, and does so, if perhaps in a somewhat wordy fashion. In D, there are some STL-style libraries, but I've never found myself needing one. For the most part, dynamic arrays, associative arrays (very similar to std::map), and custom class hierarchies achieve everything I need in terms of data abstraction. Associative arrays alone have taken the place of several more complex data structures that I used with C++.

Quote:C++ could be a better language, if its evolution weren't that painfully slow. There are so many nice features in the pipe that I want to have now, not in 2009...


C++ could also be a better language if it weren't weighed down with being natively backwards compatible with about 35 years of legacy code. Any new feature in C++ has to be painstakingly reviewed, checked, and tested to assure that it doesn't conflict with or break any existing code. D has something of an advantage because it's still being designed, but the point is that C++ is too old and too bloated to improve. This is D's entire mantra: it's not trying to be a better C++, it's just trying to make a language that has abstractions that have become common in programming today.

Quote:When you look at D you see a potentially capable language that has many nice features, however does it truly have the support network there for you to work effectively?


This is always the catch-22 with new languages. People don't want to use it because it isn't mainstream, but it'll never become mainstream if people don't use it. What has to happen is a critical mass of people have to take the leap of faith and try it out.
_______________________________________________________________________Hoo-rah.
Does anyone have some code that shows D doing something better than C++ or at least being done in a less complicated fashion?

Also I thought the resources were tied to the memory. So wouldn't the deallocation of memory be part of the managing of resources? Maybe (well i am) I am confusing the difference between resources and memory.

Beginner in Game Development?  Read here. And read here.

 

I just want my C# code to compile to native code... is that so much to ask? Darn framework.
Consider a class that as one of it's members has a HANDLE to an open file.

When the object dies, you don't necessarily care about how much memory it's taking up, but you definitely want that HANDLE to the open file to have CloseHandle() called on it, or you get an orphaned open file (one of the most annoying things about windows EVER).
daerid@gmail.com
Quote:Does anyone have some code that shows D doing something better than C++ or at least being done in a less complicated fashion?


Alright then. This is a trivial example, but demonstrates a few key issues: operator overloading, templates, classes, and overall syntax:

#include <iostream.h>#include <assert.h>template<typename T>class MyContainer{private:	T* mData;	unsigned int mLength;public:	MyContainer(unsigned int length)	{		mLength = length;		mData = new T[mLength];	}	~MyContainer()	{		delete[] mData;	}	T& operator[](unsigned int index)	{		assert(index >= 0 && index < mLength);		return mData[index];	}	unsigned int length()	{		return mLength;	}};int main(int argc, char** argv){	for(int i = 0; i < argc; i++)		cout << "Arg " << i << " = " << argv << endl;	MyContainer<int>* c = new MyContainer<int>(10u);	(*c)[4] = 5;	(*c)[6] = 10;	cout << "Length: " << c->length() << endl;	cout << (*c)[4] << ", " << (*c)[6] << endl;	delete c;	return 0;}


The equivalent in D:

import std.stdio;class MyContainer(T){private:	T[] mData;public:	this(uint length)	{		mData = new T[length];	}	~this()	{		delete mData;	}	T opIndex(uint index)	{		assert(index >= 0 && index < mData.length);		return mData[index];	}		T opIndexAssign(T value, uint index)	{		assert(index >= 0 && index < mData.length);		return mData[index] = value;	}	uint length()	{		return mData.length;	}		// Hell let's make an iterator, I don't have a clue how to do that in C++	int opApply(int delegate(inout T value) dg)	{		int result = 0;		foreach(T val; mData)		{			result = dg(val);						if(result != 0)				break;		}				return result;	}}void main(char[][] args){	foreach(uint i, char[] arg; args)		writefln("Arg ", i, " = ", arg);	MyContainer!(int) c = new MyContainer!(int)(10);	c[4] = 5;	c[6] = 10;	writefln("Length: ", c.length);	writefln(c[4], ", ", c[6]);		foreach(int v; c)		writefln(v);	delete c;}


Just........ yeah. THAT'S why I don't like C++ anymore.
_______________________________________________________________________Hoo-rah.
I'm a bit of a newbie, especially to game development... I haven't written any engines or things like that... I want to, hopefully, some day. Anyway, I know C++, but is D a good choice or should I wait until there are more libraries for it?

Thanks,
Best of wishes,
xycos
"For sweetest things turn sour'st by their deeds;Lilies that fester smell far worse than weeds."- William Shakespere, Sonnet 94
hello,
there is a third type of D users, like me, who master only one or more scripting languages (i use Maya MEL - non-OO), but in need for a real compiled language. i feel embarassed to say i made some file/data management tools in MEL, even a tool to offset the time in a subtitle file. i tried to learn c/c++, but i failed, not having the time and getting lost in so much specifications. mabye because i have not a programming technical background from school, i cannot understand many syntax stuff in c/c++, getting some kind of paranoia, thinking about those languages they were build like a maze by a sick mind :). of course i had to learn many features of c++ to learn d (it looks like the digital mars documentation is made for former c/c++ programmers :( ), lucky me i have programmer friends, and i find cool people having patience in sharing their knowledge. i allready started to make a 3d core with Derelict+dmd+build and it advances. i consider a great future for this language is evident.
bye

This topic is closed to new replies.

Advertisement