Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » the D programming language

This thread is locked; no one can reply to it. rss feed Print
the D programming language
Thomas Fjellstrom
Member #476
June 2000
avatar

Hmm, I think DMDScript would work nicely :o

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

bamccaig
Member #7,536
July 2006
avatar

Jonny Cook said:

It might just be because I started with C/C++ 4 years ago and have pretty much used it exclusively since then, but I feel like I'm somehow cheating by using a language which makes it easier to program than it is in C++.

Yeah, I partially feel the same way... I'm proud of C/C++, whereas most people I know are afraid of it. I learned to program using C++ and have yet to find a language that I prefer to it, though I consider C# an equivalent...

Jonny Cook said:

And of course this is just my opinion as a hobbyist programmer who never has to deal with a deadline (or even finish anything I start for that matter).

One thing I especially like about C/C++ is that a lot of people are afraid of it. I know that of my college class there is probably only a couple of people that enjoy C/C++ (most are literally afraid of it). Perhaps of our computer studies class it's only Samuel Henderson and I that embrace it. :) Another [possibly virtual] benefit of C/C++ is that it takes a more competent programmer to write. A lot of other languages are more forgiving and allow less competent people to work on the project which can only result in poorer code.

One thing that I saw in college is that a lot of people are in IT for money and don't actually give a fuck about the software quality (or system integrity). C/C++ scares them and that [hopefully] means that they'll stay away from "real" projects. ;D I know it's a flawed assumption, but it helps me sleep at night... :-/

Matthew Leverton said:

To me, any language that can be compiled to machine code is far from "cheating."

One could argue that any language COULD be compiled into machine code. ;)

Matthew Leverton
Supreme Loser
January 1999
avatar

Quote:

Hmm, I think DMDScript would work nicely

The biggest limitation to using D for my framework is dealing with just-in-time method calls. Since PHP is entirely run in a VM, it's simple:

<mef:loop collection="news.recent(count: 10)" item="n">
  <li>{n.headline}</li>
</mef:loop>

That gets translated to something like:

<?php
foreach ($this->var['news']->recent(array('count'=>10)) as $tmp): $this->var['n'] = $tmp;
echo '  <li>'.$this->var['n']['headline'].'</li>';
endforeach;
?>

The $this is a reference to the Template object. $this->var is an object full of virtual variables that can get evaluated just-in-time. If the requested variable doesn't exist yet, it checks to see if it's been registered in a config file as being just-in-time. If it exists in that file, it returns a new instance of the class, passing the parameters along.

(The $tmp is necessary because $this->var['n'] is a virtual property and they aren't allowed as the recipient of foreach. Limitation or bug, take your pick.)

If I were using D/DMDScript, the machine generated code would be something like:

var tmp = App.getVar('news').recent({count: 10});
for (var i in tmp)
{
  App.setVar('n', tmp<i>);
  document.writeln("  <li>" + App.getVar('n') + "</li>");
}

Obviously some optimizations could be made, like forcing the recipient of the foreach to be a local temporary variable, but that's beside the point.

App.getVar('news') is where it gets complicated. In PHP, it's no big deal:

// after determining the type that "news" should be:
$className = 'DBI_'.$classType;
return new $className;

It's a little more complex than that because I have to pass parameters, but it works pretty good.

But D, being compiled, has no way to do that. I'm assuming that DMDScript works by binding D functions as DMDScript variables. So I'd have this in my DMDScript:

1// var FrameWork is bound to some D object
2 
3var App = {
4 varList: {},
5 
6 getVar: function( varName )
7 {
8 if (!varList[varName])
9 {
10 varList[varName] = FrameWork.newClass(varName);
11 }
12 
13 return varList[varName];
14 }
15};

I don't even know if I could return an instance from D to DMDScript like that (via the FrameWork.newClass(varName)). But besides that, how is D going to be able to dynamically create a class?

In D:

class FrameWork
{
  public void* newClass(char[] varName)
  {
    // reading through the config file to find the type of varName is simple...

    var className = fromConfigFile();

    // this is really lame:
    if (className == "News")
      return new DBINews();
    else if ( ... )
  }
}

Most of that is probably not how DMDScript even works, so I really don't think that style is even going to come close to being feasible.

It would be more reasonable to move those run-time classes to DMDScript. For instance:

In DMDScript:

1// This would be a system file that the template guy wouldn't need access to
2var DBI = {
3 News: {
4 recent: function(options)
5 {
6 var news = new Framework.News(); // reference to D object.
7 var count = options.count || 5;
8 
9 return news.recent(count);
10 }
11 }
12};
13 
14var App = {
15 varList: {},
16 
17 getVar: function( varName )
18 {
19 if (!varList[varName])
20 {
21 classType = readFromIniFile(varName);
22 varList[varName] = new DBI[classType];
23 }
24 
25 return varList[varName];
26 }
27};

I think it would have to be something more like that. However, there still are issues on linking dynamically between DMDScript and D. It's just that one layer is rolled back.

Finally, you could say, well put the actual DB code in DMDScript too. But then, we are back to where we've started with the entire system being in a VM. ;D And at that point, I might as well use Python or Ruby.

Or maybe just hack PHP and remove the $, convert -> to . and make $this implicit. 8-)

