TeamMeanMachine / meanlib

A Kotlin FRC library
The Unlicense
16 stars 3 forks source link

[WIP] Simplify event loop #28

Closed hybras closed 1 year ago

hybras commented 4 years ago

Varun, from Team 25 here. I've tried to simplify the startCompetition main event loop.

tylerscheuble commented 4 years ago

Hi Varun, Thank you for your PR and your interest in meanlib!

Your code is very interesting, but you should know that MeanlibRobot is a particularly sensitive bit of code and we tend to avoid refactoring at this stage in the season if we can help it. It is unlikely that we would merge this until after our season is over.

That being said, I am happy to help with your questions:

I also need help making line 56 more idiomatic (I need to pass in the current robot object, but "this" now refers to the CoroutineScope.)

On like 56 you can refer to the robot object with this@MeanlibRobot, without having to assign it to a val above. There's a bit more information about that here: https://kotlinlang.org/docs/tutorials/kotlin-for-py/functional-programming.html?q=this%40&p=0#receivers

I do not fully understand the ifs at the beginning of the loop (lines 40-46). I'd like to remove this logic and incorporate it into the generic "On robot state change" logic in the rest of the loop.

This code allows for a special comms method to be run whenever communication is established between the robot and the driver station. It was added by Team 2521 in PR #23 . We haven't taken advantage of this as far as I can remember.

Also one other tip: KFunction0<Unit> shouldn't be necessary. It should be sufficient to use the () -> Unit type annotation, which also allows us to avoid the cast on line 113.

hybras commented 4 years ago

Thank you so much for your comments. I understand that now is far from the best time to accept a merge to such a critical section. I simply saw something I though I could improve. I have significant freedom regarding programming choices on my team, maybe I'll try testing this out (if our robot doesn't blind me, that is). I'm going to apply your suggestions.

I have no interest in pursuing this PR further than that. I starting learning kotlin 2 months ago and now feel confident enough to use it in my team's projects. I just thought I would apply some of my new kotlin chops, and take some advice along the way. Thanks for your help.

P.S. I'd be honored if this could be considered my first open source contribution. No pressure from me regarding any sort of timeline, just curious.