Jump to page: 1 24  
Page
Thread overview
What is your favorite D feature?
Jun 22, 2017
Seb
Jun 22, 2017
Mike
Re: What is your favorite D feature? [Call for snippets]
Jun 22, 2017
Seb
Jun 22, 2017
Mike
Jun 22, 2017
H. S. Teoh
Jun 22, 2017
Jon Degenhardt
Jun 22, 2017
Seb
Jun 22, 2017
Adam D. Ruppe
Jun 22, 2017
Brad Anderson
Jun 22, 2017
Seb
Jun 22, 2017
Eugene Wissner
Jun 22, 2017
Jon Degenhardt
Jun 22, 2017
ketmar
Jun 22, 2017
bauss
Re: What is your favorite D feature? [Call for snippets]
Jun 22, 2017
Seb
Jun 22, 2017
Paulo Pinto
Re: What is your favorite D feature? [Call for snippets]
Jun 22, 2017
Seb
Jun 22, 2017
Ecstatic Coder
Re: What is your favorite D feature? [Call for snippets]
Jun 22, 2017
Seb
Jun 22, 2017
Ecstatic Coder
Jun 22, 2017
Patrick Schluter
Jun 22, 2017
qznc
Jun 22, 2017
Seb
Jun 22, 2017
Era Scarecrow
Jun 22, 2017
k-five
Jun 22, 2017
Guillaume Piolat
Jun 22, 2017
Andrey
Jun 22, 2017
Andrey
Jun 23, 2017
Kagamin
Jun 23, 2017
Anonymouse
Jun 23, 2017
H. S. Teoh
Jun 24, 2017
H. S. Teoh
June 22, 2017
Hi,

I am currently trying to modernize the D code example roulette on the dlang.org front page [1]. Hence, I would love to hear about your favorite feature(s) in D.
Ideas:
- favorite language construct
- favorite code sample
- "only possible in D"

Before you ask, yes - I want to add a couple of cool examples to dlang.org (and yep the roulette rotation is currently broken [2]).

[1] https://github.com/dlang/dlang.org/pulls?q=is%3Apr+is%3Aopen+label%3A%22Frontpage+example%22
[2] https://github.com/dlang/dlang.org/pull/1757
June 22, 2017
On Thursday, 22 June 2017 at 00:48:25 UTC, Seb wrote:

> I would love to hear about your favorite feature(s) in D.

Beginning with most favorite:
 - CTFE
 - static if - If you don't consider that part of CTFE
 - Template Mixins
 - Templates - Pretty much goes along with the top 2
 - String Mixins
 - Unit Tests

DIP1000 may make that list too, if I ever get around to trying it out.

Mike


June 21, 2017
On Thu, Jun 22, 2017 at 12:48:25AM +0000, Seb via Digitalmars-d wrote:
> Hi,
> 
> I am currently trying to modernize the D code example roulette on the dlang.org front page [1]. Hence, I would love to hear about your favorite feature(s) in D.
>
> Ideas:
> - favorite language construct
> - favorite code sample
> - "only possible in D"

Slices!  And preferably in an example where it beats C performance by not needing to duplicate strings everywhere.

Built-in unittests... ddoc'd unittests!  Though it's hard to think of an example showing this off that's short enough to work for the roulette.

Sane template syntax. Template alias parameters. Manipulation of template argument lists.

UFCS.

Compile-time introspection + UDAs.  Loop over a struct defining a set of program configuration parameters, and generate code for parsing command-line arguments that fills in the struct based on field definitions.  (You could just transform the struct members into getopt arguments, as implementing this from scratch could be a bear... and ugly to look at. :-D)

std.process making it dead easy to invoke an external program, capture
its output, all without the ugliness of manually dealing with fork(),
execv(), and waitpid().


> Before you ask, yes - I want to add a couple of cool examples to dlang.org
[...]

You could search for "your code here" in the forum -- that used to be the instructions on submitting code examples back before the website was revamped, and IIRC there have been a handful of suggestions, though AFAIK none was ever actually added to the roulette.


T

-- 
Those who don't understand Unix are condemned to reinvent it, poorly.
June 22, 2017
My fav is that familiar code just works.
June 22, 2017
On Thursday, 22 June 2017 at 00:48:25 UTC, Seb wrote:
> Hi,
>
> I am currently trying to modernize the D code example roulette on the dlang.org front page [1]. Hence, I would love to hear about your favorite feature(s) in D.
> Ideas:
> - favorite language construct
> - favorite code sample
> - "only possible in D"
>
> Before you ask, yes - I want to add a couple of cool examples to dlang.org (and yep the roulette rotation is currently broken [2]).
>
> [1] https://github.com/dlang/dlang.org/pulls?q=is%3Apr+is%3Aopen+label%3A%22Frontpage+example%22
> [2] https://github.com/dlang/dlang.org/pull/1757