Thomas Fjellstrom
Member #476
June 2000
avatar

Yeah, I'm still going to finish my clone of your setup ;)

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Sevalecan
Member #4,686
June 2004
avatar

Quote:

Why, except for legacy and maturity purposes, would anyone use C++ over D?

Because I'm paranoid?

I haven't tried D yet, though I have read feature comparisons with C++ on its website.

The thing about D that bothers me? The features are different from C++. You can call it C++++ or whatever, but to me it's an entirely different language. D appears to have different concepts all together, in opposition to C++, with which I'm more familiar. It also seems to be a bit higher level.

Again, I haven't really tried it or anything, or looked into it much more than I've noted. It just scares me, so I never really try. I don't like higher level languages, and I'm afraid of losing features that C++ has and I like.

Maybe it wouldn't bother me so much if it didn't feel like people were threatening to take away my beloved C++. :P

TeamTerradactyl: SevalecanDragon: I should shoot you for even CONSIDERING coding like that, but I was ROFLing too hard to stand up. I love it!
My blog about computer nonsense, etc.

Thomas Fjellstrom
Member #476
June 2000
avatar

You can keep your precious C++. :P

I was never impressed by C++. I never saw the benefits over C to be inticing enough to use it until I found Qt. For what it was lauded for, it just wasn't enough. Not high level enough. Its supposed to be easier than C for pete's sake, and it didn't even do that right ;)

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Sevalecan
Member #4,686
June 2004
avatar

My beloved C++.

In any case, I'm not arguing C++ over C, though I would definitely prefer C++.

If you ask me, the language itself is not bad. It has what I need. I'll admit the standard library and STL may be a bit lacking, but as you've pointed out, there are things to fill those gaps.

TeamTerradactyl: SevalecanDragon: I should shoot you for even CONSIDERING coding like that, but I was ROFLing too hard to stand up. I love it!
My blog about computer nonsense, etc.

BAF
Member #2,981
December 2002
avatar

What does C++ offer that higher level languages don't? C++ is somewhat high level itself.

nonnus29
Member #2,606
August 2002
avatar

There's only one thing I measure a language by: how little I have to code to use it. I look for languages and libraries that multiply my productiveness. For example, I created a graph visualization application for a class last year (screen shots on my blog). I used java and about 5 open source libs. I never could've created the application I did with c, c++, or any other language.

I want tools that let me be as productive as 10 or 100 normal programmers. C, C++, and probably D aren't the tools, but they can be used to build the tools.

Sevalecan
Member #4,686
June 2004
avatar

Quote:

I never could've created the application I did with c, c++, or any other language.

Why does that seem 99.9% likely to be a gross exaggeration. Sure, you may not have been able to do it in the same amount of time... But not at all?

Quote:

I want tools that let me be as productive as 10 or 100 normal programmers. C, C++, and probably D aren't the tools, but they can be used to build the tools.

Well, I'll agree that some tools are better suited to certain jobs, the only way you're going to get much higher than 10 times as productive per amount of time probably depends on you not reimplementing lots and lots of features under another language.

