Our team is planning on using C++ this season but that seems pretty rare. Are any other teams using C++?
Every team I have been on uses C++. 1792 and 7900 both do for sure.
At this point in time you have to ask yourself why is C++ worth it to you? It’s a language that does very little for you and the benefits you get out of using it are what? Execution speed?
If you have a mentor that’s very knowledge in only C++ that’s a fair reason maybe, but I’ve never known a software engineer that knows C++ that also doesn’t know a more modern language that has more safeguards in place to prevent wacky failures. Even our oldest retired mentor that worked at IBM would prefer we didn’t use C++ without good reason. There are just too many great helpful tools and built in features Java or Python now to consider starting out today with C++.
I know it’s still used in industry in some or many places, but as time has gone on I have learned more and more why maybe that wasn’t such a good idea after all. I recently listened to this podcast by one of Java’s founders and it brings up some good points. Java was created because of pointer bugs in C/C++ | James Gosling and Lex Fridman - YouTube
While it’s a shrinking portion of the overall total, usage reporting from 2022 shows 248 teams used C++ last year.
I’m an old C++ programmer (well, C if I’m being totally honest ). Used C++ my first season successfully. Switched to Java and used it ever since… Java is definitely the right answer for us.
We have used C++ since our inception but are switching to Java this year. We initially chose C++ because that happened to be the language the mentors were most comfortable with, and the one that was being taught in the CS class. C++ is just more annoying (memory management and seperate header/implementation files are my 2 biggest complaints), so we decided to go to Java, and the CS curriculum has also moved away from C++ so we’ve lost that reason.
That said, if your mentors/students are more familiar with C++, it’s a totally fine decision to make.
Also to bring up something based on Peter’s comment. There are tons and tons of great code examples to study from Java teams that could help you a lot in learning different approaches to the problems we all have to solve. I find great enjoyment in studying the code of the previous world champions or finalists to see what they do differently.
There are far fewer great examples to follow in C++ I can only think of like one example that I’m certain of in 971.
I really do like Java as a language and I have a lot of experience with it. I am also incredibly proficient in C++ and teaching it. The WPILib C++ library indeed uses exposed pointers but that need not be standard practice. My fear with Java is that I am teaching students a language they are unlikely to use outside of FRC context. Most companies have moved away from Java because before Elon Musk there was Larry Ellison. They can use C++ for Rio, microcontrollers, and vision. They can be sure that any performance issues are in their algorithms and not garbage collection or jitting. Students are being taught JS, C#, and Python in school so both Java and C++ are novel. Don’t try to persuade me to use Python either. I can’t even fathom the debugging challenges that would arise.
This was not really meant to be an indictment of Java. I was hoping that other teams that have also decided to take the C++ route would establish a birds-of-a-feather group.
Citation needed.
As a professional software engineer (now devops if that matters), i can assure you there is no shortage of jobs out there using Java. Many of the startups/smaller companies may be choosing other languages, but java is still used across nearly every industry.
You’ll be fine with whatever. C → Java → Swift → etc. are so related that any skills are 100% transferable. I share your opinion on Python, it is the BASIC of this era. It’s low barrier to entry is very enticing.
And I instantly regret saying 100%.
I should not have made such a blanket statement driven only by my perception, that was in error. Certainly, Kotlin is in the slow process of consuming Android development. FWIW I like Java much more than Kotlin and I think that was a sad development. On the server side, C# has consumed much market share because of MS’s share of the cloud business. Unity has pushed C# to prominence for game and graphics programming as well. C++ remains dominant in resource-constrained and performance-driven areas. I suspect it will continue to be the underlying language for all others but Rust is making a run. I could cite TIOBE and other measures but I never felt they had good SNR.
The impression that modern C++ needs to use exposed pointers more than any other language is just wrong. However, it is a fact that WPILib was written that way and I will have to work with that.
Every team I have been on uses C++. 1792 and 7900 both do for sure.
Do you have established best practices for coding the robot?
1792 has coding standards but I’m not sure about best practices
We’ve been using C++ since 2016 off-season. We found the AP Comp Sci to not be very useful as we had to re-teach them. Modern C++ takes a lot opportunities to shoot yourself in the foot away. That being said we have considered going to Java because our FTC teams use Java, so the transition would be easier. The problem always comes back to there’s a code base that would need to be rewritten.
If you’re starting with a clean slate, I consider:
- what languages are your mentors most comfortable with
- are students coming pre-trained in a language (AP Comp Sci/FTC)
Pick the one that makes sense for your team long-term (not just this season because maybe you have a student who wants to use a particular language or has special skills or you have a parent mentor who isn’t planning on sticking around after their student graduates).
The other thing is if you have someone who really wants to do a particular language, can you run it on a co-processor. If you do custom vision, for instance, you could use python, C++, etc. there and use a different language on the roborio.
I personally prefer references over pointers. It’s annoying having to teach students when to use a * prefix, & prefix, or nothing when passing arguments. The main downside is reference and copy semantics look the same from the caller side. With that said, looking at the function prototype via intellisense isn’t hard. The C++ standard library also prefers references over pointers, so it makes sense to be consistent with that.
We use pointers for mutable arguments (and const ref for immutable arguments) because the google style guide does, but they do that because they want a context cue for what mutates what without having to look at the function declaration or definition in their huge codebase.
https://google.github.io/styleguide/cppguide.html#Inputs_and_Outputs
Our custom style guide that’s based on the Google one has a section that says to avoid pointers in general and prefer references or smart pointers.
I disagree. Straight C remains the lingua franca of shared library code. Even when C++ is used, the primary externs for a library are usually C externs.
And certainly the most resource-constrained devices don’t want the overhead of v-tables and such from C++.
Rust is the language to watch. I predict Rust will make major inroads over the next 5-10 years.
But anyway, functionally for an FRC team, I just don’t think teaching students the finer points of memory allocation, RAII, smart pointers, virtual inheritance and templates is the best use of our limited programming time. The basics of Java, C++ and even Python are the same, we prefer to focus on those transferable skills.
API design is a trade-off space and I realize you have to consider many factors. My concern is over the communication of lifespan and ownership. I prefer explicit ownership and lifetime semantics in all languages for all transitory resources. RAII is a big component of this but so are const and interfaces. I am also struggling with a few other aspects of WPILib especially that command composition invalidates commands and how I could explain lambda ‘this’ capture perils to students. Mostly None of the examples I have come across seem to show a fully composed bot that can run in simulation just as easily as it is run on target hardware.
This is one of the things you have to take into consideration. While i personally love C++ for this most students do not learn it fast enough, and if they don’t learn it during the off season or really quickly during the season you may be out of luck. The best option for skipping college classes is C++. Assuming they do the AP test and score high enough for Java.
I’m not really sure what you’re getting at. In high school I took the Java AP Computer Science class and scored high enough on the test to skip a class which was just the 101 Intro to Algorithmic Design course. The fact that C was the first language I learned had no real bearing on this or that. I personally wouldn’t recommend anyone skip college level C++ courses I know there are people who are exceptional but that’s not the typical case.