Live data from Hacker News

Why I use the D programming language for scripting (2021)

opensource.com

21–30 of 53 posts

Re: Why I use the D programming language for scripting (2021)

#21
post #3

I used D for a small prototype. I wrote that same program in GO, C# and Java(native compiled with GraalVM). The CPU and RAM usage of D-lang out performed all other languages. Compiled binary size: D-Lang : 450KB Go : 2 MB C#(.NET) : 8 MB Java-GraalVM: 9 MB D-Lang CPU & RAM Usage is also less than GO. Unfortunately D-Lang is not popular, not many libraries available.

C# and Java have a large base. If you write a small application with it the size will be huge because they both link in the base in the application. It becomes more interesting with larger applications.

D standard library uses much templates. So only what's used or what is not templatized get linked in the binary. The runtime somewhat tries to follows this too, aka the "pay-as-you-go" strategy as it is called in the dlang world.

For small applications this works even if certain templates can easily lead to have half of the standard library pulled in (e.g a few conversion, a few format, a few regex and boom, the size explodes).

A subset of the language called betterC allows to fully get rid of the "base", but requires to write much more code to get things done. Maybe this is why prakis managed to get the smaller binary ? The comment is not very clear about the methodology...

Re: Why I use the D programming language for scripting (2021)

#22

Earlier quoted context omitted.

C# and Java have a large base. If you write a small application with it the size will be huge because they both link in the base in the application. It becomes more interesting with larger applications.

Not necessarily anymore now that .NET has had a lot of enhancements for compiling to native and stripping unused references.

I think a lot of people who write off C# don't realise how much it has advanced particularly in the last few years.

Re: Why I use the D programming language for scripting (2021)

#23
Hope it's not seen as criticism... but I could love more elaborate examples...

Checking the examples, my friction here is... why should I introduce a new language for those things?

First example program equivalence:

    tr -s ' ' '\n' 
Second program equivalence:

    awk 'NR 
It takes to me more time, to understand what is doing D, even if theres is a previous explanation, that write down the equivalence with known tools.

The last example needs to download/install dependencies, from the outside of the upstream software origins of my servers (that's a no-no in many places). apt-cache search vibe is no good for me.

If I could have need a program like that simple web example, nowadays I could go with golang, compile and deploy.

But the first two other solutions that come to my mind...

    perl -Mojo -E 'a("/")->to_text(sub {
        "Hello World " . shift->req->url->path
    })->start' -l http://localhost:8080
Or something like...

    from flask import Flask, request
    
    app = Flask(__name__)
    
    @app.route('/')
    def hello_world():
        path = request.path
        return f'Hello World {path}'
    
    if __name__ == '__main__':
        app.run(host='localhost', port=8080)
I know that apt-get install libmojolicious-perl or install python3-flask is not an issue in many internal audits we did pass. Perl an Python are already present in the servers... or if puppet is in use, maybe ruby?

    ruby -rwebrick -e"WEBrick::HTTPServer.new(Port: 8000){ |req, res| res.content_type = 'text/plain'; res.body = 'Hello World ' + req.path; }.start"
But I know many places were adding new languages, using external package repositories for scripting languages, etc, is a problem...

So, if it's for that article, I'm not 100% convinced to switch to D or invest my time in it... maybe I'm not the target audience.

I've nothing against D itself, but I need better marketing to be attracted.

Re: Why I use the D programming language for scripting (2021)

#24
post #2

I've never given D a fair shake before, so my opinion of it is very weakly held, but up until now I've always thought of it as C++ with even more piles of crap bolted on. Reading the examples here makes me think that I was wrong and that I should give it a real try, because this looks like a sufficiently elegant language that I would actually want to use.

I highly recommend giving it a go! It's hands down my favorite language.

Re: Why I use the D programming language for scripting (2021)

#25
post #2

I've never given D a fair shake before, so my opinion of it is very weakly held, but up until now I've always thought of it as C++ with even more piles of crap bolted on. Reading the examples here makes me think that I was wrong and that I should give it a real try, because this looks like a sufficiently elegant language that I would actually want to use.

[deleted]

Re: Why I use the D programming language for scripting (2021)

#26

If I write an application I use Java as I am most comfortable with it. But it is not always the best choice. If I needed to write an application for windows with a GUI I would be more successful with C# as it would look more native. If I am writing a command line tool it would be a faster and smaller application if I build it in Go, Dart or Crystal. But then I would need to be good in it as well. I like seeing these…

Admittedly I don't know Groovy well and I'm a bit biased due to bad experiences with Gradle builds and Jenkinsfiles.

But if you're most comfortable with the JDK, Scala 3 with the Scala CLI provides an unmatched developer experience for small scripts and command line tools. And the output can be self-contained JAR, a GraalVM native image, or even a Scala Native binary if you use compatible libraries.

Re: Why I use the D programming language for scripting (2021)

#27
post #19
post #13

Earlier quoted context omitted.

What is in your list of acceptable languages, and what is your list of unnecessary languages? Is date of creation a factor? Because D was created last century.

So it's over 20 years old yet nobody knows it exists. Doesn't sound very promising. The first time I heard of it was someone who uses it frequently complaining about too many breaking changes in minor updates. So it's unknown and unreliable. Who gives a crap if it has elegant syntax, it's just another way to write the same stuff. The examples from the article can be done in JS, python, java, c# almost exactly the sam…

I don’t think it’s fair to knock a language on rate of popularity, unless your point is community adoption.

That being said, I agree with everything else you said lol.

All the “elegance” in the article just reminded me of what you can achieve using Linq, or pythons list comprehension (which I personally don’t care for).

I used to get excited about one-liners, but if that’s what elegance is, elegance is not important to me. Are you gaining efficiency or playing code golf?

If there’s anything dev jobs have taught me it’s that readability is whats most important. You can keep your fancy lambdas etc.

Those things have their place but it’s not a crime to write a for loop with local variables.

Unless what you’re doing is as simple as a single statement, a mapping or printing something, One liner loops are not as productive or efficient. when you have multiple statements, you’re often just calling multiple loops. And don’t forget the extra time you have to spend to get the damn thing to work, as opposed to a classic for loop.

Re: Why I use the D programming language for scripting (2021)

#28
I think D is a victim of being too early - when it was announced the open source community was still obsessed with C, and D’s garbage collection was seen as an absolute show-stopper (even if the people knocking it largely didn’t try it). By the time Go came out a decade later I guess enough people had been bitten by C that garbage collection was an acceptable option (plus Google’s backing and a more complete standard library).

It’s too bad D didn’t get more traction, writing it really is like writing a script, and the compiler is so fast that the edit-compile-run cycle is faster than some scripting languages. Walter is still a hero of mine!

Re: Why I use the D programming language for scripting (2021)

#30

I think D is a victim of being too early - when it was announced the open source community was still obsessed with C, and D’s garbage collection was seen as an absolute show-stopper (even if the people knocking it largely didn’t try it). By the time Go came out a decade later I guess enough people had been bitten by C that garbage collection was an acceptable option (plus Google’s backing and a more complete standard…

I think its probably that Go was being worked on by Google employees and the fact that GC languages were well accepted. A lot of early converts to Go were Python programmers, C++ devs didnt jump ship to anything else until Rust, I am seeing plenty of places integrating Rust with C++ code in some cases for mission critical code. I mean just look at when Discord switched from Go to Rust. They also used Rust to aide their BEAM VM code.
Post reply on HN