digitalmars.D.learn - Verbosity in D
- pascal111 (12/12) Aug 07 2022 It's clear by working with D that it has the same bad point like
- jfondren (15/19) Aug 07 2022 That's not clear to me at all, and your Pascal example about a
- pascal111 (6/25) Aug 07 2022 Do consider Go and Rust languages in the same level of C++ to
- Emanuele Torre (17/18) Aug 07 2022 ```C++
- pascal111 (3/21) Aug 07 2022 It seems complex, I didn't get it yet, I wished I didn't ask
- Emanuele Torre (15/40) Aug 07 2022 It's really trivial.
- Emanuele Torre (2/3) Aug 07 2022 Oops, this is C++, not D: `int arr[] = { 10, 12, 14 };` =)
- pascal111 (4/24) Aug 07 2022 Really, I'm not sure I'm understanding this syntax `auto [x, y] =
- Emanuele Torre (9/35) Aug 07 2022 D does not have it. You have already been told that when they
- Emanuele Torre (4/17) Aug 07 2022 Regaring this, I don't understand what you mean either.
- pascal111 (6/26) Aug 07 2022 I don't have specific code but it was a general notice. Take
- Emanuele Torre (12/39) Aug 07 2022 You are just sounding like a troll now...
- pascal111 (3/16) Aug 07 2022 Maybe I'm wrong, your words sound that Python isn't verbose-less.
- TTK Ciar (33/38) Aug 07 2022 There is definitely a spectrum of programming language practical
- Dom Disc (7/10) Aug 07 2022 For long function names you can define short aliases, for syntax
- bauss (19/24) Aug 08 2022 Yeah I don't think this is true. The only clear difference
- Siemargl (5/9) Aug 07 2022 In most cases this is a false statement.
It's clear by working with D that it has the same bad point like Pascal language; the "verbosity". Is there any plans in future to make some shorthanded techniques that clean verbosity from D? Quote: "In terms of functionality, Pascal is pretty much exactly the same as C, except with some sanity-conserving restrictions on one hand, and more verbose syntax on the other. It was an okay language for the time when it was popular, and I would give it kudos just for having the common sense to make the assignment operator := instead of =, and not allowing it to be chained, but verbosity back then was still something to be avoided if possible, so C was naturally seen as superior." https://www.quora.com/Is-there-a-value-learning-Pascal-now-Are-there-actually-any-parts-where-Pascal-is-better-than-C-Is-this-language-worth-investing-time-into-What-would-the-added-value-be-if-I-learn-it
Aug 07 2022
On Sunday, 7 August 2022 at 16:01:08 UTC, pascal111 wrote:It's clear by working with D that it has the same bad point like Pascal language; the "verbosity". Is there any plans in future to make some shorthanded techniques that clean verbosity from D?That's not clear to me at all, and your Pascal example about a feature that C and D both have, that doesn't help either. Post some code that seems particularly verbose to you. I think 'library code' tends to grow attributes like mushrooms, and that D gets longer when you try to avoid the GC, but casual use of D isn't more verbose than scripting languages. With competitors like Rust and C++ Go and and Zig, D usually wins pretty significantly in this respect. The only consistently less verbose language in this space is Nim, IMO. With that said, dmd previews =in and =shortenedMethods both allow shorter expressions in D. And there are some C++ (and even C) convenience features that D doesn't have, like destructuring binds, or doesn't like, like anonymous struct literals with named fields.
Aug 07 2022
On Sunday, 7 August 2022 at 16:45:15 UTC, jfondren wrote:On Sunday, 7 August 2022 at 16:01:08 UTC, pascal111 wrote:Do consider Go and Rust languages in the same level of C++ to make this comparison? I didn't use these languages before but I think they are just new languages which has no real history like C++ to compare with!!!It's clear by working with D that it has the same bad point like Pascal language; the "verbosity". Is there any plans in future to make some shorthanded techniques that clean verbosity from D?That's not clear to me at all, and your Pascal example about a feature that C and D both have, that doesn't help either. Post some code that seems particularly verbose to you. I think 'library code' tends to grow attributes like mushrooms, and that D gets longer when you try to avoid the GC, but casual use of D isn't more verbose than scripting languages. With competitors like Rust and C++ Go and and Zig, D usually wins pretty significantly in this respect. The only consistently less verbose language in this space is Nim, IMO.With that said, dmd previews =in and =shortenedMethods both allow shorter expressions in D. And there are some C++ (and even C) convenience features that D doesn't have, like destructuring binds, or doesn't like, like anonymous struct literals with named fields.What destructuring binds? I didn't hear about that before.
Aug 07 2022
On Sunday, 7 August 2022 at 20:15:05 UTC, pascal111 wrote:What destructuring binds? I didn't hear about that before.```C++ #include <iostream> struct Point { int x, y; }; Point add_points(const Point& a, const Point& b) { return { a.x + b.x, a.y + b.y }; } int main() { const auto [x, y] = add_points({ 1, 10 }, { -60, 40 }); std::cout << "x is: " << x << '\n'; std::cout << "y is: " << y << '\n'; } ```
Aug 07 2022
On Sunday, 7 August 2022 at 22:16:55 UTC, Emanuele Torre wrote:On Sunday, 7 August 2022 at 20:15:05 UTC, pascal111 wrote:It seems complex, I didn't get it yet, I wished I didn't ask about it :)What destructuring binds? I didn't hear about that before.```C++ #include <iostream> struct Point { int x, y; }; Point add_points(const Point& a, const Point& b) { return { a.x + b.x, a.y + b.y }; } int main() { const auto [x, y] = add_points({ 1, 10 }, { -60, 40 }); std::cout << "x is: " << x << '\n'; std::cout << "y is: " << y << '\n'; } ```
Aug 07 2022
On Sunday, 7 August 2022 at 23:31:45 UTC, pascal111 wrote:On Sunday, 7 August 2022 at 22:16:55 UTC, Emanuele Torre wrote:It's really trivial. `auto [x, y] = getpoint();` is equivalent to ```C++ auto _p = getpoint(); auto x = _p.x /* first element of the struct */; auto y = _p.y /* second element of the struct */;` ``` Also works with arrays. ```C++ int[] arr = { 10, 12, 14 }; const auto [x, y, z] = arr; /* x=10 y=12 z=14 */ ``` A lot of programming languages have this.On Sunday, 7 August 2022 at 20:15:05 UTC, pascal111 wrote:It seems complex, I didn't get it yet, I wished I didn't ask about it :)What destructuring binds? I didn't hear about that before.```C++ #include <iostream> struct Point { int x, y; }; Point add_points(const Point& a, const Point& b) { return { a.x + b.x, a.y + b.y }; } int main() { const auto [x, y] = add_points({ 1, 10 }, { -60, 40 }); std::cout << "x is: " << x << '\n'; std::cout << "y is: " << y << '\n'; } ```
Aug 07 2022
On Sunday, 7 August 2022 at 23:44:26 UTC, Emanuele Torre wrote:int[] arr = { 10, 12, 14 };Oops, this is C++, not D: `int arr[] = { 10, 12, 14 };` =)
Aug 07 2022
On Sunday, 7 August 2022 at 23:44:26 UTC, Emanuele Torre wrote:On Sunday, 7 August 2022 at 23:31:45 UTC, pascal111 wrote:Really, I'm not sure I'm understanding this syntax `auto [x, y] = getpoint();`, if you have the name of term of it in D or an explaining link.On Sunday, 7 August 2022 at 22:16:55 UTC, Emanuele Torre wrote:It's really trivial. `auto [x, y] = getpoint();` is equivalent to ```C++ auto _p = getpoint(); auto x = _p.x /* first element of the struct */; auto y = _p.y /* second element of the struct */;` ``` Also works with arrays. ```C++ int[] arr = { 10, 12, 14 }; const auto [x, y, z] = arr; /* x=10 y=12 z=14 */ ``` A lot of programming languages have this.[...]It seems complex, I didn't get it yet, I wished I didn't ask about it :)
Aug 07 2022
On Monday, 8 August 2022 at 00:15:48 UTC, pascal111 wrote:On Sunday, 7 August 2022 at 23:44:26 UTC, Emanuele Torre wrote:D does not have it. You have already been told that when they have been mentioned. If you want more information about it in C++, you could read https://en.cppreference.com/w/cpp/language/structured_binding or, for javascript, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment. That was just meant to be a simple example to show what jfondren meant with "destructing bindings".On Sunday, 7 August 2022 at 23:31:45 UTC, pascal111 wrote:Really, I'm not sure I'm understanding this syntax `auto [x, y] = getpoint();`, if you have the name of term of it in D or an explaining link.On Sunday, 7 August 2022 at 22:16:55 UTC, Emanuele Torre wrote:It's really trivial. `auto [x, y] = getpoint();` is equivalent to ```C++ auto _p = getpoint(); auto x = _p.x /* first element of the struct */; auto y = _p.y /* second element of the struct */;` ``` Also works with arrays. ```C++ int[] arr = { 10, 12, 14 }; const auto [x, y, z] = arr; /* x=10 y=12 z=14 */ ``` A lot of programming languages have this.[...]It seems complex, I didn't get it yet, I wished I didn't ask about it :)
Aug 07 2022
On Sunday, 7 August 2022 at 16:01:08 UTC, pascal111 wrote:It's clear by working with D that it has the same bad point like Pascal language; the "verbosity". Is there any plans in future to make some shorthanded techniques that clean verbosity from D? Quote: "In terms of functionality, Pascal is pretty much exactly the same as C, except with some sanity-conserving restrictions on one hand, and more verbose syntax on the other. It was an okay language for the time when it was popular, and I would give it kudos just for having the common sense to make the assignment operator := instead of =, and not allowing it to be chained, but verbosity back then was still something to be avoided if possible, so C was naturally seen as superior." https://www.quora.com/Is-there-a-value-learning-Pascal-now-Are-there-actually-any-parts-where-Pascal-is-better-than-C-Is-this-language-worth-investing-time-into-What-would-the-added-value-be-if-I-learn-itRegaring this, I don't understand what you mean either. How is D unnecesarily verbose? Do you have any specific example?
Aug 07 2022
On Sunday, 7 August 2022 at 23:53:36 UTC, Emanuele Torre wrote:On Sunday, 7 August 2022 at 16:01:08 UTC, pascal111 wrote:I don't have specific code but it was a general notice. Take Python as in example, the same program in Python doesn't cost much code as D code, and of course by putting in accounts that that I assume that there are some special tasks D can do, while Python can't do.It's clear by working with D that it has the same bad point like Pascal language; the "verbosity". Is there any plans in future to make some shorthanded techniques that clean verbosity from D? Quote: "In terms of functionality, Pascal is pretty much exactly the same as C, except with some sanity-conserving restrictions on one hand, and more verbose syntax on the other. It was an okay language for the time when it was popular, and I would give it kudos just for having the common sense to make the assignment operator := instead of =, and not allowing it to be chained, but verbosity back then was still something to be avoided if possible, so C was naturally seen as superior." https://www.quora.com/Is-there-a-value-learning-Pascal-now-Are-there-actually-any-parts-where-Pascal-is-better-than-C-Is-this-language-worth-investing-time-into-What-would-the-added-value-be-if-I-learn-itRegaring this, I don't understand what you mean either. How is D unnecesarily verbose? Do you have any specific example?
Aug 07 2022
On Monday, 8 August 2022 at 00:11:33 UTC, pascal111 wrote:On Sunday, 7 August 2022 at 23:53:36 UTC, Emanuele Torre wrote:You are just sounding like a troll now... That makes no sense: "I assume that there are some special tasks D can do, while Python can't do" How? "Take Python as in example, the same program in Python doesn't cost much code as D code" What same program are you talking about? Why did you mention python as if you showed me an example I can see? What am I supposed to say if can't even explain or show an example of how D is more verbose?On Sunday, 7 August 2022 at 16:01:08 UTC, pascal111 wrote:I don't have specific code but it was a general notice. Take Python as in example, the same program in Python doesn't cost much code as D code, and of course by putting in accounts that that I assume that there are some special tasks D can do, while Python can't do.It's clear by working with D that it has the same bad point like Pascal language; the "verbosity". Is there any plans in future to make some shorthanded techniques that clean verbosity from D? Quote: "In terms of functionality, Pascal is pretty much exactly the same as C, except with some sanity-conserving restrictions on one hand, and more verbose syntax on the other. It was an okay language for the time when it was popular, and I would give it kudos just for having the common sense to make the assignment operator := instead of =, and not allowing it to be chained, but verbosity back then was still something to be avoided if possible, so C was naturally seen as superior." https://www.quora.com/Is-there-a-value-learning-Pascal-now-Are-there-actually-any-parts-where-Pascal-is-better-than-C-Is-this-language-worth-investing-time-into-What-would-the-added-value-be-if-I-learn-itRegaring this, I don't understand what you mean either. How is D unnecesarily verbose? Do you have any specific example?
Aug 07 2022
On Monday, 8 August 2022 at 00:18:12 UTC, Emanuele Torre wrote:On Monday, 8 August 2022 at 00:11:33 UTC, pascal111 wrote:"troll" :) I like it![...]You are just sounding like a troll now...That makes no sense: "I assume that there are some special tasks D can do, while Python can't do" How? "Take Python as in example, the same program in Python doesn't cost much code as D code" What same program are you talking about? Why did you mention python as if you showed me an example I can see? What am I supposed to say if can't even explain or show an example of how D is more verbose?Maybe I'm wrong, your words sound that Python isn't verbose-less.
Aug 07 2022
On Monday, 8 August 2022 at 00:11:33 UTC, pascal111 wrote:I don't have specific code but it was a general notice. Take Python as in example, the same program in Python doesn't cost much code as D code, and of course by putting in accounts that that I assume that there are some special tasks D can do, while Python can't do.There is definitely a spectrum of programming language practical expressiveness (the opposite of verbosity), with the dynamic languages (python, perl, ruby) on the "most expressive" end, and static languages (C, C++, Java) on the "most verbose" end. D is somewhere in the middle of that spectrum, much more expressive than C but not as expressive as python. The trade-off is much better run-time performance and lower memory overhead compared to the dynamic languages. I've been writing C, Perl and Python for a living for a while, following the common practice of writing a solution in Perl or Python first, for shortest possible development time, and then rewriting performance-intensive bits in C when more performance is needed. The appeal of D, to me, is that it gives me something akin to the same approach with just one language. I can write very concise, expressive D when performance doesn't matter, and then write more verbose C-like D when I need C-like performance, all in the same source file, with the same language. Having a sane and useful threading model is an added bonus. Neither python nor perl nor nodejs have useful threads, whereas D gives us real, concurrent threads with a fraction of the boilerplate -- https://tour.dlang.org/tour/en/multithreading/synchronization-sharing On the other hand, I've noticed that D's idiomatic brevity can be diluted by the extremely verbose function names used in the standard library. Sure, foreach loops can be just as concise as python's -- foreach(i; arr) -- but then you end up getting carpal tunnel syndrome anyway from typing out "AllImplicitConversionTargets" or "filterBidirectional" or "levenshteinDistanceAndPath". My impression is that brevity is more important to the language developers than it is to the phobos developers.
Aug 07 2022
On Monday, 8 August 2022 at 00:40:11 UTC, TTK Ciar wrote:On the other hand, I've noticed that D's idiomatic brevity can be diluted by the extremely verbose function names used in the standard library.For long function names you can define short aliases, for syntax you can't. So having short and efficient language constructs is by far more important than short function names. Especially a standard-library is much better off having descriptive and unique names - which sort of requires them to be long.
Aug 07 2022
On Monday, 8 August 2022 at 00:11:33 UTC, pascal111 wrote:I don't have specific code but it was a general notice. Take Python as in example, the same program in Python doesn't cost much code as D code, and of course by putting in accounts that that I assume that there are some special tasks D can do, while Python can't do.Yeah I don't think this is true. The only clear difference between D and Python is the vast amount of libraries that Python has and that D is a static-typed language, Python is not (by default) You generally don't write much more code. Loops, ranges etc. are all just as pleasant to work with in D as they are in Python. I'd argue it's even easier to work with classes in D than in Python, and even easier to work with metadata in D than any other language. Python has an unnecessary amount of verbosity when it comes to OOP (because it really isn't an OOP language.) I think D only looks verbose to people who don't really understand its metaprogramming capabilities, templates and/or are new to the language and perhaps come from dynamic typed languages. But I don't think D is in particular more verbose than Python, you can write very similar expressions and some code are almost 1:1 in Python and D when you only consider syntax.
Aug 08 2022
On Sunday, 7 August 2022 at 16:01:08 UTC, pascal111 wrote:It's clear by working with D that it has the same bad point like Pascal language; the "verbosity". Is there any plans in future to make some shorthanded techniques that clean verbosity from D?In most cases this is a false statement. Just see examples on frontpage of dlang site. Or try write and compare concrete programs. Python have a good expressiveness, but up to 100 times slower.
Aug 07 2022