11 ms·
D as a Better C
- systems 9y agoD is betting hard on memory safety, and apparently system programming honestly i think, had they gone in the direction of D as a better Python, and application development, they would have made bigger wins (in terms of popularity) ... better tooling, better ide, refactoring, better GC, better libraries ... better faster programs
- nindalf 9y agoThe better Python market isn't an easy one to crack because its a bit crowded. Go (despite its perceived and real faults) has succeeded in this space by delivering better GC, good libraries, static typing and faster programs. Python itself is improving rapidly, for example with the addition of Type Hints. Its pretty difficult to be a better Python in 2017. The better C market, on the other hand, hasn't seen any real contender other than C++ gain traction for decades. Rust is trying now and it could get there, but its still a massive opportunity.
- pjmlp 9y agoAnd on embedded even C++ hardly managed to overtake C. https://youtu.be/D7Sd8A6_fYU https://youtu.be/D7Sd8A6_fYU
- deleted 9y ago[deleted]
- new299 9y agoI really really don't been to pile on Python... but every time I've had to interact with it I've been shocked at how slow it is compared with C or C++. I tend to write scientific code to process datasets in the range on 10Gb, for simple operations Python code can take hours as opposed to just taking minutes or seconds in C. I'm sure it's possible to write more highly optimized code in Python, but it never seems to be the case with the code bases I've worked with. With my own code (a few years ago now), I spent significant time optimizing and the final result was something that was still significantly slower than C/C++. Overall, for my work, I couldn't see an advantage. Am I just doing it wrong? Currently Go seems far more appealing to me and I've enjoyed using it (maybe I should also try Rust).
- fspeech 9y agoHave you tried Cython? That seems like a much smaller leap than a new language.
- saghm 9y agoPython is a high-level interpreted language, and C/C++ are low-level (even compared to other) compiled languages. While you might be able to optimize your Python code to run faster than it does now, it's never going to match the performance of C/C++, nor is it intended to. Go will be a significant speedup over Python, but likely won't quite match the speed of C/C++ for most tasks. Then again, the ease of development in Go will likely be noticeably better than in C or C++. Rust could potentially match the speed of C++, but it's a much more complex language than Go, so it will take some time to master. (Personally, having spent a large amount of time programming in Rust, I find myself more productive than in Go due to the powerful abstractions present in the former and lacking in the latter, but conventional wisdom is that this won't be the case for most people, and it certainly won't be when you're first learning Rust). EDIT: Anecdotally I've heard that D is a nice language, but I have no experience with it, so I can't comment on how productive it is or how fast D code will run.
- pjmlp 9y agoYou can easily get best of both worlds with Lisp derived languages.
- sythe2o0 9y agoIt's been my understanding that Lisp and its relatives aren't designed to compete against C for speed either. Is this wrong?
- pjmlp 9y agoC was designed on a PDP-11, a computer much more powerful than the mainframes where Lisp was already running since 10 years, so Lisp implementations were already quite good for most tasks by then. While C designers were trying to create UNIX at AT&T, Xerox PARC was busy creating Smalltalk, Interlisp-D and Mesa/Cedar. Other companies were creating Genera and the Connection Machine, In the end Worse is Better won, because the machines were too expensive for most pockets, normal developers could not grasp Lisp, mismanagement from those companies and UNIX was kind of cheap when comparing prices, with source code available almost for free (AT&T was prevented from selling it early on).
- saghm 9y agoAccording to their respective Wikipedia articles, D is 8 years older than Go. Given that you're saying that Go had a lot of success breaking into the Python market, why couldn't D have instead if they had put their efforts there from the beginning?
- mattnewton 9y agoI suspect a large part of go's initial success are the names attached to it, both Google and the team have great reputations. Go's continued success is a credit to the language, but maybe D has had some discoverability issues?
- vram22 9y ago>According to their respective Wikipedia articles, D is 8 years older than Go. And Go itself is some years old now (created in either 2007 or 2009 - according to its Wikipedia article - maybe they mean initial creation and first release for public use, by those two year values). So Go is about either 8 or 10 years old. And that makes D either 16 or 18 years old. >Go had a lot of success breaking into the Python market, why couldn't D have instead if they had put their efforts there from the beginning? So when D was new or just a few years old (13 to 16 years ago, say), the Python market was a lot smaller that it is today or has been for the last few years. It might not have even been a target for them, for that or any other reason - another reason could be that Walter is from a systems and compiler background, so might not have been too interested in the domain of interpreted languages (just guessing here, maybe he will comment on this). But BTW, D can be used almost like a scripting language due to its speed of compilation. See rdmd command and the "Why D?" and "D as a scripting language" articles on the Infognition blog (a google away).
- WalterBright 9y agoI've always been attracted to systems programming, and it's what I know best. Hence D is angled that way.
- vram22 9y ago
- vram22 9y ago>Go (despite its perceived and real faults) has succeeded in this space by delivering better GC, good libraries, static typing and faster programs. Also fast compilation, which D also has.
- norswap 9y agoD's objective is/was not to be popular but rather to be exactly what it is: a better low-level language. From what I can gather, it succeeded pretty well at that, lacking maybe some hype. The recent open-sourcing of the toolchain might help though.
- camus2 9y ago> D's objective is/was not to be popular but rather to be exactly what it is: a better low-level language. I don't believe that one second, every language strives to be popular and reach large adoption, since more developers == more maintainers == bigger ecosystem == more reach into enterprise.
- jacquesm 9y agoI would hold up Haskell as another counter example to your assertion.
- StevePerkins 9y agoWould you really, though? I can definitely picture some proponents taking enjoyment from their programming language being perceived as inaccessible to the masses. Insofar as it makes them feel more elite for their knowledge of it. But even then, the ego gratification depends on there being a wide audience of people who know "of" the language and its inaccessibility. If people don't know that you're elite, then well... are you? Proponents of programming languages notwithstanding though, I don't believe for a moment that the creators of any programming language do not wish for it to obtain wide adoption.
- WalterBright 9y agoYou're right. The aim for D is total world domination.
- dbaupp 9y agoWow! I think you're being extremely uncharitable to SPJ, who I believe expressed the sentiment about Haskell originally. There's ton of reasons to not wish for adoption. For instance, supporting commercial use of a programming language is a lot of effort and takes a very different shape to pure language/compiler experimentation and research: more software engineering and less computer science. It is true that the creators probably wish for the product of the research (as in, the successful ideas) to be adopted widely, but that's not the same as wishing for popularity of the framework that proved the ideas. The researchers can focus on their strengths as can commercial compiler/language developers.
- mhh__ 9y agoThe two are clearly not mutually exclusive. The standard library, IMO of course, is already structured in such a way that it can be used in a very high level way.
- Shorel 9y agoThe only difference I see is in marketing. D could be marketed as a better Python and it has enough features to qualify.
- WalterBright 9y agoThere are many D programmers who use D as a fast Python.
- anentropic 9y agowhat do people mean by 'a fast Python' in this context, when the language syntax and features look nothing like Python?
- vram22 9y agoWalter and others who know D much better can answer better, but I'll add my 2c, based on what I've read and some use I've done of D: - The Wikipedia article about D says that Python was one of the languages that influenced it: https://en.wikipedia.org/wiki/D_(programming_language) https://en.wikipedia.org/wiki/D_(programming_language) - After programming in D for a while, I noticed that a) it felt comfortable to program in it, and b) that it did feel a bit like Python, in the sense that, once you've learned some of the basic features [1] and are writing small but non-trivial programs, the language does not seem to get much in your way, as they say. Also there are a few things where its library functions are a bit like Python, like using File(filename) to open a file and get a File object to operate on. Not exactly similar syntax (though there may be some of that too, if you overlook the superficial things like braces instead of indentation to delimit blocks of code), but more of a "feel" - maybe it is the way some of the functions are designed, at a somewhat higher level of abstraction than C. Also, both Python and D were influenced by C. Incidentally, Python seems to have both influenced and been influenced by many languages (14 and 11 respectively): https://en.wikipedia.org/wiki/Python_(programming_language) https://en.wikipedia.org/wiki/Python_(programming_language) [1] I've not tried many of the advanced language features yet (and D has many language features, including some relatively advanced ones), but I found it somewhat easy to grasp even basic use of function templates. But you can do a lot even with the basic language features and standard library.
- deleted 9y ago[deleted]
- WalterBright 9y agoIronically, there are very few choices for programmers who want to write memory safe, high performance systems code. There's plenty of choice at the Python level. BetterC is a way for C programmers to gradually move to memory safety without disrupting their valuable, tested investment in working code.
- YSFEJ4SWJUVU6 9y agoint main(char** argv, int argc) { Really? :-)
- wyldfire 9y agoshrug if an argv falls in the lexer and there's no backend to hear it, did it really matter to the AST? ;)
- e12e 9y agoMakes me wonder if the D programs work, as they also have the order reversed, but might possibly a) have different order defined, or b) do something clever based on the types (but then, what about **env ?)...
- WalterBright 9y agoHow embarrassing :-) But it doesn't affetc the opertaion of the prorgam (I did test it). Edit: fixed it
- deleted 9y ago[deleted]
- jfaucett 9y agoDoes anyone know what the package management story is like for D? And also what is the D ecosystem like for embedded systems?
- pjmlp 9y agoIt is called dub. https://code.dlang.org https://code.dlang.org Regarding embedded, there were some progress lately, but still needs some improvements.
- christophilus 9y agoI tinkered with D a bit (along with Nim, Dart, and C as a comparison) while writing a Clojure interpreter. D seems to be a nice language, but I found the editor integration wasn't the best. I also found it annoying that the docs used `auto` all the time, so you could never figure out the right type annotations for their APIs (e.g. I want to call the foo API and return its value from my method, but the docs all use `auto` to refer to its return value, so I don't know how to annotate my method.) I liked Nim better in almost every way but one: the compiler was fickle and would just fail silently sometimes.
- logicallee 9y ago>Nim, Dart, and C as a comparison) Could I ask about your thoughts regarding Go (which has much less syntax and fewer features than all of the above). Have you looked into it?
- christophilus 9y agoYeah. It should have been in that list, actually. I wanted to like Go. It seems simple (which is what I like so much about Clojure), but honestly, I found it to be frustrating for all the standard reasons the Go team is tired of hearing (e.g. no generics, error handling littering my code and obscuring intent, etc). In fact, I think Go doesn't quite deserve the reputation it has as being a simple language. It's a familiar language, and it's a bare-bones language, but that's not the same thing as being simple. One last thing that was interesting: I got more null pointer runtime exceptions in Go than I expected (vs none in Nim, for example). Granted, I'm a Go n00b, but I'm also a Nim and Dart n00b, and didn't have nearly as much trouble with those two languages (aside from the aforementioned compiler bugs). I really wish modern statically typed languages would rid us of null pointer errors once and for all. This is totally possible with Option types, but seems to rarely be done. I wonder why?
- lambda 9y agoHave you looked at Rust? It uses Option types, has generics, also uses return values for error handling but has a lot more syntactic sugar to make it cleaner than in Go.
- Rhinobird 9y agoD is one better than C, but K goes all the way to 11.
- gjm11 9y ago(This is a slightly funnier joke than it may appear at first glance, because as well as being the name of another programming language K is in fact the 11th letter of the alphabet.)
- deleted 9y ago[deleted]
- wentoodeep 9y agoM is 2 steps ahead of K
- Ace17 9y agoWhy remove RAII? It's not fundamentally incompatible with "Better C" semantics, especially if there are no exceptions.
- zombinedev 9y agoRAII in not removed by design. It is just work in progress. It will be added to -betterC when its implementation is more mature for this mode.
- WalterBright 9y agoRAII requires exceptions to be correct. I hesitate to say it it has RAII otherwise. Exceptions have two issues: 1. D exceptions currently require the GC. There is a Pull Request to fix that, but it isn't incorporated yet. 2. More problematic is the Dwarf exception handling mechanism requires a language specific "personality" handler. This is supplied by the D runtime library. Trying to trick the C runtime library one into working with D isn't a solved problem at the moment.
- andrewflnr 9y ago> RAII requires exceptions to be correct. I'm not exactly sure what you mean here, but all I really want is guaranteed destructors. Can we just have those?
- WalterBright 9y ago> Can we just have those? It's a good thought. D as Better C is new for us, and we'll be flexible in making it work better.
- millstone 9y agoWhy does RAII require exceptions? RAII is routinely used in C++ with -fno-exceptions.
- WalterBright 9y ago
- MichaelBurge 9y agoIf I'm writing C, it's usually a small module or algorithm that I link into another language. Since D is supposed to be in gcc now, I wonder if it's reasonable to start including D code in e.g. Perl or Ruby or Haskell libraries. The great thing about C is once you write it, you never really have to worry about the language changing 15 years down-the-line and breaking your code. The GNU version might have a similar property, since GNU tools stay around for a long time.
- zxy_xyz 9y agoFunnily, the D code looks more verbose than the C code.
- zombinedev 9y agoYes, in this example, but once you start looking at more interesting pieces of code it becomes close to impossible for C beat D without heavy use of macros on the code readability front. Check the runnable examples on the front page - http://dlang.org/ http://dlang.org/.
- benlorenzetti 9y agoI like Walter's writing. He is very articulate; terse but in a polished way. Relies on you knowing a thing or two first though.
- altotrees 9y agoI have really been enjoying working with Rust lately. I also enjoyed working with Go prior to that. Maybe I will give D a try too, see if I have similar luck. I can find things I like and dislike about each of the new languages I try, but it kind of feels like there are a glut of options for me right now, and each one has held mostly positive surprises. Good problem to have: too many new languages that don't give me a headache, hard to choose.
- lobster_johnson 9y agoIs "BetterC" only for DMD? I see that LCD (the LLVM front end) also appears to have "--betterC" flag.
- srcmap 9y agoI love to see someone prove D as a Better C by porting the "small" sqlite 124K line of C code to D and run some benchmark/test code against it. I used to work on OO database engine that handles billions of records. I end up rewriting/overloading my own new/delete and redesign everything how data is load/store around it. Shorten the open/close document time from hours to seconds for large documents. Basically, one can easily mmap billions of records directly into data structures accessible by C API easily in a few ms. One can dispose billions of records also in a few ms. I saw similar design patterns from the sqlite code base. Language with memory safety (GC) design in mind won't allow anything like that as far as I know. I love to see some D experts prove me wrong.
- zombinedev 9y agoD provides the same low-level access as C. Heck, in D you can even use inline assembly, so there are really no barriers to what you can achieve. MMaping files and casting their contents to structures is often used technique. The GC only one of the many ways of getting memory in D. You'll just have to manage the other ways yourself like in C or C++ ;)
- jmh530 9y agoCould you recommend some resources on these techniques?
- anonfunction 9y agohttps://stackoverflow.com/questions/45972/mmap-vs-reading-blocks https://stackoverflow.com/questions/45972/mmap-vs-reading-bl...
- steveklabnik 9y ago> What may be initially most important to C programmers is memory safety in the form of array overflow checking, no more stray pointers into expired stack frames, and guaranteed initialization of locals. Are there any docs about this anywhere? http://dlang.org/spec/betterc.html http://dlang.org/spec/betterc.html doesn't really describe this stuff.
- zombinedev 9y agoIt is not described in the betterC page as these features are not new for D. The betterC page only describes the differences versus the full D feature set. Documentation for the individual features mentioned: http://dlang.org/spec/function.html#safe-functions http://dlang.org/spec/function.html#safe-functions > array overflow checking http://dlang.org/spec/arrays.html#bounds http://dlang.org/spec/arrays.html#bounds > guaranteed initialization of locals http://dlang.org/spec/type.html http://dlang.org/spec/type.html http://dlang.org/spec/declaration.html#void_init http://dlang.org/spec/declaration.html#void_init > no more stray pointers into expired stack frames DIP1000 describes D's scoped pointers approach to memory safety - https://github.com/dlang/DIPs/blob/master/DIPs/DIP1000.md https://github.com/dlang/DIPs/blob/master/DIPs/DIP1000.md. This is work in progress and the document doesn't reflect latest state of things. Conceptually, scoped slices/pointers/references are similar to concept of borrowing that you guys have in Rust.
- steveklabnik 9y agoGreat, thanks! That makes sense, but it wasn't clear to me in the post.
- fithisux 9y ago"Exceptions, typeid, static construction/destruction, RAII, and unittests are removed" Thank you guys "But it is possible we can find ways to add them back in." Over my dead body
- fithisux 9y agoNow we need another flag to enable a better Java mode. By default D is in better C++ mode.
- jmh530 9y agoHow about betterC# instead? Given that C++/CLR is a thing, I imagine that it would be possible to get D working on it. JVM is a bit more limited in what it allows vs. CLR. For instance, C# has the unsafe keyword that allows pointer arithmetic, which would correspond to @system in D. @safe D would correspond to the normal C# behavior on that front. Probably a lot of work though and I'm not sure why anybody would bother.
- pjmlp 9y agoMicrosoft is. That is why .NET Native and CoreRT exist. .NET 4.6 got a few news ways to control when the GC is allowed to run. Also C# got its reference types improved on version 7, and the roadmap up to 8.0 includes a few more goodies, like spans.
- srean 9y agoD already is and has been (better C#) when taken as a language. No need for a command line flag.
- codyguy 9y agoI have tried D, loved the language but I feel the ecosystem and environment issues need to be addressed asap. Here are a few inputs (1) setting up env different operating systems eg GNU/linux variants. Compilers ldc, etc are not really easy to setup on all systems. (2) Memory usage during compile can get out of control resulting in mid-build crashes if sufficient memory is not available. (3) Setting up of a simple http server should be made simple. (ideally the way Go allows to convert any regular Go program to a http server)
- pirocks 9y agoHigh memory usage could be cursed by Ctfe code. There is an existing project to improve the Ctfe interpreter, called newctfe.
- deleted 9y ago[deleted]