3 ms·
Rust Keyword Arguments, Optional Arguments, and Variable-Arity
- flerovium 5y agoI can't think of a feature that would help me convince the team to migrate more to Rust. Rust is young; it learns from the mistakes of old languages and picks the best. E.g. Python's default arguments were declared once; JavaScript's are recreated on each invocation.
- cfcosta 5y agoCan you elaborate a little bit why it would be important? I get the appeal, of course, but having spent lots of time in Rust the past few years, it feels like polymorphism/traits cover that hole quite well, and will get better once/if GATs get fully implemented (different implementations for different enum variants). Maybe I'm too biased by the current state, how do you think optional arguments would make it better?
- flerovium 5y agoNamed parameters came from Smalltalk, and no explanation I give can equal the sheet beauty of reading smalltalk code. I'm not sure I could devise a full explanation, but a concise example is in scientific libraries for functions like, `run_simulation(data, optimizer = "Lebesque", shearing_algorithm = "Neue", spline_intensity = "Forrester")`. The number of options can be very large.
- cfcosta 5y agoOh, smalltalk is neat, indeed, but would need both optional and named arguments at the same time to get the same effect, right? Would still make sense to you to get one without the other? I think optional is much more possible than named :P
- vegai_ 5y agoThese days, this is probably the only thing I miss from python when I write Rust.
- potatochup 5y agoMe too. And IDE helps a lot (because it'll inline the argument names for you) but code reviews and etc are still difficult sometimes