I'm sure there's something out there to make it quicker.

Quote:

What does C++ offer that higher level languages don't? C++ is somewhat high level itself.

I find it incredibly difficult to manipulate and handle binary data.

In any case, there have been times I've wanted to write something in a higher level language and been unable to because it lacks basic functions. Which seems to be caused by certain things being completely covered up for "ease of use" (and under the assumption that you'd never need them directly).

I might just be talking out of my ass(blame the paranoia ;) ), but I'm writing this not actually knowing the reason I said D looked higher level. Maybe it's because it's supposed to be so damn "easy".

D probably isn't that bad, in actuality though. If it's supposed to replace C++, it should allow a route to the bottom of it's functions and allow a person to do whatever they please.

TeamTerradactyl: SevalecanDragon: I should shoot you for even CONSIDERING coding like that, but I was ROFLing too hard to stand up. I love it!
My blog about computer nonsense, etc.

bamccaig
Member #7,536
July 2006
avatar

IIUC, C# has a pretty nice design. For regular use of the language things like references and such are taken care of automatically. However, there is also what they call unsafe code (which actually requires the unsafe keyword) to provide lower level access if you know what you're doing. It's also nice because it highlights the dangerous parts of code so you know to be extra careful with them.

D and C# sound pretty similar so far... I'd like to see an unbiased comparison between them.

Matthew Leverton
Supreme Loser
January 1999
avatar

Quote:

Why does that seem 99.9% likely to be a gross exaggeration. Sure, you may not have been able to do it in the same amount of time... But not at all?

I'm sure the time limit was implied.

Quote:

but I'm writing this not actually knowing the reason I said D looked higher level. Maybe it's because it's supposed to be so damn "easy".

Considering D lets you drop into assembler and call any C library function (including malloc() and free()), I don't really think it's lacking any power. If you take a look at D and try it out, I think you'll quickly find yourself wondering why C++ isn't more like it.

Edit: Regarding D vs C#, see this chart. It's since been taken down, which means maybe it was out of date. Also, of course, it's not meant to show the other language's advantages.

I think the biggest differences would stem from D being a compiled language. As such, it gives you lower level access ... but cannot do quite as much run-time magic.

bamccaig
Member #7,536
July 2006
avatar

Apparently D can't use C++ libraries, however (at least "not easily"). I find it odd that a language designed to replace C++, capable of implementing C libraries, doesn't support C++ libraries... :-/ Or am I misinformed?

CGamesPlay
Member #2,559
July 2002
avatar

Well, C++ libraries have always been a bitch to deal with: name mangling isn't standardized, so a C++ library from one compiler won't work in another. And I don't mean "may not work"--it really won't work.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

bamccaig
Member #7,536
July 2006
avatar

CGamesPlay said:

Well, C++ libraries have always been a bitch to deal with: name mangling isn't standardized, so a C++ library from one compiler won't work in another. And I don't mean "may not work"--it really won't work.

What do you mean by name mangling? :-/???

CGamesPlay
Member #2,559
July 2002
avatar

Run objdump on a C++ DLL and you will see things like _ZNSi3getEv. That's called name mangling and it translates to std::istream::get(). Each compiler does this differently. Name mangling is what allows the compiler to tell the difference between void foo(int) and void foo().

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

bamccaig
Member #7,536
July 2006
avatar

CGamesPlay said:

Run objdump on a C++ DLL and you will see things like _ZNSi3getEv. That's called name mangling and it translates to std::istream::get(). Each compiler does this differently. Name mangling is what allows the compiler to tell the difference between void foo(int) and void foo().

There was never a standard for this in C++ compilers? :-/

23yrold3yrold
Member #1,134
March 2001
avatar

That is the standard. :)

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

nonnus29
Member #2,606
August 2002
avatar

Quote:

Why does that seem 99.9% likely to be a gross exaggeration. Sure, you may not have been able to do it in the same amount of time... But not at all?

Yes, the implication was 'with in the time limit of one semester', my bad.

