Code layout for range-intensive D code

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Sun Jun 10 12:56:02 PDT 2012


"bearophile" <bearophileHUGS at lycos.com> wrote in message 
news:lkplokawtyisvwhvfsew at forum.dlang.org...
> The introduction of UFCS in D offers new ways to format D code, especially 
> when your code uses many high order functions. What is a good layout of 
> the D code in such situations? I have tried several alternative layouts, 
> and in the end I found to appreciate a layout similar to the one used in 
> F# code. Below I show a kind of  extreme example :-)
>
[...]
>
>     auto t = "table.txt"
>              .File()
>              .byLine()
>              .map!(r => r.removechars("^01".dup))()
>              .array();
>
>     const transposed = t[0]
>                        .length
>                        .iota()
>                        .map!(i => t.transversal(i).array())()
>                        .array();
>
>     (t ~ [(char[]).init] ~ transposed)
>     .map!(r => r
>                .group()
>                .filter!(p => p[0] == '1')()
>                .map!(p => p[1].text())()
>                .join(" ")
>          )()
>     .join("\n")
>     .writeln();
> }
>
>

That's basically what I do, except I always indent by exactly one tab.




More information about the Digitalmars-d mailing list