![]() |
How is this looking?
I'd love to hear some feedback from people who actually know about this stuff (My team is first year and nobody is really above me in terms of java knowledge - or frc strategies in code)
Code:
/* |
Re: How is this looking?
I notice several *interesting* redundancies and *different* ways of doing things.
But practically, code is supposed to be judged on usefulness. 1. Does it work? 2. Does it break? If yes to 1 and no to 2, then it's great. No one on your team will know the difference. :p |
Re: How is this looking?
Consistency is key in making maintainable code, which will save you from headaches in the future.
Not all of the following things can be done immediately, since programming is something that takes time to learn. 1) Having a standardized naming convention will make code much more readable, and thusly maintainable by larger teams. For example, the code contains the following: 1a) VariableName, variableName 1b) METHODNAME (which to a some would look like some sort of macro), methodName 1c) CONSTANT_NAME, ConstantName 2) Breaking up your code into organized classes increases code maintainability (You have object oriented programming! Take advantage of that!) 3) Use the features available in your language. One thing that really caught my attention is this: Code:
public void timerControl(String args) {4) Consider designing the "contract" which comes with a method. When I call something named "Get Emergency", I expect it tells me something along the lines of "Is there a critical failure?" or "Is the emergency button pressed?". I don't expect it to actually mutate the state of the robot (GetEmergency can stop the drive train) 5) I should note that Code:
while(getBrake() == false && getEmergency() == false)Code:
while(!getBrake() && !getEmergency())ItzWarty |
Re: How is this looking?
Your team is lucky to have you! While there are definitely some differences in conventions.... I agree with the previous posters.
If the code works, then who cares! Of course, in a professional world, optimizing code can definitely be a big factor, but for this application it's not necessary. |
Re: How is this looking?
Thanks for the feedback guys :)
I just have one question about the whole object oriented stuff. Honestly, I just havnt had to time to even start understanding how java really works. I'm mostly basing my code on what I know already from other languages. My question is, how would I use separate classes and still pull variables from all of them? Or is that question invalid (public modifier)? I would also love to hava a constantly updating print function that shows speed, turning, gyro, encoders, etc. But to do that, I think that I would need to either Thread.sleep() every time to keep it from flashing, or find a way to clear the console (which might be a bad idea for debugging other things). Newbie question, I know, but how do you actually call classes from the main class, and how do I actually run methods from those? In FRC, is it just public static void main(String[] args) to make a main method in separate classes? All help is appreciated, Thanks :) |
Re: How is this looking?
Quote:
The code obviously isn't a complex part of our program, but it will at least serve as an example of how object oriented programming can make your life really nice. Note that our method names are UpperCamelCase as opposed to the usual lowerCamelCase. I come from a C# background. Code:
package edu.wpi.first.wpilibj.templates;Edit: I should note that RelayManager is one of our own classes; WPILibJ does not have a RelayManager class. ---- Printing stuff through System.out.println should be fine as long as you aren't doing anything completely excessive. Clearing the console will do nothing except free memory on the controlling interface (ex: netbeans). Netconsole is a pretty simple protocol - you send text and the guy on the other side gets that raw text. ---- In our example: RobotMain calls Initialize on the LED Rings manager: LEDRingsManager.Initialize(); RobotMain's teleop and autonomous methods do so too: SetWhiteLedRingEnabled(true); ---- Best wishes, ItzWarty edit: I did end up renaming some methods (the *AllLeds methods) to enable/disable methods for consistency |
| All times are GMT -5. The time now is 22:41. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi