Java or C++

I’m debating over whether our team should switch from C++ to Java or stick with C++. I’ve looked over some of the forums about it and I didn’t see much help. I’m looking to whether C++ is more beneficial or Java is more beneficial in relation to it’s simplicity, and control.

I’ve done some research and found out that C++ has the ability to pass over variables and Java doesn’t. I’m not sure but just asking around to see what everyone knows.

I also noticed there’s a large part in my community, Central Valley, switching over to Java large part to the new AP classes teaching Java, is there any other reason why the support of Java?

Our team has used all three programming languages since we started in 2008.

C++ was ok, but there were quite a few bugs and the documentation was really bad. We switched to LabView last year because one of the teams we partner with recommended it, but they switched to Java that year.

This year we had a large intake of new software mentors (Google became one of our sponsors…) and students so we revisited what language to use. After our experiences with the other two, we landed on Java. Our code this year was the best we’ve ever had, and I think we’ll be a “Java team” for awhile now.

If there are a lot of teams in your area who use Java, switching might be a good choice so you can draw on their expertise.

During my first year with our FRC team, we switched to Java, primarily because that was the language taught in our high school programming classes. I was primarily a C/C++ guy beforehand, but for our purposes in robotics, I found Java to be a very good choice. I didn’t notice any performance problems (outside of trying to do image processing on the cRio, which is another issue entirely), cross-platform development was nice (I’m a Linux user), and not having to deal with explicit memory management made things less complicated.

I wholeheartedly recommend Java, but I think the most important factors in a decision like this should be prior student and mentor knowledge; if you don’t have someone who knows the language already, programming a whole robot with it can be quite a difficult task.

In terms of what makes the best robot-- they are all just tools. They all have there advantages & disadvantages. I would go with the one that you have the best local support. I get the impression that the Java & AP sort of works in reverse. Coding the robot teaches way more about under the hood aspects that you learn in AP.

We switched from c++ to java this year. We really like java because of it’s simplicity and documentation

I’m not entirely sure what you mean by this, but I think you’re talking about “Pass by reference” versus “Pass by value”. In short, Pass by reference means that changes made to a variable passed into a function are reflected in the calling function, while Pass by value means they aren’t. Java, by default, uses Pass by Reference (although you can easily make a new object to make it work the same as Pass by Value), while C++ uses Pass by value (Although with pointers C++ can do Pass by Reference). In short, both languages are capable of supporting the same behavior, they just take different approaches to it.

The three programming languages are supposed to be equally capable for FRC, and from what I’ve seen teams do in the different languages, I’d say they are. The choice really comes down to what you’ll have the most support with. If you have mentors that know one of the languages, go with that. If your school teaches one of the languages, go with that. If you have local support from other teams for one of the languages, go with that.

im probably not the best person to be discussing this topic, partly because programing is no where near my topabilities, our team uses C++ and i dont think we plan on changing it, because we are comfortable with it and it works.

I would counter. (at least now) almost everything is documented using Doxygen, and you can easily generate the documentation yourself from the source code.

As far as with bugs, the Java and C++ implementations of WPILib track rather closely now so bugs should be similar.

If you mean as to build toolchain, I can’t speak to that as my team has used ucpp for the past two years.

If anything, my anecdotal experience is that LabVIEW broke more often - though the debugger was awesome when it worked, halfway through competition (logomotion). It also bricked without explanation once - we had to do a full reformat in order to get everything back up and running. The technical staff at the regional couldn’t figure out why in either case also. The whole affair was rather strange.

That’s just my anecdotal experience though, and I must admit to be fair that I am not unbiased in my opinions :slight_smile:

As far as I’m concerned, the single greatest factor in favor of Java or C++ is that version control is much easier than with LV. That’s saved my team on a number of occasions. I also contend that distributed systems are nicer because they let you have full access to history and make commits at the competition without an internet connection to your host.

I think the main advantage of JAVA over C++ is that the development tools are free unlike C++ and LabView. This makes things way easier if you have a programming team.

Searching is your friend.

Shameless plugs: http://www.chiefdelphi.com/forums/showthread.php?t=110720 and http://www.chiefdelphi.com/forums/showthread.php?t=116921

It’s time for me to be the pedantic guy: Java uses pass by value for primitive types and by reference for all others. This is not merely a default: it cannot be changed (The ugly work-around of the caller copying arguments does work, of course). Also, for passing references in C++, I recommend: the language feature called “references”

On a different note, it’s interesting to hear that the Java and C++ WPIlib impelemtations are equally buggy. I had assumed that the C++ one must be worse because the code looks like it was written by someone who wanted to be writing Java.

Okay thankyou everyone, this is quite alot of input. Our team has decided to move to Java, but also continue some C++ so that we can continue to compare and study the differences.

I swear, I’m not trying to be the LabVIEW guy in the “Java or C++” thread, but I just wanted to comment on a few things.

