Conversation
| pub fn new( | ||
| ty: Type, | ||
| pos: FPos, | ||
| long_distance: bool, | ||
| offset: FPos, | ||
| count: u32, | ||
| data: f32, | ||
| ) -> Self { | ||
| Self { | ||
| ty, | ||
| pos, | ||
| long_distance, | ||
| offset, | ||
| count, | ||
| data, | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
all the fields are public, no need for a constructor. Forcing users to use struct literals is also clearer, as you can see the field names.
There was a problem hiding this comment.
the constructor is still here. forgot to push maybe?
macmv
left a comment
There was a problem hiding this comment.
looking better, but it still needs some work. I think the reason I didn't add particles in the past is just because a 6-argument constructor is annoying. A builder would be much clearer, so I'd prefer to just have a builder and do it right the first time.
| pub fn new( | ||
| ty: Type, | ||
| pos: FPos, | ||
| long_distance: bool, | ||
| offset: FPos, | ||
| count: u32, | ||
| data: f32, | ||
| ) -> Self { | ||
| Self { | ||
| ty, | ||
| pos, | ||
| long_distance, | ||
| offset, | ||
| count, | ||
| data, | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
the constructor is still here. forgot to push maybe?
| }, | ||
| }) | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
cargo fmt is the way. make sure you're on the nightly toolchain, and it should just fix all this.
| let particle = particle::Particle::new( | ||
| "witch", | ||
| player.pos(), | ||
| true, | ||
| util::FPos::new(0.0, 0.0, 0.0), | ||
| 100, | ||
| 0.0, | ||
| ) |
There was a problem hiding this comment.
I dislike having a function take 6 arguments. I think using a builder like this would be clearer:
particle::Particle::builder("witch", player.pos())
.long_distance(true)
.velocity(0.0, 0.0, 0.0)
.amount(100)
.data(0.0)
.build()plus, the builder can have some defaults, so you don't need to set everything:
particle::Particle::builder("witch", player.pos())
.long_distance(true)
.amount(100)
.build()
No description provided.