1.0 Why C ? - NO-skcaj/FRC-Cpp-Crash-Course GitHub Wiki
What is a Robot?
Let's start with the basics.
- A robot is a collection of hardware and electronics, organized into subsystems, which interact in order to perform tasks.
- Programming is required to orchestrate all of these components.
- The "brain" of the robot is in the RoboRio, a small computer which connects all the electronics together and runs the software.
Libraries
Now, it would be very difficult to write robot code entirely from scratch.
We need external code; we need libraries. We use one such library to connect to the RoboRio, and some other hardware: WPILib. WPILib is available in both Java and C++ versions.
So, why?
The RoboRio is not a very powerful computer and has limited resources. Therefore, we need to keep code light and efficient, so that the robot is always responsive.
Commonly, Java is used among FRC teams. It's considered easy to learn as the syntax is easily understood and memory management is automatically handled. However, Java is not the best solution for relatively low-memory management situations like the RoboRio.
C++, on the other hand, was built on top of C, which is one of the fastest and most efficient languages.
- It was created in 1985, and is a tried and true low-level language, which runs directly on the hardware, rather than virtual machine like Java's JVM.
- Its syntax is similar to Java, but has a lot more features that give the programmer for flexibility
- The C++ compiler also includes an optimizer which identifies inefficient or unused code and optimizes it to the maximum.
While it does have a higher skill ceiling compared to Java, it is not difficult to get started with.
So in summary,
- We use C++ to maximized our inefficiency and get the most out of the RoboRio's limited resources.
- The flexibility of C++'s syntax and libraries provide us with a lot of options and potential solutions.
- Finally, knowing C++ is a great skill that can serve you well into the future. It is widely used and using it teaches you the fundamentals of programming that applies to all languages.