17 ms·
Better C – A subset of D Programming Language
- dgellow 7y agoFor more context and details, Walter Bright wrote a series of blog article between 2017 and 2018 on the subject (though their content is a bit outdated as more D features are now supported in BetterC mode): - "D as a Better C" (2017): https://dlang.org/blog/2017/08/23/d-as-a-better-c/ https://dlang.org/blog/2017/08/23/d-as-a-better-c/ - "Vanquish Forever These Bugs That Blasted Your Kingdom" (2018): https://dlang.org/blog/2018/02/07/vanquish-forever-these-bugs-that-blasted-your-kingdom/ https://dlang.org/blog/2018/02/07/vanquish-forever-these-bug... - "DasBetterC: Converting make.c to D" (2018): https://dlang.org/blog/2018/06/11/dasbetterc-converting-make-c-to-d/ https://dlang.org/blog/2018/06/11/dasbetterc-converting-make...
- F-0X 7y agoOne thing that really annoyed me about D is that its documentation lists basically every function with an 'auto' return type. Auto should be completely banned from documentation, it's a complete hindrance. It's the single biggest contributor to why I stopped using D for personal projects - I was so tired of having to hunt down what functions are going to return, sometimes having to resort to just using it and looking at what the compiler complains about. And that's a huge shame. Because in general I really liked using D.
- WalterBright 7y agoYou don't have to wait for the compiler to complain. Using: pragma(msg, T); where T is any type will print the type to the screen during compilation. pragma(msg) will print all kinds of things, making it a very handy tool to visualize what is happening while compiling. I use it all the time.
- slezyr 7y agoPrint-debug you program before it's even compiled and even have a bug is a bag idea.
- arunc 7y agoWhy so?
- entropicdrifter 7y agoYou shouldn't need to reverse-engineer your own program just to understand the code you wrote yourself.
- pjmlp 7y agoApparently it is a common Go pattern to discover which interfaces a type implements.
- WalterBright 7y agoI salute those who never have to debug their own code :-)
- ahartmetz 7y agoUgh, that is even more ill-advised than using auto without good reason in C++.
- MaxBarraclough 7y agoIn the interests of perpetuating this endless flamewar, here's Herb Sutter saying C++ programmers should use auto 'by default'. (I see my snarky comment there got no reply.) https://softwareengineering.stackexchange.com/a/180616/ https://softwareengineering.stackexchange.com/a/180616/
- jfkebwjsbx 7y agoHerb Sutter is biased. He works on C++ language lawyering, he works on new features, he works in the STL, etc. People like him tend to be biased about using auto because they write mostly libraries and generic ones at that (data structures, for instance). In most code out there you actively avoid templates if possible, so that code is concrete, compiles faster and is easier to debug.
- dirtydroog 7y agoBingo! Writing a template library is totally different to writing an application.
- Koshkin 7y agoWell, there's two ways to write an application, analogous to two styles in mathematics as described by A. Grothendieck. http://www.landsburg.com/grothendieck/mclarty1.pdf http://www.landsburg.com/grothendieck/mclarty1.pdf
- Koshkin 7y agoIn the context of C++, the use of auto allows to avoid unintended type conversions during initialization.
- GoblinSlayer 7y agoAnother reason for C/C++ is that they are very permissive with implicit lossy conversions. If you specified explicit type, chances are the compiler helpfully made a lossy conversion for you.
- JoeAltmaier 7y agoMore a failure of documentation/tools? We've been content for a decade to just name the arguments and return without any context. Like the old joke "Where am I?" answered by "In a hot air balloon!". Correct but useless. I wonder if the document could describe (in some regular way) how those auto types are constructed...from what input, with what operations?
- WalterBright 7y agoThey already do.
- acehreli 7y agoI've been using D since 2009 both personally and professionally. 'auto' return did bother me in a few places but it never came close to being a deal breaker.
- WalterBright 7y agoIt's helpful to bring up issues you are encountering in the D forums. This is the first I've heard of this particular one.
- anaphor 7y agoI had this issue last year when I started learning D. I eventually got used to it, but it was a stumbling block at first. The #d IRC channel helped me out.
- bachmeier 7y agoIt's been raised many times before. By me and numerous others. The standard library is generic, which isn't the end of the world, but you can't tell from the documentation how you can work with the output. It's common for someone to ask a question and be told "add .array to the output". They'd never know that after reading the documentation.
- WalterBright 7y agoReading the example code in the documentation is very helpful with this.
- aldacron 7y agoAnd the "Returns:" section!
- p0nce 7y agoIt's often because these functions have unnamed types. Chain of lazy computations in D often return unnamed types (so called "Voldemort" types) because finding good names for those inner structs is a challenge, they have a single use (which is to have a particular signature).
- Konohamaru 7y ago> Chain of lazy computations in D often return unnamed types (so called "Voldemort" types) because finding good names for those inner structs is a challenge There is something so absurd about having "unnamed types" as an antipattern!
- p0nce 7y agoNot everything is worth naming, if there isn't an obvious good name for somethink (like say, a Java Anonymous Classes) then why not allow it to have no name?
- Konohamaru 7y agoJava's objects aren't types even though they're mixed up with its type system. Objects are supposed to represent units of computation so anonymous classes aren't absurd. But the reason why it seems that types without names are absurd is that types are only real for the interpreter or compiler. At runtime they aren't used anymore. So it's absurd that a construct made for humans to understand and describe code starts to become something opaque to human understanding because they're impossible to be named.
- atilaneves 7y agoNot really - the concrete type isn't important, but what you can do with it is. One could argue that instead we'd use a concept in place of `auto`, and Bjarne has argued exactly that for C++.
- masklinn 7y ago> Not really - the concrete type isn't important, but what you can do with it is. Then surely that's what should be shown? Rust uses `impl <Trait>` for that, the actual return type is opaque but you know it implements the specified trait.
- pansa2 7y agoI think it’s really interesting that as dynamically-typed languages increasingly encourage explicit type hints, statically-typed languages are recommending “almost always auto”.
- logicchains 7y agoIn dynamically typed languages, adding types can stop things blowing up at runtime. In compiled languages, all the type-inference is still done at compile time, so if it compiles than you're not going to get a crash from accidentally adding a string to an integer at runtime.
- Koshkin 7y agoThe template language is weakly typed and code written in it, too, can “crash” when it runs (which is the compilation time) for the same reasons.
- gmueckl 7y agoThe use of Auto is requires in some places because the standard library returns types that cannot be named in the context of the calling function. This happens for example with algortihms that return a custom Range implementation that is declared within the scope of the function implementing the algorithm. I am not sure what to make of this pattern. At least the documentation should be more explicit about these Voldemort types. Documentation has other issues as well. The standard documentation generator doesn't cope well with version statements (conditional compilation), potentially skipping docs for stuff that wouldn't be compiled into a particular build variant.
- fluffything 7y agoI'm glad that Rust has no `auto`. I find this: fn map<U, T, F, I>(it: I) -> impl Iterator<Item=U> where I: Iterator<Item=T>, U: From<T> { it.map(|t| From::from(t)) } infinitely more readable than fn map<U, T, F, I>(it: I) -> auto where I: Iterator<Item=T>, U: From<T> { it.map(|t| From::from(t)) } The type signature of the first one clearly tells me that the return type is an `Iterator<U>`, even though the actual type cannot be named because of the anonymous closure. The second one leaves me guessing what the return type is. If the actual type cannot be named, it is rarely the case that this is all there is to it. Usually, users are expected to use that type "somehow" (it is a `Range`?), and that means that there are some interfaces that these types implement.
- EvenThisAcronym 7y agoRust does have auto; "let" and function literal parameter type inference, for a start. It just doesn't let you use it in the return type position.
- kibwen 7y agoThat's the salient point of this thread though; Rust doesn't have type inference in any position that shows up in API documentation. (The closest thing Rust has is return types of `impl Trait`, but even that imposes a contract that the caller must adhere to and that the callee cannot see through.)
- logicchains 7y ago>so tired of having to hunt down what functions are going to return, sometimes having to resort to just using it With highly generic functions, it's often not possible to know what they'll return without knowing what you'll call them with. Especially given that D functions like "map" and "reduce" tend to return special iterator types so that the compiler is able to smarty fuse them where possible. If D had concepts like C++20, you could probably describe them with something looking like: template<class R> concept __SimpleView = // exposition only ranges::view<R> && ranges::range<const R> && std::same_as<std::ranges::iterator_t<R>, std::ranges::iterator_t<const R>> && std::same_as<std::ranges::sentinel_t<R>, std::ranges::sentinel_t<const R>>; But at least for me that doesn't seem like it would be much more helpful than just reading the documentation, which states what the function returns, if not necessarily the type.
- rowanG077 7y agoSo you still can see that it depends on some input. That is hugely more useful then auto.
- asdkjh345fd 7y ago>With highly generic functions, it's often not possible to know what they'll return without knowing what you'll call them with. Of course it is. Map's type is "(a -> b) -> [a] -> [b]". D just absolutely and completely failed here, despite this being a solved problem 40 years ago.
- neutronicus 7y agoIt doesn't have to be specialized to []
- asdkjh345fd 7y agoOf course not. But it still has a type. Functor f => (a -> b) -> f a -> f b
- jcelerier 7y ago
- skocznymroczny 7y agoPersonally I dislike var/auto in languages because I like having types explicitly written. But in case of languages like Java or Kotlin you can move the cursor over the variable name and you will see the type, also you can right-click and select "replace with explicit type" and it will work. In D, IDEs struggle with templates and can rarely index templated code (no wonder, because most of the code doesn't exist until build time). Most people will tell you, "oh just use auto, it makes the code more generic". That's sweet, except as soon as I want to pass it to another function, I need to have the concrete type. Like you, I usually just copy-paste the full type from the error message and move on.
- stcredzero 7y agoPersonally I dislike var/auto in languages because I like having types explicitly written. But in case of languages like Java or Kotlin you can move the cursor over the variable name and you will see the type, also you can right-click and select "replace with explicit type" and it will work. In D, IDEs struggle with templates and can rarely index templated code (no wonder, because most of the code doesn't exist until build time). It's 2020. Why couldn't things work like this, where one can open a window for a concrete type using templates, and it shows the code?
- kevin_thibedeau 7y agoA well designed language should be usable from a text editor. Even in 2020.
- qqssccfftt 7y agoA good dev uses an IDE. In 2020.
- snazz 7y agoThis is a really tired argument that we don't need to get into right now. Different things appeal to different people.
- arunc 7y agoVim vs emacs, auto inference vs explicit, I don't think it will ever end. :)
- jbverschoor 7y agoAren't there any type synthesizers which modify your code based on inferenced types?
- thesuperbigfrog 7y agoIsn't that called weak typing? (https://en.wikipedia.org/wiki/Strong_and_weak_typing#Definitions_of_%22strong%22_or_%22weak%22 https://en.wikipedia.org/wiki/Strong_and_weak_typing#Definit...)
- jbverschoor 7y agoNo. I mean altering code to strong typing using type inference. So that auto becomes int, or MyClass*.
- lostmsu 7y agoIt already ended. VSCode and auto inference.
- takeda 7y agoI don't know D, but after reading more comments looks like auto is also compensating for poor type system. For example functions that accept arguments of many types apparently need to be declared that are returning auto. At least that's what I understood.
- jane_red 7y agoScala has a strong type system and when working with it on a daily basis I was not programming, I was thinking about types and fighting with the compiler. And that is the language which has a pretty decent IDE plugin. When I moved to D, it felt like a breathe of fresh air to me. Therefore, the whole talk above about auto and types looks like subjective nitpicking. In practice though, D codes fast and runs fast, as promised on the official site.
- dirtydroog 7y ago+1, I cringed when Herb Sutter released the 'Almost Always Auto' C++ presentation on YouTube. Sure, auto has its place, and I personally use it, but I just knew that less experience devs would go nuts with it, and it'd only make their lives easier for a short time.
- Koshkin 7y agoPlus, seeing the word 'auto' all over the place leaves a weird impression.
- thesuperbigfrog 7y agoIt lets C++ almost return to C-style duck typing. Whether that's really what you want and whether that is the best approach to solve the problem at hand is a matter of preference and the problem space. It is also allows for a "gradual typing" approach that Dart 1 had.
- self_awareness 7y agoI've never programmed in D so I don't know, but from curiosity I wanted to check if what you write is true. However, I can't find any function that is declared as auto. Could you please paste some example of a function that has a return value which is declared as auto?
- F-0X 7y agoThe major examples are parts of the stdlib which offer higher-level pipelines (some answers here indicate the need for such things to be very flexible in their return values to allow this, but this is not a priori obvious - Java manages similar functionality with just the Stream<T> class after all). In this (and the sibling pages in algorithm) nearly every entry is listed as either "template" or "auto" relhttps://dlang.org/phobos/std_algorithm_iteration.html https://dlang.org/phobos/std_algorithm_iteration.html
- aldacron 7y agoD's classes and interfaces are much like Java's, so it's possible and easy to write functions that express return types like that. It's also quite restrictive for generic programming. D's metaprogramming features are much more powerful. That means a template can return different types that do not conform to a single, easily-expressed interface. The std.algorithm package is built on that concept.
- takeda 7y agoMaybe it was fixed? I would imagine that saying in documentation that return type is auto is equivalent to not mentioning return type at all, so feels like something not intentional.
- masklinn 7y ago> Maybe it was fixed? It wasn't. They probably didn't look into the more "generic" functions e.g. hofs and algorithms. The vast majority of functions in https://dlang.org/phobos/std_algorithm_iteration.html https://dlang.org/phobos/std_algorithm_iteration.html returns "auto"
- stevefan1999 7y agoWell, not everyone likes automatic type deduction -- some people just like to torment him/herself by repeating information that is unneeded. Why?
- Koshkin 7y agoSometimes when reading a long passage in a novel you need a reminder who "he" is.
- throwaway894345 7y agoType inference systems generally have crumby error messages, and are harder to reason about all around. The best type inference systems are those that allow inference within a function definition, but the function signature requires explicit annotation. This keeps the inference local, which is easier for humans to read about. Good tooling can make either system easier to work with, but tooling is much less important in the type annotation case because the cost of adding annotations is trivial (contrary to your "torment" vocabulary) compared to reasoning about (non-local) type inference. In general, this reduces to the principle that concrete is easier to reason about than abstract. The type signature of an unannotated function in a type inference system is maximally abstract, while (especially in practice) the signatures for functions that are manually annotated are more concrete if not fully concrete. There are still problems in non-type-inferred systems with programmers who try to be egregiously abstract, but these are fewer and farther between.
- schveiguy 7y agoSometimes I feel like auto is definitely overused. In a recent fix, I changed something that returned a boolean (no templates involved) from returning auto to returning bool. But sometimes auto is the best tool for the job, especially when writing wrapping types. In that case, yes, you have to read the documentation (and I mean what is written in the ddoc comments). But in many cases, you don't have to, because you recognize the pattern, or it's simply a wrap of the underlying type's function.
- lumberjackstian 7y agoI've felt this as well, been using D for a couple years now, and this is the kind of thing that just makes me have to context switch more than I'd like. With the current implementation of the language it's hard to avoid, and function's return type can be quite complex, so writing it down can be hard. Another reason is the (ironically) dynamic nature of a return type. E.g. auto whatDoesItReturn(int i)() { static if (i == 0) { return int.init; } else { return string.init; } } Template code can do that quite easily and then you don't have a choice but to write auto as the return value. What would be fantastic if the documentation could be given access to the the compiler's return type inference, so that it could document the auto returns with a little more info. Another way useful approach would be to implement protocols like in swift, or traits like in scala/rust/others, signatures in ml, etc. Then you would be able to define the interface of what a function returns.
- RandallBrown 7y agoWhat would be the return type of that? Does D have an Either type?
- lumberjackstian 7y agoDepends on the value of the template parameter. If it's 0 the return type is an int, if it's not 0 the return type is a string. There's a wanting implementation of a sumtype in the standard library (https://dlang.org/phobos/std_variant.html#.Algebraic https://dlang.org/phobos/std_variant.html#.Algebraic), and a much better one as a package: https://code.dlang.org/packages/sumtype https://code.dlang.org/packages/sumtype
- RandallBrown 7y agoInteresting, so the return type isn't known until runtime.
- lumberjackstian 7y agoWhen it comes to templates it's not until instantiation time - when the compiler see the code being used. So this is just an issue during compilation. The docs on static if may shed some more light: https://dlang.org/spec/version.html#staticif https://dlang.org/spec/version.html#staticif
- jimbob45 7y agoI vehemently disagree. Auto/var is a tool that may be used judiciously by your userbase. This new philosophy of blocking your users from using dangerous tools because you know better than them just invites workarounds and kludges. Give the user the tools and warn them of the ways it can go wrong. There's a reason Rust is losing the war to C++. Anyways, var/auto is critical in some cases. C#'s LINQ, for example, would be very difficult to develop with if you had to manually figure out the type you were returning with long queries every time you wanted to restructure your query.
- z3t4 7y agoIm annoyed that you have to spell out auto all over the place. It should be implicit. The compiler should automatically add auto if you have not specified something else.
- underthensun 7y agoI really hate the auto keyword but as I like D so much, I kinda get used to it.
- WalterBright 7y agoWalter here - AMA!
- jdmoreira 7y agoI'm sorry that the question is not really related to your compilers but I'm curious about your opinion on Zig?
- WalterBright 7y agoI know nothing about Zig.
- voldacar 7y agoYou should definitely check Zig out. It's a relatively simple (compared to D, Rust, C++) language with C-level semantics but more modern syntax. It is designed to be extremely easy to interface with existing C source code, enabling one to convert a program from C to Zig incrementally and with minimal headaches https://ziglang.org https://ziglang.org
- abainbridge 7y agoYou should probably address that. It's a serious competitor to D (as better C). At the very least, you might see some ideas worth stealing!
- deleted 7y ago[deleted]
- MaxBarraclough 7y agoNitpick: Zig is more a competitor to the Better C subset of D, than to D itself.
- deleted 7y ago[deleted]
- JoeAltmaier 7y agoOhh! Ohh! C and C++ are used. How about ℂ (double-struck C) to mean "Like C but double the fun!"
- michaelmior 7y ago> To link D functions and libraries into C programs, it's necessary to only require the C runtime library to be linked in. Not that I'm suggesting this would be a better approach, but wouldn't it be possible to link both the C and D runtime libraries and wrap the main function to do the initialization?
- dmux 7y agoNot included as part of the subset linked above, but D's Contract Programming piqued my interest: https://dlang.org/spec/contracts.html https://dlang.org/spec/contracts.html
- thesuperbigfrog 7y agoAda (https://learn.adacore.com/courses/intro-to-ada/chapters/contracts.html https://learn.adacore.com/courses/intro-to-ada/chapters/cont...) and Eiffel (https://www.eiffel.com/values/design-by-contract/introduction/ https://www.eiffel.com/values/design-by-contract/introductio...) also support contracts. Contract-based programming is a very nice way to quickly find errors and specify how different parts of the program should interact.
- pjmlp 7y agoC++20 almost got them. There are some Java annotation processors that rewrite the bytecode for contracts. As extra info.
- thesuperbigfrog 7y agoJava annotations have always struck me as interesting since they fill the Lisp macros and C preprocessor niche for Java. It's another layer of complexity, but it extends the language to offer a bit more richness or layers of abstraction. I would not be surprised if a future C++ standard adds contracts officially. Boost seems to already have contracts: https://www.boost.org/doc/libs/1_67_0/libs/contract/doc/html/boost_contract/contract_programming_overview.html https://www.boost.org/doc/libs/1_67_0/libs/contract/doc/html...
- pjmlp 7y agoYes, many aren't aware how much annotation processors and compiler plugins are capable of. On the .NET side you have Roslyn, Attributes, expression trees and on F# quotations. While they are all a bit cumbersome to use versus what Lisp macros allow for, they already allow for quite a lot. Yes, there is some hope that C++23 will bring them. The more languages support DbC the better, only so can we start seeing more widespread adoption across the industry.
- Koshkin 7y agoRegarding the ongoing auto/var readability issues debate, how about the popular dynamic languages that often do not even have the means of specifying a type? They surely must be suffering from huge readability issues?
- flohofwoe 7y agoSuch languages (e.g. python) serve a different purpose, at least in my opinion. Using python as scripting language for small "adhoc automation" things is great. For long-living and bigger code bases, worked on by teams, explicit types and "proper" static type system are the better choice. E.g. it's less about readability, but maintainability.
- richardwhiuk 7y agoI find using Python libraries where the documentation doesn't tell me anything about the return type a hugely frustrating experience.
- kalium-xyz 7y agoSo D-- then?
- sgt 7y agoD is pretty exciting. Seems like a perfect choice for those of us looking for an alternative systems programming language and are not completely convinced we'll be happy in Rust.
- rakoo 7y agoI'm not looking for an alternative to C but I used this quarantine to start nim, and it feels quite right until now
- dom96 7y agoNim actually happens to be a very good better C. The fact that it compiles to C is a key feature of that.
- pron 7y agoMine is Zig.
- dgellow 7y agoZig is still very experimental though, the language isn’t stable yet
- AnIdiotOnTheNet 7y agoDefinitely. However I will say that Zig does so many things right already that I struggle to code in more mature languages without thinking "I wish I was writing Zig right now" all the time.
- pron 7y agoTrue, but I'm not in a hurry. We've waited a long time for a C/C++ alternative, we can wait a bit more. Some find it in D, some find it in Rust, some (like me) are waiting for Zig, and some for something else.
- logicchains 7y agoAre you aware of anyone with large projects in Zig? I'm curious how fast it compiles, given in my view faster compilation is one of the biggest advantages of D over C++ and Rust, due to it having a lightweight compiler, DMD. Zig seems to still use LLVM, like Rust, which is relatively slow.
- kqr 7y agoThis is a great idea. I maintain that Ada is a better "better C" than any of the alternatives I've looked into, but it has an obvious big hurdle: while it has approximately the same use cases as C, it is completely different in terms of looks and handling. One of the strong points of D is that it still seems very much like C. Very good call to emphasise this.
- WalterBright 7y agoI like Ada. D took inspiration from it.
- kqr 7y agoI know. I think you and I have discussed aspects of it at various points in comment threads before. I'm impressed with how well D is doing things that are really very hard.
- augustk 7y agoFor me Oberon is the better C. https://www.miasap.se/obnc/oberon-report.html https://www.miasap.se/obnc/oberon-report.html
- pjmlp 7y agoOn the Oberon linage that place belongs to Active Oberon. http://cas.inf.ethz.ch/news/2 http://cas.inf.ethz.ch/news/2 Only Active Oberon exposes non traced references, RAAI and a couple of other low level features that made it more complex to do systems programming in Oberon and Oberon-2, let alone Oberon-07.
- auxym 7y agoNim was inspired by Oberon, and compiles to C (so easy interop). Neat language.
- elcritch 7y agoI’ve always liked the idea of Ada, but never had a place to use it. Though someone on HN pointed out that NVidia was using Spark for secure code sections. Quite interesting! Personally while D seems a great tool, I really keep running into situations where a language that lives on top of C/C++ is useful. So I’ve been trying out Nim for those use case, using the ARC GC which appears to work well for embedded. It’s deterministic but with move semantics for performance optimization. Interesting approach IMHO. But the biggest advantage is being able to directly interface with any C or C++ natively. D/Rust both seem to have difficulty being 100% onboard with C++ (for good reasons).
- pjmlp 7y agoNow with WebAssembly support thanks to LDC, the Better C experience is definitely much more productive than dealing with emscripten. Then again, I am biased.
- kreco 7y agoIt's interesting how this works: - enumerate everything C is doing bad. - presents fixes with a full bag of unnecessary features that no c programmer wants. I wonder why there is no "Fixed C".
- WalterBright 7y agoThe trouble is, everyone has a different view of what is unnecessary. Fortunately, you can simply not use any feature you find unnecessary. We won't harangue you about it, I promise! (Well, maybe a little bit if it's so cool we just can't resist.)
- pjmlp 7y agoThat is why they are now persona non-grata on Apple, Google and Microsoft platforms. So on Apple platforms they will eventually have to deal with C++ and Swift no matter what. On Microsoft platforms, they complain about C support and get shown the door to C++. And on Google platforms, given the years of ignoring security advices, starting with Android 11, hardware memory tagging is a required feature, with the kernel randomly attaching GWP-ASan to processes, while on ChromeOS Linux gets to run on a hypervisor sandbox.
- mhd 7y agoThere have been many, many "Fixed C"'s. That's the problem. This isn't a technology issue, it's a social one.
- kreco 7y agoI'm actually curious. until now I came across new language that sells themselves as c replacement but with a lot and lot of new features, usually "here is a new language it does a lot more than C but still compatible with it". examples in top of my head: - adding object oriented feature like built-in constructor/destructor while only default values are needed as week as a defer statement. - weird template, while I can sense that we only want a proper hygienic macro system. And "array type", pointer with length, to deal with contiguous memory. The rest is well described in the video, but those 3 points are my major issues.
- runjake 7y agoFor those who have been around a while, this is not the same as DailyWTF’s Better C dialect. https://thedailywtf.com/articles/The_Secret_to_Better_C https://thedailywtf.com/articles/The_Secret_to_Better_C
- deleted 7y ago[deleted]
- arunc 7y agoFor me the single best feature that stands out in D is the uniform member access using dot. - Want to access member in a aggregate (class/struct)? Use . - Want to access member in pointer to an aggregate? Use . - Want to access member in a module? Use . - Want to access reference (not free standing)? Use . This makes switching between different implementations pretty easy. Coupled with UFCS, this is pretty fantastic!
- jane_red 7y agoI can strongly relate to that. You can write a custom "fill" method for your array and just do "arrray.fill", bam! It just works. You want numpy "zeros"? Just do a template void zeros(T)(ref T arr) { arr.each!"a = 0"; } someArr.zeros;
- zem 7y agoevery time I've looked into this I've found the documentation severely lacking in examples of how one would go about incrementally migrating a c project to better c. does someone have a pointer to a blog post or even a git commit that illustrates the first step of migrating a single c file, with all the attendant makefile changes?
- WalterBright 7y agoThe dmd backend itself used -betterC to make the conversion from the original C-with-Classes code. DMC++ itself underwent the conversion to D using -betterC. https://github.com/DigitalMars/Compiler/tree/master/dm/src/dmc https://github.com/DigitalMars/Compiler/tree/master/dm/src/d... It still looks a lot like C.
- WalterBright 7y ago1. rename the file from prog.c to prog.d 2. set up to compile with dmc prog.c -c -betterC 3. replace all the preprocessor stuff 4. compile it, and fix the errors diagnosed by the compiler The hardest part will be how much metaprogramming was done using the C preprocessor. Once that's dealt with, the rest is fairly mechanical.
- 0xDEEPFAC 7y agoReminds me of Ada++
- hirves_lot 7y agoI think D is great for scripting.. and having no python experience but java/c/c++ it feels more familiar. The standard library is useful.
- colonwqbang 7y agoThe chosen example (printf) doesn't make D look very good compared to C. If I modify the example to include a simple type error: printf("Hello %s", 123); Then the D version will still happily compile without warnings and will segfault. Compiling with GCC -Wall -Werror, the type error is easily caught by the compiler.
- arunc 7y agoUse dmd master and you will have printf/scanf format argument validation [0]. [0] https://github.com/dlang/dmd/pull/10852 https://github.com/dlang/dmd/pull/10852
- WalterBright 7y agoYeah, I am glad we fixed that one.
- bedros 7y agoI think they should call it only slightlybBetterC All the features I like in D such as dynamic arrays and associate arrays are gone
- gok 7y agoFeels like a more accurate name would be "Freestanding D" but it's a cool idea.
- WalterBright 7y agoI actually wrote "D as Better C" before realizing "Das Better C" sounded much better. And a shout out to all our German speaking D users!
- optymizer 7y agoMr. Walter Bright, I'm late to the party here, but I hope you will see my comment. I have a lot of respect for you and Andrei, and I think D deserves much more love than it gets. I personally feel like there are too many options when it comes to D. Perhaps it would be good to double down on some combination of those options and make that widely known? As a newcomer to D, I am exposed to GC/non-GC code, dmd/llvm compiler/gcc compiler, several debuggers, some BetterC option, etc. I don't know which toolchain is best, and I don't want to deal with the integration issues between them. All of these options that exist are great, but the brand gets diluted. D seems to be the ideal thing: it's seemingly a better C++, and a better C, with a clean syntax like Java. I trust it's a better C, but how do I know the combination of the D toolchain that I'm choosing is better than sticking with the devil I know already? What I would love to see is an opinionated package spun off from D. One compiler, one debugger, one IDE, one standard library. Make my onboarding experience better and take the thinking out of assembling a D toolchain. Every time I find myself thinking "maybe I should look into using D instead of C for this project", I spend a few hours with D, and then I get frustrated at all the options and I go back to the devil I know. I truly wish I could be one day convinced that I can install D and I get a solid platform without weird moving parts.
- WalterBright 7y agoIf you were to pick one option, stick with BetterC.
- dgellow 7y agoYes, I completely agree, the onboarding experience is daunting. It's quite hard to understand all the moving parts and figure out which one I should care about or not.
- teleforce 7y agoThis is a nice tutorial introduction on using D as a better replacement for C [1]. Some excerpts "At one time, C was my go-to language for most programming. One day I realised that most of my C programs kept reimplementing things from C++: dynamic arrays, better strings, polymorphic classes, etc". [1]https://theartofmachinery.com/2019/04/05/d_as_c_replacement.html https://theartofmachinery.com/2019/04/05/d_as_c_replacement....
- kazinator 7y agoThe problem is that since this Better C is not compatible with any C dialects, and requires a D compiler, there is no reason to restrict D programs to this subset. At least no reason that is related to simply working in something better than C. The real reasons can be articulated better, starting with a different name, like "Reduced D" (D that avoids garbage collection, exceptions and/or has a smaller footprint or whatever). How about "Dm": D Minor: a sad subset of D. A subset of C++ is a better C, that can be written in such a way that C compilers translate it, so that is meaningful. Well, at least a slightly better C, anyway.