It's either Continuing Professional Development, or just getting so bored that learning something new is the only cure. But I finally sat down this week a dug into
D.
D, for the uninformed, is billed by it's author as a successor to C++, (and to some respect C). The website is a little tricky to understand (the 4 links on the left are the key navigation - Language = Overview of language, and Phebos = core library docs). The Documentation is clear, and reasonably well expressed with quite a few examples. (although it could probably do with PHP's comment system.)
There is also a PEAR/CPAN style site,
dsource.org, which has a few projects written in
D. including wrappers around common C libraries (which make them more OO like - even though you can directly access C calls in the language without wrappers.).
What makes this language interesting is quite a few key points
- It compiles into .exe/binary/.so/.dll etc.
- The core library is tiny ~1Mb (500K striped) compared with the classic java/C# frameworks
- memory management (autofreeing at the end of each function) - so you dont need to splatter the code with malloc()(/free()
[slight correction thanks to Regan Heath] - this is really due to the built in garbage collector, and the auto free'ing only occurs when you define the type as auto, or when resources get tight.
- The core library is small and limited (so I dont have to learn 1000's of classes/packages to understand code)..
- The code syntax is similar to PHP/Java/C# etc. for class construction / definition,
- native Arrays and Associative Array's, just like PHP!.
- No need for .h header files
- It's pretty damn fast! - beat's gcc in benchmarks (well even considering you always take them with a pinch of salt)
- It just works....
A simple D Code... (It's LGPL'ed from the DUI distribution)
/* See original for copyright - I've removed for the example) */
// give this file a module name (bit like namespaces)
module hw.HelloWorld;
// private imports so that any code importing this,
// doesnt import these as well.
// so you dont flood the global namespace too much..
private import dui.MainWindow;
private import dui.DUI;
public:
class HelloWorld : MainWindow // it extends MainWindow..
{
private import dui.Label; // imports can go here as well..
char[char[]] testarray = [ // yah - native array's in prop. def's
"one": "1",
"two": "2"
]; // oops - this doesnt work (although it may do in the future)
// thanks to Jarrett Billingsley for spotting this..
char[][] testarray = [ // well, semi-yah limited support
1: "atest", // for assoc. array initalizers..
5: "another test",
];
this() // yeap that's the constructor..
{
super("DUI Hello World"); // like parent::_construct()
this.setBorderWidth(10); // you dont need this. , but
// I think it add's clarity.
this.add(new Label("Hello World" ~ testarray["one"]));
// string concat with the ~
// operator.
this.show();
}
}
void main(char[][] args)
{
DUI dui = DUI.dui(args); // pass parameters to Gtk+
new HelloWorld();
dui.go(); // start the main event loop
}
Click on the more bit for the full story..
View Extended Entry