Hello, folks! Newbie to D, have some questions!
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Feb 18 13:09:20 PST 2017
On Saturday, 18 February 2017 at 20:15:55 UTC, timmyjose wrote:
> 2. I am more interested in learning D as a pure systems
> programming language so that I can develop my own tools (not
> looking to develop an OS, just some grep-scale tools to start
> off with). In that regard, I have a few concerns about the GC.
> My rudimentary knowledge of the D ecosystem tells me that there
> is a GC in D, but that can be turned off. Is this correct?
There is a GC, but you can avoid the features that use it.
There's a function attribute for that: @nogc [1]. It forbids
GC-manages allocations. The GC is still there, but it won't do
anything because you're not triggering it.
You can also turn automatic collections off (GC.disable [2]).
There's no need for that when all your code is @nogc, though,
because collections are triggered by allocations.
As for getting rid of the GC entirely (for saving space, I
guess), I think that's more involved. May require changes to
druntime. Shouldn't be necessary most of the time.
> Also, some threads online mention that if we do turn off GC,
> some of the core std libraries may not fully work. Is this
> presumption also correct?
Yes. Whenever a std function returns a new string or some such
it's going to be GC-allocated. There's an experimental module for
custom allocators [3], but the rest of the library doesn't make
use of it, yet. When a std function uses the GC, the compiler
won't let you call it from @nogc code.
> In this regard, I am curious to know if I would face any issues
> (with my intent in mind), or will I do just fine?
I don't think you're going to run into much trouble when making
"grep-scale tools".
[...]
> 4. I have heard good reports of D's metaprogramming
> capabilities (ironically enough, primarily from a thread on the
> Rust user group), and coming from a Common Lisp (and some
> Racket) background, I am deeply interested in this aspect. Are
> D macros as powerful as Lisp macros?
D doesn't have macros. D has templates like C++, string mixins
(insert a statically know/generated string as D code), and CTFE
(Compile Time Function Evaluation, to programmatically generate
static stuff).
> Are they semantically similar (for instance, I found Rust's
> macros are quite similar to Racket's)?
Can't answer this, because I'm not familiar enough with those
languages.
> 5. Supposing I devote the time and energy and get up to speed
> on D, would the core language team be welcoming if I feel like
> I can contribute?
Absolutely. Anyone is welcome to contribute. D is very much a
volunteer effort. Also don't hesitate to point out (or even fix)
any stumbling blocks you may encounter when starting out.
[1] https://dlang.org/spec/attribute.html#nogc
[2] https://dlang.org/phobos/core_memory.html#.GC.disable
[3] https://dlang.org/phobos/std_experimental_allocator.html
[4] http://ddili.org/ders/d.en/index.html
[5] https://tour.dlang.org/
More information about the Digitalmars-d-learn
mailing list