eliminate cast (style)

Bruno Medeiros brunodomedeiros+spam at com.gmail
Tue Jun 10 08:25:27 PDT 2008


downs wrote:

> 
> Where did you get that idea?
> In this case, basically, we know the file is really text. So we put this knowledge into code by assuring the compiler that yes, the arbitrary data you've just read _is_ text after all.
> In any case, it's just a reinterpreting cast. It doesn't change any actual data. So no time lost.
> 
> Also, just fyi, here's how that code would look like in tools.functional:
> 
> gentoo-pc ~ $ cat test2.d; echo -----; rebuild test2.d -oftest2 && ./test2

> module test2;
> import std.stdio, std.file, tools.functional, std.string: split, atoi;
> void main() {
>   auto sizes = (cast(string) "test.txt".read()).split() /map/ &atoi;
>   writefln(sizes);
> }
> -----
> [345,5467,45,238]
> 
> 
> I still prefer infix ^^
> 
>  --downs

Once again I see that wicked operator overloading.
Am I the only one to find this code... ingenious but distasteful?

Isn't this nicer?:
   auto sizes = (cast(string) "test.txt".read()).split().map(&atoi);


-- 
Bruno Medeiros - Software Developer, MSc. in CS/E graduate
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list