digitalmars.D.announce - Article: the feature that makes D my favorite programming language
- aberba (3/3) Jul 24 2020 Wrote something on the feature that makes D my favorite
- Ernesto Castellotti (2/5) Jul 24 2020 An interesting article, excellent job
- Steven Schveighoffer (10/14) Jul 24 2020 Nice!
- aberba (3/18) Jul 24 2020 Someone said something similar in the comments π .
- H. S. Teoh (10/14) Jul 24 2020 Nitpick: evenNumbers doesn't need to return int[]. In fact, dropping
- aberba (2/15) Jul 24 2020 Yeah, you're right.
- Andre Pany (16/19) Jul 25 2020 Great article. I assume you didn't chained writeln by purpose,
- aberba (3/23) Jul 25 2020 Oop! Chaining the writeln too could have increased the wow
- Adam D. Ruppe (3/5) Jul 25 2020 oh I hate it when people do that though, it just looks off to me
- aberba (3/8) Jul 25 2020 Ha ha. If you're writing idiomatic D code, why not not all in on
- Jesse Phillips (5/14) Jul 25 2020 It bugs me too, though I have done it.
- Paul Backus (11/26) Jul 25 2020 This is no different from any other "sink" that consumes a range:
- aberba (2/22) Jul 26 2020 I believe one can use tee!(writeln) to avoid consuming the range.
- =?UTF-8?Q?Ali_=c3=87ehreli?= (6/10) Jul 25 2020 I agree with Adam and others on this. My reasoning is, writeln's first
- H. S. Teoh (19/25) Jul 25 2020 Me too. It gives me the same creepie-feelies as when people write
- Aliak (6/32) Jul 26 2020 Oh my god ... itβs like haskells $ π€
- guai (1/1) Jul 26 2020 I find something like writable.writeTo(stdout) nicer
Wrote something on the feature that makes D my favorite programming language https://opensource.com/article/20/7/d-programming
Jul 24 2020
On Friday, 24 July 2020 at 20:34:17 UTC, aberba wrote:Wrote something on the feature that makes D my favorite programming language https://opensource.com/article/20/7/d-programmingAn interesting article, excellent job
Jul 24 2020
On 7/24/20 4:34 PM, aberba wrote:Wrote something on the feature that makes D my favorite programming language https://opensource.com/article/20/7/d-programmingNice! You could make this more dramatic. I'm sure you just "did it automatically", but you used UFCS in your function implementation as well! return numbers.filter!(n => n % 2 == 0).array; Without UFCS, this really should be written: array(filter!(n => n % 2 == 0)(numbers)); If you use that in the first boring non-UFCS version, then I think the wow factor goes up ;) -Steve
Jul 24 2020
On Friday, 24 July 2020 at 21:18:37 UTC, Steven Schveighoffer wrote:On 7/24/20 4:34 PM, aberba wrote:Someone said something similar in the comments π .Wrote something on the feature that makes D my favorite programming language https://opensource.com/article/20/7/d-programmingNice! You could make this more dramatic. I'm sure you just "did it automatically", but you used UFCS in your function implementation as well! return numbers.filter!(n => n % 2 == 0).array; Without UFCS, this really should be written: array(filter!(n => n % 2 == 0)(numbers)); If you use that in the first boring non-UFCS version, then I think the wow factor goes up ;)-Steve
Jul 24 2020
On Fri, Jul 24, 2020 at 08:34:17PM +0000, aberba via Digitalmars-d-announce wrote:Wrote something on the feature that makes D my favorite programming language https://opensource.com/article/20/7/d-programmingNitpick: evenNumbers doesn't need to return int[]. In fact, dropping the .array makes it even better because it avoids an unnecessary allocation when you're not going to store the array -- writeln is well able to handle printing arbitrary ranges. Let the caller call .array when he wishes the store the array; if it's transient, omitting .array saves an allocation. T -- Nearly all men can stand adversity, but if you want to test a man's character, give him power. -- Abraham Lincoln
Jul 24 2020
On Friday, 24 July 2020 at 21:19:28 UTC, H. S. Teoh wrote:On Fri, Jul 24, 2020 at 08:34:17PM +0000, aberba via Digitalmars-d-announce wrote:Yeah, you're right.Wrote something on the feature that makes D my favorite programming language https://opensource.com/article/20/7/d-programmingNitpick: evenNumbers doesn't need to return int[]. In fact, dropping the .array makes it even better because it avoids an unnecessary allocation when you're not going to store the array -- writeln is well able to handle printing arbitrary ranges. Let the caller call .array when he wishes the store the array; if it's transient, omitting .array saves an allocation. T
Jul 24 2020
On Friday, 24 July 2020 at 20:34:17 UTC, aberba wrote:Wrote something on the feature that makes D my favorite programming language https://opensource.com/article/20/7/d-programmingGreat article. I assume you didn't chained writeln by purpose, same for import std? ``` import std; int[] evenNumbers(int[] numbers) { return numbers.filter!(n => n % 2 == 0).array; } void main() { [1, 2, 3, 4].evenNumbers.writeln; } ``` Kind regards Andre
Jul 25 2020
On Saturday, 25 July 2020 at 10:22:53 UTC, Andre Pany wrote:On Friday, 24 July 2020 at 20:34:17 UTC, aberba wrote:Oop! Chaining the writeln too could have increased the wow factor. I didn't see that.Wrote something on the feature that makes D my favorite programming language https://opensource.com/article/20/7/d-programmingGreat article. I assume you didn't chained writeln by purpose, same for import std? ``` import std; int[] evenNumbers(int[] numbers) { return numbers.filter!(n => n % 2 == 0).array; } void main() { [1, 2, 3, 4].evenNumbers.writeln; } ``` Kind regards Andre
Jul 25 2020
On Saturday, 25 July 2020 at 11:12:16 UTC, aberba wrote:Oop! Chaining the writeln too could have increased the wow factor. I didn't see that.oh I hate it when people do that though, it just looks off to me at that point.
Jul 25 2020
On Saturday, 25 July 2020 at 13:28:34 UTC, Adam D. Ruppe wrote:On Saturday, 25 July 2020 at 11:12:16 UTC, aberba wrote:Ha ha. If you're writing idiomatic D code, why not not all in on it?Oop! Chaining the writeln too could have increased the wow factor. I didn't see that.oh I hate it when people do that though, it just looks off to me at that point.
Jul 25 2020
On Saturday, 25 July 2020 at 14:47:01 UTC, aberba wrote:On Saturday, 25 July 2020 at 13:28:34 UTC, Adam D. Ruppe wrote:It bugs me too, though I have done it. I think the right answer of why it is odd is because writeln is void. As soon as it is placed on the end the chain is broken and you can't expand on it.On Saturday, 25 July 2020 at 11:12:16 UTC, aberba wrote:Ha ha. If you're writing idiomatic D code, why not not all in on it?Oop! Chaining the writeln too could have increased the wow factor. I didn't see that.oh I hate it when people do that though, it just looks off to me at that point.
Jul 25 2020
On Saturday, 25 July 2020 at 18:24:22 UTC, Jesse Phillips wrote:On Saturday, 25 July 2020 at 14:47:01 UTC, aberba wrote:This is no different from any other "sink" that consumes a range: someSource .map!foo .filter!bar .splitter(baz) .each!quux; `each` returns void [1], so using it ends the chain. But that's not a problem, because the whole *point* of using `each` is to consume the range. [1] Not exactly, but close enough.On Saturday, 25 July 2020 at 13:28:34 UTC, Adam D. Ruppe wrote:It bugs me too, though I have done it. I think the right answer of why it is odd is because writeln is void. As soon as it is placed on the end the chain is broken and you can't expand on it.On Saturday, 25 July 2020 at 11:12:16 UTC, aberba wrote:Ha ha. If you're writing idiomatic D code, why not not all in on it?Oop! Chaining the writeln too could have increased the wow factor. I didn't see that.oh I hate it when people do that though, it just looks off to me at that point.
Jul 25 2020
On Sunday, 26 July 2020 at 01:14:53 UTC, Paul Backus wrote:On Saturday, 25 July 2020 at 18:24:22 UTC, Jesse Phillips wrote:I believe one can use tee!(writeln) to avoid consuming the range.On Saturday, 25 July 2020 at 14:47:01 UTC, aberba wrote:This is no different from any other "sink" that consumes a range: someSource .map!foo .filter!bar .splitter(baz) .each!quux; `each` returns void [1], so using it ends the chain. But that's not a problem, because the whole *point* of using `each` is to consume the range. [1] Not exactly, but close enough.[...]It bugs me too, though I have done it. I think the right answer of why it is odd is because writeln is void. As soon as it is placed on the end the chain is broken and you can't expand on it.
Jul 26 2020
On 7/25/20 7:47 AM, aberba wrote:On Saturday, 25 July 2020 at 13:28:34 UTC, Adam D. Ruppe wrote:I agree with Adam and others on this. My reasoning is, writeln's first parameter is not special compared to its other parameters. In other words, I can't see writeln as a special operation on its first argument. Except, when there is just one thing... Meh... I don't like it. :) Alioh I hate it when people do that though, it just looks off to me at that point.Ha ha. If you're writing idiomatic D code, why not not all in on it?
Jul 25 2020
On Sat, Jul 25, 2020 at 01:28:34PM +0000, Adam D. Ruppe via Digitalmars-d-announce wrote:On Saturday, 25 July 2020 at 11:12:16 UTC, aberba wrote:Me too. It gives me the same creepie-feelies as when people write writeln(x) as: writeln = x; Actually, D's lax syntax surrounding the = operator gives rise to the following reverse-UFCS nastiness: // Cover your eyes (unless you're reverse-Polish :-P)! and don't // do this at home, it will corrupt your sense of good coding // style! import std; void main() { writeln = filter!(x => x % 3 == 1) = map!(x => x*2) = [ 1, 2, 3, 4, 5, 6 ]; } // Output: [4, 10] T -- Winners never quit, quitters never win. But those who never quit AND never win are idiots.Oop! Chaining the writeln too could have increased the wow factor. I didn't see that.oh I hate it when people do that though, it just looks off to me at that point.
Jul 25 2020
On Saturday, 25 July 2020 at 16:22:52 UTC, H. S. Teoh wrote:On Sat, Jul 25, 2020 at 01:28:34PM +0000, Adam D. Ruppe via Digitalmars-d-announce wrote:Oh my god ... itβs like haskells $ π€ Why is this allowed? I mean, ok, it was probably done to allow property syntax. But how did this end up being applied to every function? Can this be fixed?On Saturday, 25 July 2020 at 11:12:16 UTC, aberba wrote:Me too. It gives me the same creepie-feelies as when people write writeln(x) as: writeln = x; Actually, D's lax syntax surrounding the = operator gives rise to the following reverse-UFCS nastiness: // Cover your eyes (unless you're reverse-Polish :-P)! and don't // do this at home, it will corrupt your sense of good coding // style! import std; void main() { writeln = filter!(x => x % 3 == 1) = map!(x => x*2) = [ 1, 2, 3, 4, 5, 6 ]; } // Output: [4, 10] TOop! Chaining the writeln too could have increased the wow factor. I didn't see that.oh I hate it when people do that though, it just looks off to me at that point.
Jul 26 2020