I hope no one is paying money for either Wind River tools or LabVIEW tools. Teams are given as many copies as can be stuffed on the hard drives. Yes, in industry and in academia, people pay money for those products. That is how I make my house payments. Through the affiliates program, I know Bjarne Stroustrup and the A&M portion of the gcc distro guys and they live in houses too. I guess my point is that I don’t see the connection between someone else paying money for something that you get for free and which tool helps your students learn to program a robot.

As for source code control, it is an important aspect of SW development. LV has plug-ins for perforce and a few other SCC tools, but not for all of the recent free ones I see mentioned on CD. It looks like https://github.com/joerg/LabViewGitEnv explains how to accomplish a GIT integration, and I’m sure there are similar tutorials on other sites.

On the original topic? C++ is a very powerful language, but that power makes it complex and able to make mistakes that are very difficult to debug. The other languages aren no slouches in that regard, but C++ definitely takes the cake. For an introductory language, I’d also choose Java over C++. And if you want to learn a language that takes a different approach, you might give that other one a try.

Greg McKaskle

OK, now it’s my turn to be pedantic. Java is entirely pass by value in all cases. The thing is, that all objects are really pointers, so it appears to be pass by reference. So, if actually use the equals operator with an object in a function, the whole pass by value-ness will rear its head. Though a lot of these things don’t work in C++ either, the syntax of C++ makes it so that these things don’t make conceptual sense in the cases that they do not work, whereas a java programer could reasonably expect some of these cases to work since they are conceptually congruent…

BUT THERE ARE NO POINTERS IN JAVA.

And this is why I never grok Java. I don’t like drinking kool-aid. Learned enough to get by in class and moved on…

I hope no one is paying money for either Wind River tools or LabVIEW tools. Teams are given as many copies as can be stuffed on the hard drives. Yes, in industry and in academia, people pay money for those products. That is how I make my house payments. Through the affiliates program, I know Bjarne Stroustrup and the A&M portion of the gcc distro guys and they live in houses too. I guess my point is that I don’t see the connection between someone else paying money for something that you get for free and which tool helps your students learn to program a robot.

We all like living in houses - I don’t blame you or anyone for that. For me the larger concern is portability. Also, even closed source linux tools don’t integrate as well 99% of the time for me - they rarely integrate with the package manager (a rare exception being google chrome), for example. I don’t like dealing with installer programs or license managers. I like writing code. Anything that gets in my way of writing code in the environment I like to do it in, therefore, I don’t like.

I also didn’t say that LV didn’t work with VC. But it doesn’t work as well for me. If I’m managing my code on github, it’s a lot easier for me to get a pull request, look at the plain text diffs, and automatically merge it in using a grand total of about 3 clicks and a quick mental compile than manually fetching, comparing using one tool, merging using another, and then manually pushing. It really sounds trivial but its the small frustrations in a smooth workflow that annoy me. It does work, though. We used git with LV three years ago and managed to make it work. It didn’t erase the fact though that it felt like a suboptimal situation.

On a completely anecdotal note, I’ve found it harder to convince inexperienced programmers to split their LV code into several subVIs than to split Java/C++ code into several functions. I don’t know why this is. Good chance it’s just my sample.

I did not mean to turn this post into a diatribe… sorry all. Really, I believe LabVIEW is a good language. It’s great for rapid prototyping and throwing together a quick custom dashboard. It’s just not the tool I prefer to use, and deep down it’s really just because I don’t have as much experience with it :wink:

On a different note, it’s interesting to hear that the Java and C++ WPIlib impelemtations are equally buggy. I had assumed that the C++ one must be worse because the code looks like it was written by someone who wanted to be writing Java.

I recant my previous statement. Currently on FirstForge Java has 17 open bugs while C++ has 26. This is significant, though it is by no means scientific (are C++ users more likely to find and/or report bugs than Java users?).

Now you guys are just nitpicking how Java handles objects :stuck_out_tongue: Personally, I find dealing with pointers and memory in C++ to be more of an issue and more error-prone (generally speaking) than anything in Java! But then, you should keep in mind I haven’t done much in C++ since college…

Using a language your mentors (or teachers) can teach you. Java and C++ each have advantages and disadvantages but nothing is more important, in my opinion, than access to an expert with your chosen language.

HTH

Agreed.

Java and C++ both have their advantages and disadvantages. However, the disadvantages are generally outweighed by having someone with the knowledge and experience to deal with them. A lack of understanding the details even with a simpler-to-use system/language will become a huge time-sink when trying to get past the basic implementation.

What areas have you found c++ documentation lacking compared to java? My impression is that they are similar.

Can I use that quote out of context Greg? :slight_smile:

But back to the topic.

It’s a bit like asking “which human language should I learn to speak*?”
All of them have roughly the same expressive power and can be used to communicate the same ideas, but which is right for you depends on the community you are part of and your previous experience.

Which human languages correspond to C++, Java & Labview is left as an exercise for the more comedically talented among us.

  • note I did not say “learn to write”