Rust Code in the Wild

Meta jared771 at gmail.com
Thu Sep 5 12:14:48 PDT 2013


On Thursday, 5 September 2013 at 13:50:59 UTC, Timon Gehr wrote:
> Why? I cannot spot any syntax I wouldn't get used to quickly in 
> this example. (AFAIK the @ are going away in favour of a 
> library solution with more verbose syntax though.)
>
> In D something similar would look like this:
>
> struct BodyWorld(N, LV, AV, M, II, CM){
>     World!(N, Body!(N, LV, AV, M, II), Constraint!(N, LV, AV, 
> M, II)) world;
>     BodyForceGenerator!(N, LV, AV, M, II)* forces;
>     BodySmpEulerIntegrator!(N, LV, AV, M, II)* integrator;
>     BodiesBodies!(N, LV, AV, M, II, BF!(N, LV, AV, M, II))* 
> detector;
>     IslandActivationManager!(N, LV, AV, M, II)* sleep;
>     SweptBallMotionClamping!(N, LV, AV, M, II, BF!(N, LV, AV, 
> M, II))* ccd;
>     JointManager!(N, LV, AV, M, II)* joints;
>     AccumulatedImpulseSolver!(N, LV, AV, M, II, CM)* solver;
> }
>
> Afaics there is not much of a difference. Arguably, having the 
> identifiers conveniently aligned to the left is actually a 
> slight advantage of rust's syntax.
>
> Of course, the code contains a certain amount of duplication I 
> wouldn't really want to write down, and this could be improved 
> in D:
>
> struct BodyWorld(N, LV, AV, M, II, CM){
>     private alias Args = Seq!(N, LV, AV, M, II);
>
>     World!(N, Body!Args, Constraint!Args)    world;
>     BodyForceGenerator!Args*                 forces;
>     BodySmpEulerIntegrator!Args*             integrator;
>     BodiesBodies!(Args, BF!Args)*            detector;
>     IslandActivationManager!Args*            sleep;
>     SweptBallMotionClamping!(Args, BF!Args)* ccd;
>     JointManager!Args*                       joints;
>     AccumulatedImpulseSolver!(Args, CM)*     solver;
> }

Just looking at the code, it looks very dense. The multiple 
nested <> brackets (D was right to get rid of these) and the @mut 
really bog down the code (I am aware that @mut has been moved to 
a library solution now). Like I said, Rust coders no doubt get 
used to parsing and understanding the different symbols, but to 
an outsider it's a lot to take in. Note that this is only one 
example. I found several other instances such as this in the 
codebase that were difficult to make sense of at first. The thing 
that trips me up the most, I think, are the lifetimes.


More information about the Digitalmars-d mailing list