A very simple vibe app could be added using dub's single-file package format. Something like (I haven't tried this):

    #!/usr/bin/env dub
    /+ dub.sdl:
        name "hello"
        dependency "vibe-d" version="~>0.8.0-rc.1"
    +/
    import vibe.d;

    shared static this()
    {
        auto settings = new HTTPServerSettings;
        settings.port = 8080;

        listenHTTP(settings, &handleRequest);
    }

    void handleRequest(HTTPServerRequest req,
                  HTTPServerResponse res)
    {
        if (req.path == "/")
            res.writeBody("Hello, World!", "text/plain");
    }

    // Dependencies fetched, compiled, cached, built against, and result executed
    // in one command:
    //     $ ./hello.d
June 22, 2017
On Thursday, 22 June 2017 at 00:48:25 UTC, Seb wrote:
> Hi,
>
> I am currently trying to modernize the D code example roulette on the dlang.org front page [1]. Hence, I would love to hear about your favorite feature(s) in D.
> Ideas:
> - favorite language construct
> - favorite code sample
> - "only possible in D"
>
> Before you ask, yes - I want to add a couple of cool examples to dlang.org (and yep the roulette rotation is currently broken [2]).
>
> [1] https://github.com/dlang/dlang.org/pulls?q=is%3Apr+is%3Aopen+label%3A%22Frontpage+example%22
> [2] https://github.com/dlang/dlang.org/pull/1757

ranges
nice operator overloading
June 22, 2017
On Thursday, 22 June 2017 at 01:13:43 UTC, H. S. Teoh wrote:
> On Thu, Jun 22, 2017 at 12:48:25AM +0000, Seb via Digitalmars-d wrote:
>
> [snip]
>
> Slices!  And preferably in an example where it beats C performance by not needing to duplicate strings everywhere.
> ...

For slices the example in blog post I wrote might serve (https://dlang.org/blog/2017/05/24/faster-command-line-tools-in-d/). To shorten it drop the associative array component. For example, sum the values in a specific field.

--Jon

June 22, 2017
On Thursday, 22 June 2017 at 01:13:43 UTC, H. S. Teoh wrote:
> Slices!  And preferably in an example where it beats C performance by not needing to duplicate strings everywhere.

There's one in the queue, feel free to vote for or destroy it:

https://github.com/dlang/dlang.org/pull/1756

> Built-in unittests... ddoc'd unittests!  Though it's hard to think of an example showing this off that's short enough to work for the roulette.

Yes ... ideas welcome ;-)

> Sane template syntax. Template alias parameters. Manipulation of template argument lists.

Do you have anything specific in mind?

> UFCS.

Absolutely agreed, but how do we show this?
Range - one of the best uses cases - are already shown.

> Compile-time introspection + UDAs.  Loop over a struct defining a set of program configuration parameters, and generate code for parsing command-line arguments that fills in the struct based on field definitions.  (You could just transform the struct members into getopt arguments, as implementing this from scratch could be a bear... and ugly to look at. :-D)

Ok - I gave it a shot, but it got quite long. Any ideas on trimming it down?

https://github.com/dlang/dlang.org/pull/1762

> std.process making it dead easy to invoke an external program, capture
> its output, all without the ugliness of manually dealing with fork(),
> execv(), and waitpid().


I realized std.parallelism gives an excellent showcase as well:

https://github.com/dlang/dlang.org/pull/1760

And created another one for std.process:

https://github.com/dlang/dlang.org/pull/1761

Feedback welcome!

> You could search for "your code here" in the forum -- that used to be the instructions on submitting code examples back before the website was revamped, and IIRC there have been a handful of suggestions, though AFAIK none was ever actually added to the roulette.

Thanks, but I can only remember spam being posted with "your code here".
The search also doesn't show any results for me...
June 22, 2017
On Thursday, 22 June 2017 at 01:42:10 UTC, Brad Anderson wrote:
> A very simple vibe app could be added using dub's single-file package format.

Hmm this is a great idea, but it wouldn't be "runnable" on the web.
Here's a PR for discussion:

https://github.com/dlang/dlang.org/pull/1763

> Something like (I haven't tried this):

You can even go more minimal - the following works:

#!/usr/bin/env dub
/+ dub.sdl:
name "hello_vibed"
dependency "vibe-d" version="~>0.8.0-rc.1"
versions "VibeDefaultMain"
+/
import vibe.d;

shared static this() @safe
{
    auto settings = new HTTPServerSettings;
    settings.port = 8080;
    listenHTTP(settings, (req, res) {
        res.writeBody("Hello, World: " ~ req.path);
    });
}
June 22, 2017
On Thursday, 22 June 2017 at 00:48:25 UTC, Seb wrote:
> Hi,
>
> I am currently trying to modernize the D code example roulette on the dlang.org front page [1]. Hence, I would love to hear about your favorite feature(s) in D.

A couple more:
- std.conv.to - Safe, convenient conversions that just work.
- std.regex - Really well done. May be hard to illustrate all the capabilities in a few examples
- Pragmatic functional programming constructs. No guessing about performance. Purity with local mutable variables. Interaction with UCFS.

--Jon
« First   ‹ Prev
1 2 3 4