Thread overview | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
July 24, 2020 Article: the feature that makes D my favorite programming language | ||||
---|---|---|---|---|
| ||||
Wrote something on the feature that makes D my favorite programming language https://opensource.com/article/20/7/d-programming |
July 24, 2020 Re: Article: the feature that makes D my favorite programming language | ||||
---|---|---|---|---|
| ||||
Posted in reply to aberba | 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-programming
An interesting article, excellent job
|
July 24, 2020 Re: Article: the feature that makes D my favorite programming language | ||||
---|---|---|---|---|
| ||||
Posted in reply to aberba | 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-programming
Nice!
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
|
July 24, 2020 Re: Article: the feature that makes D my favorite programming language | ||||
---|---|---|---|---|
| ||||
Posted in reply to aberba | 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-programming Nitpick: 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 |
July 24, 2020 Re: Article: the feature that makes D my favorite programming language | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | 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:
>> Wrote something on the feature that makes D my favorite programming language
>>
>> https://opensource.com/article/20/7/d-programming
>
> Nitpick: 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
Yeah, you're right.
|
July 24, 2020 Re: Article: the feature that makes D my favorite programming language | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Friday, 24 July 2020 at 21:18:37 UTC, Steven Schveighoffer wrote: > 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-programming > > Nice! > > 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 ;) Someone said something similar in the comments 😅. > > -Steve |
July 25, 2020 Re: Article: the feature that makes D my favorite programming language | ||||
---|---|---|---|---|
| ||||
Posted in reply to aberba | 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-programming
Great 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
|
July 25, 2020 Re: Article: the feature that makes D my favorite programming language | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre Pany | 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:
>> Wrote something on the feature that makes D my favorite programming language
>>
>> https://opensource.com/article/20/7/d-programming
>
> Great 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
Oop! Chaining the writeln too could have increased the wow factor. I didn't see that.
|
July 25, 2020 Re: Article: the feature that makes D my favorite programming language | ||||
---|---|---|---|---|
| ||||
Posted in reply to aberba | 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.
|
July 25, 2020 Re: Article: the feature that makes D my favorite programming language | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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:
>> 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.
Ha ha. If you're writing idiomatic D code, why not not all in on it?
|
Copyright © 1999-2021 by the D Language Foundation