-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Automagic number converting #247
Conversation
Oh the auto format changed quite a bit too :( - I'd vote for adopting the default formatting of rust-fmt just for consistencies sake... |
f2e60db
to
1bbd751
Compare
pub async fn forward(&mut self, distance: Distance) { | ||
pub async fn forward<T>(&mut self, distance: T) | ||
where | ||
f64: From<T>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could also be written as:
f64: From<T>, | |
Distance: From<T>, |
Fixed the formatting. For the generics either |
Hi @enaut, thanks for the suggestion and for taking the time to implement it. Using Writing I've actually filed an issue in the rust repo in the past to make the situation better by at least making sure we have a nice the error message for cases like this. My suggestions to allow Appreciate you starting this as a proof of concept so we could discuss it. Unfortunately it's not what we're going for with this crate. Thanks again for taking the time. |
That is very unfortunate. I used rust turtle in one course at my school and this proved to be an absolute show stopper (especially for the absolute beginners). - Thus I cannot really use rust turtle in the courses. The students know nothing about Could this decision be open for discussion again? |
Sorry to hear your students had such a bad experience. If the error messages were confusing we should open up issues on the rust repo and try to get that resolved. I really think this is something that needs to be resolved at the language level (if at all), not in the turtle crate itself. If absolute beginners to programming are learning rust and using this crate, we have far bigger hurdles to teach than explaining that numbers need to end in a decimal point in order to avoid errors. Integers and floating point numbers are not at all interchangeable in a language like Rust. Even if we allow students to write Again, I empathize with your students. That's why I filed that issue to improve the error message. I just really don't think this is something to be solved at the level of this crate. Supporting all different numeric types is likely to generate different types of confusion and I don't think avoiding |
Could it be a possibility to add a feature flag? – I agree that in some courses especially at university the difference between number types is essential – however for most turtle applications the difference is nonexistent. Just to stress again: I have said that they have to write |
Mhm another option that is independent from turtle-rs would be to create a wrapper crate. Maybe I'll do that. |
Sorry for the late reply. I was going to suggest some kind of wrapper too. If you want to avoid wrapping the whole turtle type and re-producing all the same methods, you could use an extension trait instead:
This requires teaching the students to import that trait every time, so you may prefer the wrapper to this, but I thought I'd offer another option just in case. I'm still pretty firm in my belief that if Hope the wrapper you're thinking of using helps your students! Sorry there isn't a great solution to this. |
Mhm I guess this boils down to personal preference. I don't mind so much to explain the difference between numbers especially when dividing. I think it totally makes sense that a division does weird things - they know that from earlier school years. But it does not make sense that the turtle cannot go |
Oh and thanks again for helping me out! |
It bothers me a lot that you always have to write
t.forward(100.0)
instead oft.forward(100)
.It turns out to be quite straight forward to make the argument type variable as long as it can be converted to f64 using the
From
trait.A sample function would be:
Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=11144955d3f2b0ae26e924612f905dd9
This PR contains a proof of concept implementation for the square example demonstrating different types as argument to
forward
andright
including a customstruct
that implementsimpl From<CustomStruct> for f64
.Would you appreciate that kind of change? Should I convert the whole turtle code base?