Conditions | 5 |
Total Lines | 67 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | |||
54 | public void robotInit() { |
||
55 | /// instantiate bot chooser |
||
56 | botChooser = new SendableChooser<>(); |
||
57 | botChooser.addDefault(Bot.TEUFELSKIND.toString(), Bot.TEUFELSKIND); |
||
58 | botChooser.addObject(Bot.OOF.toString(), Bot.OOF); |
||
59 | SmartDashboard.putData("Bot", botChooser); |
||
60 | |||
61 | if (botChooser.getSelected() != null){ |
||
62 | bot = botChooser.getSelected(); |
||
63 | } else { |
||
64 | bot = Bot.OOF; |
||
65 | } |
||
66 | |||
67 | DriverStation.reportWarning("ROBOT STARTED; GOOD LUCK", false); |
||
68 | /// instantiate subsystems |
||
69 | // SUB_ARDUINO = new SubsystemArduino(); |
||
70 | SUB_MANIPULATOR = new SubsystemManipulator(); |
||
71 | SUB_CLAMP = new SubsystemClamp(); |
||
72 | SUB_COMPRESSOR = new SubsystemCompressor(); |
||
73 | SUB_DRIVE = new SubsystemDrive(); |
||
74 | |||
75 | SUB_DRIVE.pid.setPIDF(.5, 0, 0, 0); |
||
76 | |||
77 | SUB_HOOK = new SubsystemHook(); |
||
78 | SUB_MAST = new SubsystemMast(); |
||
79 | vision = new Vision(); |
||
80 | |||
81 | /// instantiate operator interface |
||
82 | oi = new OI(); |
||
83 | |||
84 | |||
85 | |||
86 | /// instantiate drivetrain chooser |
||
87 | driveChooser = new SendableChooser<>(); |
||
88 | driveChooser.addDefault(Drivetrain.ROCKET_LEAGUE.toString(), Drivetrain.ROCKET_LEAGUE); // set default to RL drive |
||
89 | for(int i = 1; i < Drivetrain.values().length; i++) { |
||
90 | driveChooser.addObject(Drivetrain.values()[i].toString(), Drivetrain.values()[i]); } // add each drivetrain enum value to chooser |
||
91 | SmartDashboard.putData("Drivetrain", driveChooser); //display the chooser on the dash |
||
92 | |||
93 | /// instantiate position chooser |
||
94 | positionChooser = new SendableChooser<>(); |
||
95 | positionChooser.addDefault(Position.CENTER.toString(), Position.CENTER); // set default to center |
||
96 | for(int i = 1; i < Position.values().length; i++) { |
||
97 | positionChooser.addObject(Position.values()[i].toString(), Position.values()[i]); } // add each position enum value to chooser |
||
98 | SmartDashboard.putData("Position", positionChooser); //display the chooser on the dash |
||
99 | |||
100 | /// instantiate goal chooser |
||
101 | goalChooser = new SendableChooser<>(); |
||
102 | goalChooser.addDefault(Goal.NOTHING.toString(), Goal.NOTHING); // set default to nothing |
||
103 | for(int i = 1; i < Goal.values().length; i++) { |
||
104 | goalChooser.addObject(Goal.values()[i].toString(), Goal.values()[i]); } // add each autonomous goal to chooser |
||
105 | SmartDashboard.putData("Goal", goalChooser); //display the chooser on the dash |
||
106 | |||
107 | /// instantiate bot chooser |
||
108 | botChooser = new SendableChooser<>(); |
||
109 | botChooser.addDefault(Bot.TEUFELSKIND.toString(), Bot.TEUFELSKIND); |
||
110 | botChooser.addObject(Bot.OOF.toString(), Bot.OOF); |
||
111 | SmartDashboard.putData("Bot", botChooser); |
||
112 | |||
113 | |||
114 | |||
115 | /// instantiate cameras |
||
116 | vision.startScrewCameraThread(); |
||
117 | vision.startFrameCameraThread(); |
||
118 | |||
119 | SmartDashboard.putData("Sub_Drive", SUB_DRIVE); |
||
120 | DriverStation.reportWarning("SUBSYSTEMS, CHOOSERS INSTANTIATED", false); |
||
121 | } |
||
179 |
See this CWE advisory on why this is a security issue.