digitalmars.D - D code length vs other languages
- Walter Bright (11/11) Dec 05 2019 https://danuker.go.ro/programming-languages.html
- Adam D. Ruppe (5/7) Dec 05 2019 Indeed, I actually frequently do even less. A lot of repetition
- Paolo Invernizzi (7/15) Dec 06 2019 Yesterday happened to me to translate a modest size python script
- Craig Dillabaugh (6/13) Dec 06 2019 clip
- Jonathan Marler (4/20) Dec 06 2019 You could do that, or you could use a UFCS chain as well. More
- Paolo Invernizzi (7/28) Dec 06 2019 Maybe you are both right ... and maybe I've written too much
- Jesse Phillips (5/11) Dec 07 2019 https://dev.to/jessekphillips/map-reduce-in-d-25nm
- Steven Schveighoffer (6/18) Dec 09 2019 "In the first situation filtering came before the operation, here it
- Jesse Phillips (4/18) Dec 09 2019 Yes because anything else is filtered out.
- norm (18/39) Dec 09 2019 ---
- Jesse Phillips (2/18) Dec 09 2019 Done, using addition and adding the missing equality
- Tobias Pankrath (4/10) Dec 07 2019 What I miss though is creating ranges with something like
- Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= (5/7) Dec 07 2019 Implement C++ stackless coroutines, perhaps?
- mipri (30/41) Dec 07 2019 You can use std.range.generate with any random closure:
- Tobias Pankrath (5/36) Dec 07 2019 Didn't know std.concurrency.Generator, thanks!
- Paul Backus (21/47) Dec 07 2019 You can use Nullable (or Optional from dub) and a bit of
- German Diago (13/21) Dec 11 2019 This is something that D excels at. That is why I like it. Many
- Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= (6/9) Dec 05 2019 It is probably better to look at the examples on the Rosetta
- Jab (11/22) Dec 05 2019 They also use different (non-standard) libraries, which really
- Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= (9/13) Dec 06 2019 Yes, I think there are too many tasks in Rosetta as well. Many of
- Gregor =?UTF-8?B?TcO8Y2ts?= (4/8) Dec 06 2019 Also, the need for headers. That alone can add considerably to a
- Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= (7/9) Dec 06 2019 True, you that you have to specify the signature of all class
https://danuker.go.ro/programming-languages.html I'm unsure of the accuracy of the methodology of determining this, but D does fairly well in it. It wasn't designed to be a particularly terse language, and personally I find that excessive terseness makes for a hard-to-understand language as well as making typos more likely to produce buggy programs. (Taken to its logical extreme, for a language with no redundancy, any random sequence of bytes would be a valid program. It would be impossible for a compiler to diagnose any errors.) D being about a third less code than C++ is consistent with my unscientific experience with it. I'm a little surprised that D is significantly more compact than Rust.
Dec 05 2019
On Thursday, 5 December 2019 at 22:21:13 UTC, Walter Bright wrote:D being about a third less code than C++ is consistent with my unscientific experience with it.Indeed, I actually frequently do even less. A lot of repetition in other languages I find myself able to automate pretty well in D. Whole blocks of 1,000 lines of glue code in other languages can be replaced with 30 lines of CT reflection stuff.
Dec 05 2019
On Thursday, 5 December 2019 at 22:28:53 UTC, Adam D. Ruppe wrote:On Thursday, 5 December 2019 at 22:21:13 UTC, Walter Bright wrote:Yesterday happened to me to translate a modest size python script into D, to incorporate it in a product, and it was a pleasant experience. The port was really really easy ... but I'm starting to miss list comprehension ... Anyway, point taken!D being about a third less code than C++ is consistent with my unscientific experience with it.Indeed, I actually frequently do even less. A lot of repetition in other languages I find myself able to automate pretty well in D. Whole blocks of 1,000 lines of glue code in other languages can be replaced with 30 lines of CT reflection stuff.
Dec 06 2019
On Friday, 6 December 2019 at 08:47:59 UTC, Paolo Invernizzi wrote:On Thursday, 5 December 2019 at 22:28:53 UTC, Adam D. RuppeclipYesterday happened to me to translate a modest size python script into D, to incorporate it in a product, and it was a pleasant experience. The port was really really easy ... but I'm starting to miss list comprehension ... Anyway, point taken!Wouldn't it be fairly easy to write some sort simple library that gives you list comprehensions in D. It wouldn't be a nice as the python syntax, but it should be doable no?
Dec 06 2019
On Friday, 6 December 2019 at 18:25:20 UTC, Craig Dillabaugh wrote:On Friday, 6 December 2019 at 08:47:59 UTC, Paolo Invernizzi wrote:You could do that, or you could use a UFCS chain as well. More flexible than list comprehensions.On Thursday, 5 December 2019 at 22:28:53 UTC, Adam D. RuppeclipYesterday happened to me to translate a modest size python script into D, to incorporate it in a product, and it was a pleasant experience. The port was really really easy ... but I'm starting to miss list comprehension ... Anyway, point taken!Wouldn't it be fairly easy to write some sort simple library that gives you list comprehensions in D. It wouldn't be a nice as the python syntax, but it should be doable no?
Dec 06 2019
On Friday, 6 December 2019 at 18:53:22 UTC, Jonathan Marler wrote:On Friday, 6 December 2019 at 18:25:20 UTC, Craig Dillabaugh wrote:Maybe you are both right ... and maybe I've written too much Python code in the past years and indeed, UFCS chains are a killer future of D: every list comprehension was turned into a nice UFCS chain. Let's forget about that: the point is still taken by D, converting python code in D code is a pleasant experience!On Friday, 6 December 2019 at 08:47:59 UTC, Paolo Invernizzi wrote:You could do that, or you could use a UFCS chain as well. More flexible than list comprehensions.On Thursday, 5 December 2019 at 22:28:53 UTC, Adam D. RuppeclipYesterday happened to me to translate a modest size python script into D, to incorporate it in a product, and it was a pleasant experience. The port was really really easy ... but I'm starting to miss list comprehension ... Anyway, point taken!Wouldn't it be fairly easy to write some sort simple library that gives you list comprehensions in D. It wouldn't be a nice as the python syntax, but it should be doable no?
Dec 06 2019
On Friday, 6 December 2019 at 20:09:46 UTC, Paolo Invernizzi wrote:Maybe you are both right ... and maybe I've written too much Python code in the past years and indeed, UFCS chains are a killer future of D: every list comprehension was turned into a nice UFCS chain. Let's forget about that: the point is still taken by D, converting python code in D code is a pleasant experience!https://dev.to/jessekphillips/map-reduce-in-d-25nm This was my very brief comparison of List comprehension vs Ds libraries.
Dec 07 2019
On 12/7/19 4:28 AM, Jesse Phillips wrote:On Friday, 6 December 2019 at 20:09:46 UTC, Paolo Invernizzi wrote:"In the first situation filtering came before the operation, here it will ultimately be useless because it operates on the square of a number which is always even." You sure about that? ;) -SteveMaybe you are both right ... and maybe I've written too much Python code in the past years and indeed, UFCS chains are a killer future of D: every list comprehension was turned into a nice UFCS chain. Let's forget about that: the point is still taken by D, converting python code in D code is a pleasant experience!https://dev.to/jessekphillips/map-reduce-in-d-25nm This was my very brief comparison of List comprehension vs Ds libraries.
Dec 09 2019
On Monday, 9 December 2019 at 16:33:30 UTC, Steven Schveighoffer wrote:On 12/7/19 4:28 AM, Jesse Phillips wrote:Yes because anything else is filtered out. I must have been thinking about addition :)On Friday, 6 December 2019 at 20:09:46 UTC, Paolo Invernizzi wrote:"In the first situation filtering came before the operation, here it will ultimately be useless because it operates on the square of a number which is always even." You sure about that? ;) -Steve[...]https://dev.to/jessekphillips/map-reduce-in-d-25nm This was my very brief comparison of List comprehension vs Ds libraries.
Dec 09 2019
On Tuesday, 10 December 2019 at 02:23:21 UTC, Jesse Phillips wrote:On Monday, 9 December 2019 at 16:33:30 UTC, Steven Schveighoffer wrote:--- new_range = [i * i for i in range(5) if i % 2 == 0] --- import std.range; auto new_range = iota(5) .filter!(i => i % 2) .map!(i => i * i); These produce different results, is that intended? I think the filter should be `filter!(i => i % 2 == 0)` For your use case it makes no difference if you map first or filter first. It might be useful to show a case where it does matter to highlight how the UFCS allows D to give a more natural order of the chained operations. Cheers, NormOn 12/7/19 4:28 AM, Jesse Phillips wrote:Yes because anything else is filtered out. I must have been thinking about addition :)On Friday, 6 December 2019 at 20:09:46 UTC, Paolo Invernizzi wrote:"In the first situation filtering came before the operation, here it will ultimately be useless because it operates on the square of a number which is always even." You sure about that? ;) -Steve[...]https://dev.to/jessekphillips/map-reduce-in-d-25nm This was my very brief comparison of List comprehension vs Ds libraries.
Dec 09 2019
On Tuesday, 10 December 2019 at 02:46:58 UTC, norm wrote:--- new_range = [i * i for i in range(5) if i % 2 == 0] --- import std.range; auto new_range = iota(5) .filter!(i => i % 2) .map!(i => i * i); These produce different results, is that intended? I think the filter should be `filter!(i => i % 2 == 0)` For your use case it makes no difference if you map first or filter first. It might be useful to show a case where it does matter to highlight how the UFCS allows D to give a more natural order of the chained operations. Cheers, NormDone, using addition and adding the missing equality
Dec 09 2019
On Friday, 6 December 2019 at 20:09:46 UTC, Paolo Invernizzi wrote:Maybe you are both right ... and maybe I've written too much Python code in the past years and indeed, UFCS chains are a killer future of D: every list comprehension was turned into a nice UFCS chain. Let's forget about that: the point is still taken by D, converting python code in D code is a pleasant experience!What I miss though is creating ranges with something like python's generator functions.
Dec 07 2019
On Saturday, 7 December 2019 at 09:59:01 UTC, Tobias Pankrath wrote:What I miss though is creating ranges with something like python's generator functions.Implement C++ stackless coroutines, perhaps? It will eventually be important to have something compatible in order to interface well.
Dec 07 2019
On Saturday, 7 December 2019 at 09:59:01 UTC, Tobias Pankrath wrote:On Friday, 6 December 2019 at 20:09:46 UTC, Paolo Invernizzi wrote:You can use std.range.generate with any random closure: import std.stdio; void main() { import std.range : take, zip, generate; auto multiples(int n) { int i; return generate!({ return i += n; }); } foreach (p; zip(multiples(2), multiples(3)).take(5)) { writeln(p[0], " ", p[1]); } } Or use std.concurrency to get the same control flow: void main() { import std.range : take, zip; import std.concurrency : Generator, yield; auto multiples(int n) { return new Generator!int({ int i; while (true) yield (i += n); }); } foreach (p; zip(multiples(2), multiples(3)).take(5)) { writeln(p[0], " ", p[1]); } }Maybe you are both right ... and maybe I've written too much Python code in the past years and indeed, UFCS chains are a killer future of D: every list comprehension was turned into a nice UFCS chain. Let's forget about that: the point is still taken by D, converting python code in D code is a pleasant experience!What I miss though is creating ranges with something like python's generator functions.
Dec 07 2019
On Saturday, 7 December 2019 at 10:17:46 UTC, mipri wrote:On Saturday, 7 December 2019 at 09:59:01 UTC, Tobias Pankrath wrote:Didn't know std.concurrency.Generator, thanks! With std.range.generate I don't know how to signal exhaustion/emptyness of a range. For simple infinite use cases it's cool though.[...]You can use std.range.generate with any random closure: import std.stdio; void main() { import std.range : take, zip, generate; auto multiples(int n) { int i; return generate!({ return i += n; }); } foreach (p; zip(multiples(2), multiples(3)).take(5)) { writeln(p[0], " ", p[1]); } } Or use std.concurrency to get the same control flow: void main() { import std.range : take, zip; import std.concurrency : Generator, yield; auto multiples(int n) { return new Generator!int({ int i; while (true) yield (i += n); }); } foreach (p; zip(multiples(2), multiples(3)).take(5)) { writeln(p[0], " ", p[1]); } }
Dec 07 2019
On Saturday, 7 December 2019 at 10:49:37 UTC, Tobias Pankrath wrote:On Saturday, 7 December 2019 at 10:17:46 UTC, mipri wrote:You can use Nullable (or Optional from dub) and a bit of post-processing to get a finite range: import std; void main() { auto seq(int start, int end) in (start <= end) { int i = start; return generate!({ if (i >= end) { return Nullable!int.init; } else { return nullable(i++); } }) .until!(n => n.isNull) .map!(n => n.get); } writeln(seq(10, 20).array); }You can use std.range.generate with any random closure: import std.stdio; void main() { import std.range : take, zip, generate; auto multiples(int n) { int i; return generate!({ return i += n; }); } foreach (p; zip(multiples(2), multiples(3)).take(5)) { writeln(p[0], " ", p[1]); } } [...]Didn't know std.concurrency.Generator, thanks! With std.range.generate I don't know how to signal exhaustion/emptyness of a range. For simple infinite use cases it's cool though.
Dec 07 2019
On Thursday, 5 December 2019 at 22:28:53 UTC, Adam D. Ruppe wrote:On Thursday, 5 December 2019 at 22:21:13 UTC, Walter Bright wrote:This is something that D excels at. That is why I like it. Many external world communication can be done efficiently. About a third of the code. There are still things in C++20 that cannot be done, but modules will allow to use using directives more liberally and they remove the implicit inline from classes. This means that code will get quite shorter I think. C++20 has a lot of baggage but still stays as a very competent language IMHO.D being about a third less code than C++ is consistent with my unscientific experience with it.Indeed, I actually frequently do even less. A lot of repetition in other languages I find myself able to automate pretty well in D. Whole blocks of 1,000 lines of glue code in other languages can be replaced with 30 lines of CT reflection stuff.
Dec 11 2019
On Thursday, 5 December 2019 at 22:21:13 UTC, Walter Bright wrote:https://danuker.go.ro/programming-languages.html I'm unsure of the accuracy of the methodology of determining this, but D does fairly well in it.It is probably better to look at the examples on the Rosetta website. Seems to me that some try to be terse, yet others try to show off language features. So, for the same language you have sometimes very verbose low level and very terse high level solutions (some are clearly cheating).
Dec 05 2019
On Friday, 6 December 2019 at 00:26:14 UTC, Ola Fosheim Grøstad wrote:On Thursday, 5 December 2019 at 22:21:13 UTC, Walter Bright wrote:They also use different (non-standard) libraries, which really depends on what they implement and what kind of interface they provide. Some of the C++ code examples have variables defined at the start in old C-style. With multiple variables just being declared on 7+ more lines. The examples weren't intended to be used a means to measure number of lines of code. Even on the page it points out that comments weren't taken into consideration. This data is extremely unreliable and should be taken with a huge grain of salt.https://danuker.go.ro/programming-languages.html I'm unsure of the accuracy of the methodology of determining this, but D does fairly well in it.It is probably better to look at the examples on the Rosetta website. Seems to me that some try to be terse, yet others try to show off language features. So, for the same language you have sometimes very verbose low level and very terse high level solutions (some are clearly cheating).
Dec 05 2019
On Friday, 6 December 2019 at 05:44:31 UTC, Jab wrote:provide. Some of the C++ code examples have variables defined at the start in old C-style. With multiple variables just being declared on 7+ more lines. The examples weren't intended to be used a means to measure number of lines of code.Yes, I think there are too many tasks in Rosetta as well. Many of the code examples states that it is translated from the C example. That clearly makes a lot of the code "unnatural" for any given language. Probably the D code too. C++ is more verbose than D. In part because the C++ std lib requires more syntax and also because C++ code often use explicit namespaces. C++ is gradually getting less verbose by newer features like for-each, lambdas and constexpr.
Dec 06 2019
On Friday, 6 December 2019 at 09:58:28 UTC, Ola Fosheim Grøstad wrote:C++ is more verbose than D. In part because the C++ std lib requires more syntax and also because C++ code often use explicit namespaces. C++ is gradually getting less verbose by newer features like for-each, lambdas and constexpr.Also, the need for headers. That alone can add considerably to a codebase.
Dec 06 2019
On Friday, 6 December 2019 at 10:16:59 UTC, Gregor Mückl wrote:Also, the need for headers. That alone can add considerably to a codebase.True, you that you have to specify the signature of all class members that is implemented in a .cpp file. So you often have to write a lot of code twice, once for the .hpp file and once for the .cpp file. Kinda made sense before C++ added templates as the .hpp file was slim and easy to read, now it is quite the opposite.
Dec 06 2019