1. 32
    1. 3

      Id like to see a feature comparison of D and Zig.

      1. 5

        I admire Walter Bright and the D language & community. I think the project sets a great example, and parts of Zig were inspired by or at least informed by the D language. That said, in the spirit of friendly competition, here’s one difference: how lean binaries are:

        $ zig build-exe hello.zig --release-small --strip --single-threaded 
        $ strip ./hello
        $ ./hello
        Hello, World!
        $ ls -ahl ./hello
        -rwxr-xr-x 1 andy users 6.0K Jul  3 19:18 ./hello
        $ ldd ./hello
        	not a dynamic executable
        

        vs

        $ dmd hello.d -O -release -inline -boundscheck=off 
        $ strip hello
        $ ./hello
        Hello, World!
        $ ls -ahl hello
        -rwxr-xr-x 1 andy users 699K Jul  3 19:13 hello
        $ ldd ./hello
        	linux-vdso.so.1 (0x00007fffc8591000)
        	libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007ff03913a000)
        	libm.so.6 => /usr/lib/libm.so.6 (0x00007ff038fa4000)
        	librt.so.1 => /usr/lib/librt.so.1 (0x00007ff038f9a000)
        	libdl.so.2 => /usr/lib/libdl.so.2 (0x00007ff038f95000)
        	libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007ff038d7f000)
        	libc.so.6 => /usr/lib/libc.so.6 (0x00007ff038bc7000)
        	/usr/lib/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007ff03915d000)
        

        I’m sure there are plenty of things D could show off in this thread. And please let me know if there are other flags I could pass above.

        1. 3

          Using your example, I used D’s betterC mode

          https://dlang.org/spec/betterc.html

          dmd -betterC hello_betterc.d

          Getting 8.2K executable.

          $:~/d-vs-world/binsize$ ls -ahl hello_betterc
          

          rwxr-xr-x 1 v v 8.2K Jul 4 01:46 hello_betterc

          /d-vs-world/binsize$ ./hello_betterc Hello betterC

          /d-vs-world/binsize$ ldd hello_betterc

          linux-vdso.so.1 (0x00007fff79d32000)
          
          libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc80ce40000)
          
          /lib64/ld-linux-x86-64.so.2 (0x00007fc80d433000)
          

          cat ./hello_betterc.d 
          
           extern(C) void main()
           {
             import core.stdc.stdio : printf;
             printf("Hello betterC\n");
           }
          

          dmd –version

          DMD64 D Compiler v2.086.1-beta.1

          (sorry, had to make several formatting updates to the post)

          1. 2

            Ah! Thank you for sharing this. I tried to use -betterC but I didn’t know how to get past the compile errors from my hello world code:

            import std.stdio;
            
            void main()
            {
                writeln("Hello, World!");
            }
            

            which gave:

            /usr/include/dmd/std/stdio.d(3806): Error: template std.stdio.File.LockingTextWriter.put cannot deduce function from argument types !()(string), candidates are:
            /usr/include/dmd/std/stdio.d(2865):        std.stdio.File.LockingTextWriter.put(A)(scope A writeme) if ((isSomeChar!(Unqual!(ElementType!A)) || is(ElementType!A : const(ubyte))) && isInputRange!A && !isInfinite!A)
            /usr/include/dmd/std/stdio.d(2895):        std.stdio.File.LockingTextWriter.put(C)(scope C c) if (isSomeChar!C || is(C : const(ubyte)))
            hello.d(5): Error: template instance `std.stdio.writeln!string` error instantiating
            

            I see now that the trick was to use core.stdc.stdio.printf.

      2. 3

        I have only read about Zig but they feel very different too me on a high level.

        Zig wants to be a simple language: Few features that can be combined in powerful ways.

        D wants to be a comprehensive language: Many features so wherever you go you have the right tool for the job.

    2. 3

      D has been a real pleasure for me. I did the 2017 AoC in it.

      The richness and flexibility of compile-time features almost make it feel like a lisp, with the slight downgrade of sometimes working on strings of source code instead of sexps. Regardless, like the article says, D’s metaprogramming alone is worth the entry price of reading a few books or tutorials about the language.

      1. 1

        The richness and flexibility of compile-time features almost make it feel like a lisp, with the slight downgrade of sometimes working on strings of source code instead of sexps

        What do you mean working on strings?

        1. 4

          I’ve just been reading the tour, prompted by this article. I believe it’s to do with mixins and other compile-time function stuff.

          1. 3

            Yes, string mixins. It’s kind of a compile-time eval but with some restrictions to prevent certain kinds of abuse of other evals in other languages.

            But that’s just one tool, there’s lots of other ways to metaprogram in D that don’t require building strings of code yourself.

    3. -10

      nope