One 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…
Well, not everyone likes automatic type deduction -- some people just like to torment him/herself by repeating information that is unneeded. Why?
Better C – A subset of D Programming Language
171–180 of 360 posts
Re: Better C – A subset of D Programming Language
#172Earlier quoted context omitted.
Is Range a kind of interface? If yes, then wouldn't that be the appropriate return type? edit: Looking at other answers, I think Range is probably not an interface like they exist in Java, but rather a pattern of behavior per templates in C++. Concepts are supposed to solve this problem in C++, but I don't know how well they actually do.
A Range is something that implements one or more interfaces depending on its properties and guarantees. So in order to name a Range that way you'd first have to create interfaces for all possible guarantees. That doesn't sound practical. It's analogous to C++ containers implementing common concepts without deriving from corresponding interfaces. See also https://tour.dlang.org/tour/en/basics/ranges
Re: Better C – A subset of D Programming Language
#173Earlier quoted context omitted.
I'm not super familiar with r-value references, but doesn't passing-by-value in Rust do essentially the same thing as that optimization does in C++?
Yes. But this is all a bit uglier at the call site, since either the library provides value-semantically-similar things with different names that either eat their arguments or copy-from-reference them, provides only the argument-eating version and relies on the caller to `clone` at their discretion, or provides only the referencing version and fails to elide copies. In C++ you can provide a referencing version, and a…
fn eats_a_string(s: impl Into) {
dbg!(s.into());
}
fn main() {
eats_a_string("foo");
eats_a_string("foo".to_string());
eats_a_string(&"foo".to_string());
}
In that case, eats_a_string() will allocate internally in the first and third cases, but it won't allocate in the second case, because the caller gives up ownership of its own allocated String. I wouldn't say this is a super common idiom, and "provide only the argument-eating version and rely on the caller to `clone` at their discretion" is often preferred to be simpler and more explicit. But you see it occasionally in the standard library, for example here: https://doc.rust-lang.org/std/ffi/struct.CString.html#method...Re: Better C – A subset of D Programming Language
#174One 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…
+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.
Re: Better C – A subset of D Programming Language
#175Earlier quoted context omitted.
Yeah I think "better C" is a space which has a really good reason to exist and I'm always interested to see new entrants. IMO describing Rust as a "C replacement" is slightly off the mark because Rust's value proposition is very different from C. Rust is about giving you the best possible performance in a safe-by-default language. C is about giving you maximal control over memory, with a very thin layer of abstractio…
Many programmers think of the programming world as: "assembly When I see someone saying that they prefer D/Nim/Zig value proposition as a "better C" than Rust, what I see is that people are just starting to realize that there are many more options than C for doing programming tasks that require a more precise interaction with the hardware. It's just not "assembly", but there are multiple different assemblers with dif…
So only the old generation remembers how things used to be, and those that are curious about the computing history and evolution of programming languages.
Re: Better C – A subset of D Programming Language
#176Earlier quoted context omitted.
Hard disagree. If you are assigning a value that's the result of an expression you might have somewhat complicated logic. Being able to say what you expect returned is very useful. MyClass myVar = something ? SomeFunction() || somethingThatMightBeASubClassOfMyClass
Anything wrong with var myClass = ... (or some other descriptive name of the variable)?
Like, in C#
List accountsToDelete = accountService.GetAccountsToDelete();
repository.Delete(accountsToDelete);
becomes var accountsToDelete = accountService.GetAccountsToDelete();
deleterService.Delete(accountsToDelete);
So as much type information is already encoded into names so that all references to this object are clear in what we're handling, and so the type declarations at the point where the variable is declared is just redundant noise.If your variables aren't informative when I'm reading the code, I'll be confused 5 lines later anyways. So make them informative at the start. And given that, doesn't that mean the List is a bit redundant?
Re: Better C – A subset of D Programming Language
#177Earlier quoted context omitted.
In 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/
Herb 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.
Re: Better C – A subset of D Programming Language
#178Not included as part of the subset linked above, but D's Contract Programming piqued my interest: https://dlang.org/spec/contracts.html
Ada ( https://learn.adacore.com/courses/intro-to-ada/chapters/cont... ) and Eiffel ( 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.
There are some Java annotation processors that rewrite the bytecode for contracts.
As extra info.
Re: Better C – A subset of D Programming Language
#179This 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.
I use Pascal as better C
Re: Better C – A subset of D Programming Language
#180Earlier quoted context omitted.
https://dlang.org/library/std/algorithm/iteration/map.map.ht... auto auto map(Range) ( Range r )
Returns A range with each fun applied to all the elements. If there is more than one fun, the element type will be Tuple containing one element for each fun.
Maybe read and try to understand the complaint instead of pointing out something unrelated?