I've since seen two commercial products that provide a legacy system visualization diagrams somewhat like what I produced (although with additional features and a higher level of refinement) that have site licenses of over $100k per year.

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

There was never a standard for this in C++ compilers? :-/

Name mangling itself is standard, but the style of the mangling is not. Early C++ compilers just translated code to C and were compiled normally (meaning it had to mangle to valid C symbols), while others didn't bother with that step.

Wikipedia explains it quite well:

http://en.wikipedia.org/wiki/Name_mangling said:

While it is a relatively common belief that standardised name mangling in the C++ language would lead to greater interoperability between implementations, this is not really the case. Name mangling is only one of several application binary interface issues in a C++ implementation. Other ABI issues like exception handling, virtual table layout, structure padding, etc. cause differing C++ implementations to be incompatible. Further, requiring a particular form of mangling would cause issues for systems where implementation limits (e.g. length of symbols) dictate a particular mangling scheme. A standardised requirement for name mangling would also prevent an implementation where mangling was not required at all — for example, a linker which understood the C++ language.
The C++ standard therefore does not attempt to standardise name mangling. On the contrary, the Annotated C++ Reference Manual (also known as ARM, ISBN 0-201-51459-1, section 7.2.1c) actively encourages the use of different mangling schemes to prevent linking when other aspects of the ABI, such as exception handling and virtual table layout, are incompatible.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Simon Parzer
Member #3,330
March 2003
avatar

D for a web framework seems a bit risky. What about Perl or Python?

CGamesPlay
Member #2,559
July 2002
avatar

Interpreted languages, loose typing... bad idea.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Indeterminatus
Member #737
November 2000
avatar

The thing that lured me into trying D was mostly its nice support for the Design by Contract paradigm. So far, it's the only language I know that truly supports preconditions, postconditions and invariants as part of the language.

Having said that, the lack for a proper IDE is the thing that keeps me from using D in a production environment (I tried a few, none of which was usable enough yet).

I'm a fan of the language, and given a proper IDE and more libraries, I'd be using it "for real" as well -- what I'm doing now with it is basically playing around.

_______________________________
Indeterminatus. [Atomic Butcher]
si tacuisses, philosophus mansisses

Matthew Leverton
Supreme Loser
January 1999
avatar

Quote:

D for a web framework seems a bit risky. What about Perl or Python?

Right now I'm using PHP for it, and it works well. For a typical web site, I'd use it over Perl, Python, or Ruby simply because PHP has native support for running in a web server. (That's its primary purpose.)

Writing a framework with it is still possible, but it's less than ideal. The reason is that it's already an interpreted language. Adding another layer on top of it can really hurt performance. This is why my templates are actually translated to raw PHP code and cached at run time. I don't want to introduce another virtual layer.

While that works well, the rest of the framework still has to be written in PHP. But there's a lot of higher level things I'd like to add that are just impractical to do. (I'd like to add things to the core language.) So what I've considered is writing my own custom language that just gets translated to PHP, similarly to what I do with the templates.

And yes, languages like Python and Ruby are more flexible than PHP, but I'd still have to do the same thing. MVC frameworks already exist that use an existing language as-is (e.g. Rails [Ruby], Django [Python]). They are all good and well, but they require you to learn so much about the framework, to me, you might as well be learning a language/script that was designed from the top down to do what it's doing.

So ideally, I'd write the framework in a language like D and just skip all this translating to another scripting language. Of course that's a large task, and for a long time will probably only be a personal, hobby project of mine.

Quote:

having said that, the lack for a proper IDE is the thing that keeps me from using D in a production environment

I don't mind the lack of IDE support. I just use UltraEdit (with a D syntax highlighting file) on Windows, save to my mapped virtual Linux drive, and run make in a Putty terminal. But, like you, I'm just playing around with it at the moment. However, I've seen enough to never use C++ again.

CGamesPlay
Member #2,559
July 2002
avatar

If you were to write the framework in .NET 1.1, you could actually (easily) compile the code to .NET 1.1 executables. Since you used 1.1 and not 2.0, Mono could then actually compile them to native images.

Of course, D will yield enough performance by itself, so blah :P

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>



Go to: