365 points · by chmike · 13y ago · 232 comments
https://groups.google.com/forum/#!topic/golang-nuts/8k59RgkeJ6s
The discussion between Andrei Alexandrescu (Facebook) and Ian Lance Taylor (Google) is highly intellectual, especially the part about how each language addresses concurrency.EDIT: Removed dot at the end of the URL
"D has resolutely exited C++'s shade because it is good at things C++ is not good at, in addition to being good at things C++ is good at. Also, Go would be tenuous to frame as a better C because it cannot do everything C does - e.g. unsafe memory access and manual memory management, which are needed in certain systems - and it interoperates poorly with C."
In short, he states that D can do unsafe memory access and manual memory management. Go can't.
Go is a great systems programming language especially for modern concurrent systems — http servers etc. It talks to C easily so you can integrate all kinds of system level code into your apps. Having a Garbage collector makes it trivial to write long-running daemons.
Modern operating systems have traditionally been written in C (and C++) plus some assembly language code. D can do everything C & C++ can do but it would still no doubt need the assembly language code.
Go lacks manual memory management. Some say that this would be a barrier for writing an operating system while others don't. The fact that you would have to use some assembly language code to talk to the hardware and you might need to add some manual memory management via assembly language code. After that I'm sure the garbage collector would make the OS more reliable and potentially a little quicker in places.
Either way I don't see why Go gets criticised for needing a bootstrap layer when operating systems written in C and C++ also need this.
In a lot of contexts, this is a feature (makes terrible code smells in normal code easier to see), but depending upon the type of coding you do, you do sometimes find yourself wishing it were a bit easier when dealing with things like graphics APIs where you just want to lock a texture, update some bits in-place, and then unlock it. Sometimes what might be a couple lines of C code are 10s of lines of Go code where you either do crazy gymnastics with the unsafe package, or juggle things in and out of byte buffers.
However, like many flaws with HN's underdeveloped software, you can't actually do that on HN because the parser includes the trailing > in the URL. So your best bet here is with whitespace.
How does the language do this? Doesn't that have more to do with the design of the program itself? It certainly is a interesting security idea, much more strict than sending remote procedure calls or serializing objects and sending them across the network.
(Although due to this announcement, the site is being slammed at the moment. It's a single server hosting dlang.org, not a farm.)
I remember finding the website disturbingly fast on my first visit. I wonder if it is just me being so used to loading delays, or if there is a point were you can be so fast that it is detrimental to the user experience. The latter doesn't sound like it makes sense so it must be of matter of getting used to it.
Forums these days need to allow for multiple users to log in, read content and post messages. I'm pretty sure that the link above received several hundreds or thousands of users in a single hour. Forums these days also use database systems (or other services external to the process) that represent a big bottleneck. Then you've got the issue of static assets, like CSS, Javascripts, images and so on.
As a general rule of thumb, if you want scalability, you have to trade some throughput for it, as scalability concerns hurts performance.
That said, popular open-source web software, in general is awful in terms of everything.
It does not send a complex JSON object that is then marshalled into some kind of Angular-Knockout-Backbone framework of the day where complex magic creates views, links and templating language formats objects into HTML created via DOM.
As JS in the browser speed up, all those framework find some way of using it. Sure, your 5-item TODO list app looks good...
It is ridiculously fast.
Back to the 90s URLs.
I mean, yes, superficially this is less obtuse:
http://advrider.com/forums/showthread.php?t=801516
But the number holds no meaning to a human either way.
http://advrider.com/forums/showthread.php?t=801515
exist (while http://advrider.com/forums/showthread.php?t=801517 doesn't at this time).
"Normally" such an app (avrider) would be set up with routing such that the url became /forum/thread/<id> -- and with a simple 6-digit id, that's much more managable to type/communicate manually than an uuid or something.
All that said, I basically agree -- exposing some "magic" constant/serial number to the user usually doesn't do much to help with the ux. It's actually an interesting problem: what would be the better, more "true" web/REST-like url-scheme for a forum? Perhaps forum/topic/sub-topic/thread-topic ? How limiting would that be wrt. reorganizing the forum threads (and not breaking links) -- this is especially an issue if there's a chance of re-using uri's -- it's annoying to have a link to one discussion morph into a link to another one. I don't think there are any solutions that are significantly better than a (symbolic/numerical) thread/topic id...
edit: Actually I see the sense in the email-id-like urls of the d-mars forum (or usenet-like).
https://github.com/d-programming-language
Naturally, contributors are welcome!
If Google picked up D I would be much more interested as to why.
So, this is just one step forward, but it's a big one and exciting to the folks who are fans of D - especially those who have put a lot of time and effort into it.
I was using the other standard library (yeah, there were two, kind of), there were bugs which weren't resolved for years, there were issues with people camping on both sides of standard libraries, there was development stagnation because D2 was being pushed hard... but it all boils down to preference.
D1 (with Tango) to me was like a really really good blend of C with classes and modern stuff in it (mixins for example). I was happy with it, but then D2 started to emerge which was more templatey than I was comfortable with. I have accepted, long ago, that I am a C programmer, not C++, by heart. Ultimately following factors threw me away from D altogether:
- my code isn't an island, I leverage a lot of libraries, and for each and every one I had to use I had to either make my own bindings or rely on somewhat unstable other people's bindings. I accepted the reality of it, but it wasn't something I wanted to waste my time on.
- D2 - it just didn't feel the same
- Lack of tools. DMD compiler, while somewhat working, was a lackluster (to be polite) compared to what I was used to in C world. There was a GDC frontend for gcc which, at the time, wasn't actively developed, there was an attempt to make a LLVM thing.. but if you wanted to work with D, at that time, you pretty much had to use DMD
- several bugs which were ignored in core development which were uncomfortable for my use. I didn't have the expertise at the time to help with resolving that. Coincidentally just yesterday I received an update from bug tracker that bug I reported four years ago is still in.
- Development of D pretty much relied on one man alone
- out of frustration and a tight deadline, I developed something in C at that time and came to a realization that "it just works". I was able to concentrate on my task at hand instead of tackling various gotchas and doing extra amount of work that I had to with bindings etc.
D is more than 10 years old. Honestly, I think it has good ideas, I really liked the approach of D1, but I think it will never catch on en masse.
The Tango/Phobos split has been resolved for awhile. You can now use Phobos, Tango, or both in the same D2 program.
The number of libraries and bindings is growing rapidly. There is the new dub package manager that makes it easy to include dependencies < http://code.dlang.org/ > and Deimos which is a collection of C library bindings < https://github.com/D-Programming-Deimos/ >.
GDC and LDC are both actively developed and kept up to date with the state of DMD.
It used to be you'd usually hit a bug while working on something in D but the community is really starting to notice they aren't hitting many bugs these days (especially over the last year or so). < http://dlang.org/bugstats.php >
Everything is up on Github now < https://github.com/D-Programming-Language > and Walter is just one of 21 committers. Github says dmd has 72 contributors and Phobos has 116.
If you don't like D2's template approach though you probably still won't be happy with it even with almost everything being better. Personally I love the power it gives you without sacrificing speed.
That said, D has a lot of promise, and a lot of these issues have been worked out, but I feel like there are many people like you and I...
History proves that the only system programming languages that succeed in the industry, have been at a given moment adopted by OS vendors as their main language.
It hasn't happened so far to D, but it might still happen.
"Aside from speaking whether 5112 lines of code is really a good sign, there is separate issue regarding quality. When you will look at claim that some language (lets take for example C# or Java) "supports feature X", that really means that the feature is supported. In D this for sure means that the feature is either broken or misdesigned (shared libraries, routine code breakages, obsolete ms32 object format, AA arrays, shared, const postblits, odd template crosstalk bugs, type system holes, segfaulting lambdas, unstable stdlib, absent of third-party libraries). Untill this stuff is fixed this is a huge barrier irrespective of whether D is used in Facebook or not."
The situation is better and greatly improving. Many things have a work around. It is just one of the problems with a language full of tools and little full-time man power. Java and Go are rather simple languages so there aren't as many features to boast (e.g. not supporting shared libraries is a feature of Go, yet "broken" in D [lots of good work in git HEAD])
I checked, to get the facts straight: DMD is the reference implementation. The frontend is under GPL but the backend (optimizer and codegen) is not. The source code is available but you are not allowed to redistribute it.
https://github.com/D-Programming-Language/dmd/blob/master/sr...
(I wonder if you are allowed to fork it on GitHub.)
[1] http://gdcgnu.sourceforge.net/ [2] https://github.com/ldc-developers/ldc
(In my tests, they are also mostly the fastest ones, especially LDC ... see for example my comparisons in http://saml.rilspace.org/moar-languagez-gc-content-in-python... ... D with LDC is among the top contenders, together with various optimized C versions ...)
- C++11 is good enough (and a little better than that)
- The eco system. Yes, I can use C libs from dlang but managing extra bridges/headers is too much overhead if the alternative is just to throw them into my C++ project and use them without writing any glue code.
- The garbage collector. (RAII fan here)
- Tooling. Are there any good dlang IDEs with mature refactoring support and code completion?
For the tasks I'm using C++ for, C++11 is more than sufficient. For more abstract/high level stuff where I don't particularly care about top performance/memory layout I don't need another C++ contender but can use higher level languages/scripting languages.
D would look more tempting if there was no C++11 but for now for me I'm perfectly happy with C++.
- Sensible, pragmatic design decisions.
- dub + VisualD makes building code, managing dependencies and debugging painless for me.
- being part of building the ecosystem is fun
- I'm not comfortable with the high cost of developing in C++ (even with last revision) and never chose to use it in the first place. C++ is basically forced on me since years.
- I feel like I can be more productive and write higher quality programs when using D. I can use RAII in D like I would in C++.
- I feel like Go and Rust do not address C++ shortcomings while introducing problems of their own.
- D programs are short. I don't need nor want IDE refactorings.
You can use RAII all you want in D. The D standard library uses it for things like Files, containers, and smart pointers. I feel like Garbage Collectors have become something of a bogeyman for native languages. There is a lot of value a garbage collector can add. In D it's rarely hard to switch to managing your own memory if your profiler shows the garbage collector taking up more time than you'd like. For most programs avoiding the garbage collector is a premature optimization though.
For IDEs you have: - Mono-D http://mono-d.alexanderbothe.com/ - VisualD (should be included with Windows DMD in the next release) https://github.com/D-Programming-Language/visuald - Code completion for a variety of editors including vim, emacs, SublimeText2 , Textadept, and zeus. DCD https://github.com/Hackerpilot/DCD
Is it just that maintaining ownership semantics for heap memory tends to be more complicated than doing the same for file objects (much more rarely shared, I'd guess) or mutexes (not sure if "sharing" is even sensibly defined here).
- RAII-style freeing means a lot of reference counting. Reference counting and multiple threads don't mix well. You can circumvent that by having multiple separate heaps, but that's not always a practical solution.
- Reference counting is slow; if you want GC-like speed and RC-like pause time guarantees, you're probably better off with deferred reference counting, but that's not easy to engineer into C++; it's essentially a form of garbage collection.
- Lack of fully automatic memory management may affect modularity adversely; see Jones/Lins for the gory details. In brief, wholly or partly manual memory management creates leaky abstractions (this is if you eschew RC for some of your code/types for speed reasons or because you need to deal with cyclic references).
- It is not difficult to have scoped deallocation for resources (scope statement in D, using statement in C#, etc., destructor pragma in Nimrod). Resource lifetime, in any event, does not always coincide with the lifetime of a variable, so this is an incomplete solution. Using GC does not mean not using RAII where its downsides do not matter.
That being said, D does not require the GC. It's easier if you use it for at least some of the features, but D makes it very easy to use RAII and manual memory management, which also helps a lot in making the GC work better, because it's much easier to avoid making a lot of garbage for it to collect when you don't need to. A lot of stuff in D ends up on the stack rather than the heap, and D's GC ends up having a lot less work to do than the GC does in languages like C# or Java. That being said, the current GC implementation needs some work (and effort is definitely put forth in that area), but if you don't want to use the GC, you can minimize its use or even outright avoid it (though _completely_ avoiding it can be a bit annoying since that means avoiding a few language features that require it; that list is short though).
So, while D definitely uses the GC and promotes its use where appropriate, you have full control over memory just like you would in C++. And the few features that are hampered by avoiding the GC don't even exist in C++ in the first place.
I'd just like to say there are sane solutions out there already to things like this. With the proper abstractions you get things like custodians[0] in Racket and several alternatives in terms of "call-with-..."[1] functions that do handling for you.
These might not be the languages that are being discussed here, but they offer things like these precisely because they are not the languages discussed here right now.
[0] http://docs.racket-lang.org/reference/eval-model.html?q=cust...
[1] http://docs.racket-lang.org/reference/file-ports.html?q=call...
Took awhile to get used to, but it is a damned fine way to avoid memory leaks of any kind!
But even that aside, if you are writing something like a render loop with hard timing guarantees, (or anything else with timing needs!) having non-deterministic allocation costs can easily blow your cycle budget.
The DCD utiltiy can drive the code completion for a bunch of editors/IDEs.
https://github.com/Hackerpilot/DCD
It works well.
Note that I live in a startup environment all the time and the time and cost to develop in C++ is just too damn high for me. Also, the verbosity and its philosophy kills me.
What was it?
std::map<int, std::vector<int>> whatever = new std::map<int, std::vector<int>>();
Why not d = {} auto whatever = new std::map<int, std::vector<int>>();
or std::map<int, std::vector<int>> whatever;
depending on if you want heap or stack allocated variable, stack allocation usually being preferred as the default solution (and thus being the tersest form).But lets look a bit deeper why C++ is more verbose in this case. One central reason is the idea that standard library should not be special/privileged in the language syntax. The upside from that is that almost all syntax sugar can be applied to user defined types. A relevant example would be uniform initializer lists in C++11, which allow you to write eg.
std::vector<int> foo {1,2,3};
but also MyFunkyDatastructure bar {1,2,3};
as long as suitable constructors are defined. In comparison afaik in Python you can not define a class that can be initialized with sugared syntax.The theme of non-privileged standard library also extends to global namespace pollution. In C++ stdlib does not get to reserve names at global namespace, which leads slightly increased verbosity (std:: -prefixes or using-statements).
So when you ask why you cant make a map/dict in C++ with just 'd = {}', know that there are actually good reasons for (some/most) of the verbosity. The tradeoffs might make it less suitable in your usecases, but there is no absolute/general superiority in either way.
This is why I talked about the philosophy of the language. I wasn't arguing about whether it was good or bad.
That being said, for my own use cases, verbosity is a big deal.
>> In C++ stdlib does not get to reserve names at global namespace, which leads slightly increased verbosity (std:: -prefixes or using-statements).
I understand and agree, but you'd have to agree with me that if you start naming your classes Map and Vector, you're looking for problems ;-)
d = {}
is absolutely not equivalent to a map of int to a vector of ints. Sure in javascript, you can indeed use an object as a map, but you are lacking the type safety that the C++ version provide and all the nice API. Also, in C++11, you can shorten it with auto : auto whatever = new std::map<int, std::vector<int>>();
and to be fair with the js, if you want it as short as possible, you could use a using namespace statement for std (although not really recommended) : auto whatever = new map<int, vector<int>>();
or maybe not use new : map<int, vector<int>> whatever;
I don't think it's that bad. But sure, any dynamic language will be less verbose that a static language because, well, you are removing information...1. You picked probably the most verbose way to do it.
2. It's not valid C++ because you're assigning a pointer to a value.
3. Idiomatic C++ doesn't use `new` explicitly anyway
4. The `d = {}` of Python is not really equivalent.
My feeling is that python gains brevity in exchange for putting a heavier mental load on the programmer, which is manageable for small programs but becomes unwieldy for larger ones.
It's a lot shorter, actually correct, and it's totally cool to import whole namespaces in a .cpp implementation file where you're likely to actually declare something like that.
If you're going to critique the language you should try to learn it first.
map<int, vector<int>> d = {{0, {1,2,3,4,5}},
{1, {6,7,8,9,10}}}; int[int] whatever; int[][int] whatever;
? Because I think we should be getting an array out whenever we do whatever[1]
and not just an int.Now, I'm less clear on how D2 compares to C++11. Certainly some of the smaller improvements matter less, as C++11 has them.
The drawbacks today are in my eyes mostly the relatively minimal support for non-PC platforms and that a number of language features are not yet completely finished. But if the main target are x86 based systems and the use of cutting edge features is not the primary concern, D2 is a great development tool today.
* I can only really talk about my experiences going from C++ -> D, but it was a long process where my way of designing systems and solving problems was gradually altered in many areas - much to the better. And the immediate reward of course is the extreme gain in productivity due to concise syntax, fast compilation times and, last but not least, the lack of a need for header files.
The D community has greatly pushed D away from this initial improvement. In C++ there is a separation of the developer tools and the library writer tools. I think that separation still exists in D, but it is in an area even library writers don't/can't reach for in C++.
Ultimately D doesn't force a fundamental change, but as one learns to use the language, the result is a fundamental change.
Right. One can do a line by line translation of C++ to D, but idiomatic D can be very unlike C++.
"Memory is usually managed with garbage collection, but specific objects can be finalized immediately when they go out of scope. Explicit memory management is possible using the overloaded operators new and delete, and by simply calling C's malloc and free directly. Garbage collection can be controlled: programmers can add and exclude memory ranges from being observed by the collector, can disable and enable the collector and force a generational or a full collection cycle. The manual gives many examples of how to implement different highly optimized memory management schemes for when garbage collection is inadequate in a program."
I wonder if the GC is stop-the-world.
So I'd imagine it has something to do with said expertise.
Go is targeted for developers that can move out of C in their use cases.
D is targeted for developers that can move out of C++ in their use cases.
I've always much preferred C style to C++/D/Rust based mainly on readability and how small the language felt. I completely agree though that Go has given me this similar feeling - to me it really is a modern C. That said, I'm not sure how many C devs are going to like the bounds put in place by Go, or the mandatory GC.
I am, admittedly, a big fan of go also. For me, it has taken from both C and Python use cases, which I think says a lot about its versatility.
The D statement may be accurate, I've never done anything with D and only minimal brush ins with C++ - but to my untrained eyes, they seem pretty similar.
However, I quickly became disappointed with Go's spartan design, given my broad experience across languages and paradigms.
That is why somehow I feel it is more indicated for C developers, that could live with a GC enabled language.
As they would mostly getting type safety and a few more features, whereas developers from other languages are mostly giving away features.
D also owes more of its ancestry to C++, while Rust takes a lot of its inspiration from the ML family of languages.
Both languages are gunning to appeal to C++ programmers, and they're both worthy in this regard depending on your use case. The C++ pie is more than big enough to let both languages thrive independently (and their underlying philosophies are different enough that I expect very little overlap between their communities).
That doesn't mean that it's stable, it's just that we do know what it looks like.
(Disclaimer: I work on Rust, among other things.)
> The project is in heavy daily use at Facebook
So, they had code under heavy use which was not under source-control?
Sometimes I wonder how computing would look like if the default implementations of Java and C#[1] were available from the start as native compilers, instead of VM environments.
[1] Funny enough, the precursor of .NET was native and COM based, similar to what is now WinRT, more info here,
http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-co...
I think that's why the GP has the JIT in parentheses (to account for Julia's implementation, which does use a JIT-compiler, as opposed to D and Nimrod)
At least with Java that would defeat one of the main intents of its development. What would you think would be gained by having non-VM based implementations of these by default?
For the JVM, considerably lower startup/JIT warm-up times. You can really observe this nicely if you're using Zinc (the incremental Scala compiler), where you not only cut the startup overhead down to pretty much zero, but compilation really speeds up once the JIT has warmed up a bit. (Hence why Nailgun exists.)
If you mean bytecode, well there isn't nothing speaking against it. After all it is just an implementation issue.
And bytecodes are not Java specific. Pascal, Ada, Modula-2 are languages with native compilers that also had originally bytecode compilers as well.
But most importantly, it would not confuse a whole generation of developers to mix strong typing with VM as form of implementation.
That's what I was attempting to convey, not any similarity between the languages themselves (the erroneous and unfortunate mention of C++, notwithstanding).