Why are you using D instead of Rust?

Ali Çehreli acehreli at yahoo.com
Sun Oct 24 21:18:06 UTC 2021

On 10/24/21 1:57 PM, Antonio wrote:
 > On Saturday, 23 October 2021 at 04:25:21 UTC, Dr Machine Code wrote:
 >> Just would like to know you all opinions
 > Try to write this in Rust

Are you saying Rust makes it difficult to write inefficient algorithms? 
I have to learn more about Rust then. ;)

 > ```d
 > T[] sorted(T)(T[] xs) {
 >    return  xs.length == 0 ? [] :
 >      xs[1..$].filter!(x=> x < xs[0]).array.sorted ~
 >      xs[0..1] ~
 >      xs[1..$].filter!(x=> x >= xs[0]).array.sorted;
 > void main() {
 >    [1,6,2,3,1,9,3].sorted.writeln;
 > }
 > ```

I am glad we can do that but the number of arrays allocated there is *I 
think* 4 per sorted() call. Ouch!

And picking the first element as the pivot is known to hurt worst-case 
performance horribly. (For example, passing already (or nearly) sorted 
data will be very bad there.)

 > D is not Scala... but it is more expressive than Rust (Thanks to UFCS,
 > Ranges & GC).

D is not Haskell either so let's at least pick a random pivot. ;)

"Who possibly missed a joke."

More information about the Digitalmars-d mailing list