Advantages of each programming language

Hi everyone!

Although it is only 3 days until our first regional, we have yet to solidify what programing language will be used. I was wondering what the advantages of each would be, and availability of teams who would be able to help at the regional. Also any other tips to help our rookie team out would also be great!

:]

Use whatever language you’re most comfortable with. What did you program with while you were developing and testing your robot?

I sincerely hope you’ve already programmed your robot :eek:

There are tons of threads out there on this, but I’ll offer some quick points

  • There’s a fair amount of support at regionals in all three official languages, but LabVIEW seems to take a majority
  • I’m not American, but I believe many American high school comp sci courses (specifically AP level) teach Java
  • Java and C++ have a fair amount of similar syntax
  • SmartDashboard can be extended with Java, default Dashboard can be extended with LabVIEW

EDIT: If you need specific real-time help, PM me

Java and C++ compile and deploy much faster than LabVIEW, or at least that was the case last year. We use C++, and it takes 5-10 seconds to compile and 3 to deploy our code, which really cuts down on programming development time. LabVIEW takes several minutes. That said, LabVIEW is far easier for beginners at programming.

LabVIEW also has some very nice debugging tools.

Disclaimer: That being said, I use C++ for the robot and this year quite a bit of Java for the dashboard and won’t be switching anytime soon.


if(youKnowAnyLanguage) {
    use(theLanguageYouKnow);
} else {
    read([WPILibCookbook](http://firstforge.wpi.edu/sf/go/doc1297));
    if(youUnderstoodAnyOfThat) {
        use(java); // C++ is an option, but it's a bit fiddly.
    } else {
        use(labview);
    }
}

An experienced FRC programmer using Java (and presumably any other language) can get a passable program running in a matter of hours, not days. Nevertheless, start learning and/or coding ASAP!

Care to elaborate?

If I were teaching someone to program and I had a choice as to whether or not I had to explain memory management, I would choose not having to. But it’s not that big of a deal. Besides, every language has its own special problems :).

Memory management is an important topic in Java, the severe memory leak in SmartDashboard this year is a perfect example.

For the purposes of programming a robot in only three days and not testing it until practice day, memory management probably is not their primary concern :stuck_out_tongue:

cierra_shawe, what programming languages are you or those on your team familiar with? If the answer is “none,” I am leaning towards recommending LabVIEW. Not because it is necessarily easier, but because its control structures seem more intuitive than the syntax that comes with Java or C++. If the answer is “some,” then I would go with Java, because its WPIlib implementation seems simpler than the C++ implementation, which makes it easier to learn. But I could be wrong about that, since my team uses Java. At least you will not need to be concerned about memory management if you are unfamiliar with it, unless you are doing computer vision, which I do not recommend if you are testing your robot for the first time in a few days!

I really think this depends on your background. LabVIEW control structures can be intimidating and non-obvious at first. The way a LabVIEW program executes is quite a bit different than a C++/Java program. If a student has a background or enjoys math or algorithms they might find C++/Java more intuitive to them. If a student has a background in electrical they might find LabVIEW more intuitive to them.

I don’t think this is entirely correct, the components inside the WPILib for Java and C++ are abstracted at essentially the exact same level - it’s really about which ever language you’re more comfortable with.

I would argue that starting from scratch, it is easier for a student programmer to use Java (for FRC) than C++ (for FRC).

I cannot count the number of times I have been asked to help a team with C++ and seen problems like the following…


Victor myVictor(1);

myVictor->set(0.0); // Error!


Victor *myVictor = new Victor(1);

myVictor.set(0.0); // Error!


Victor *myVictor;

myVictor->set(0.0); // Error!  You declared, but did not substantiate, your Victor!


void SomeFunction(Victor victor)
{
victor.set(0.0);
}

Victor *myVictor = new Victor(1);

SomeFunction(myVictor); // Error!


void SomeFunction(Victor victor)
{
victor.set(0.0);
}

Victor myVictor(1);

SomeFunction(myVictor); // Still an Error!  You are making a copy of your Victor!

In Java you don’t have to worry about objects on the stack vs. the heap (they are all on the heap), pass by reference vs. pass by value (always pass by value, even if your “value” is itself a reference to an object), memory leaks, C++ name mangling in compiler errors, initializing static class members outside of the class declaration, etc.

Definitely, but this all depends on the commitment and/or the amount of time the student has to learn the language they choose.

<Obligatory Python pitch>

These advantages and disadvantages will differ according to your experience.

Java
Advantages

  • Can be programmed on Windows, Mac and Linux.
  • Forces good programming patterns such as object-orientation.
  • Simpler than C++.
  • No explicit memory management. You don’t have to worry about handling specific memory addresses.
  • It’s the AP Computer Science language, so if any of your students are taking that course, you don’t have to learn a new language.

Disadvantages

  • Incomplete vision tracking APIs.
  • No explicit memory management. (Yes, this is both an advantage and a disadvantage.)

C++
Advantages

  • Executes and compiles much faster than LabVIEW.
  • Has complete vision tracking libraries.
  • Explicit memory management, so you don’t ever have memory leaks if you know what you’re doing.
  • Most popular, so more teams are likely to be able to help you at the competition.

Disadvantages

  • Syntax can be confusing for new programmers.
  • Requires a Windows PC to upload code.

LabVIEW
Advantages

  • Data flow is more intuitive than object-orientation in other languages.
  • Arguably easiest to teach among the three major supported languages.
  • Has access to the most NI vision libraries.
  • Very quick debugging tools. You can probe wires in the code while you’re running it to see what the problem is very quickly.
  • Garbage collection means no explicit memory management.

Disadvantages

  • It’s likely you know text-based languages already, so it could be harder to learn the data flow paradigm.
  • Only runs on Windows PCs.

Python
Advantages

  • You do NOT need to restart the cRIO to upload code, which is great for rapid development.
  • Uses the C++ cRIO image, so you can switch between the two if need be.
  • Simplest syntax of all of them. It’s quite beautiful, and it’s very easy to teach.
  • You can develop on any platform in any IDE.
  • Access to all of Python’s fantastic modules.

Disadvantages

  • Depending on your IDE, a syntax error can go unnoticed, so you have to run tests that execute every line of code.
  • This language is not supported, so you won’t get much help at the competition.

Honestly, write your programs in the language with which you are most comfortable. If you’re caught between two or more, figure out which is the best for what you’re trying to do. LabVIEW is much better for vision tracking than say Java, but if you need Java’s higher level features, go for that.

There are many environments (in the real world) where C and C++ is only choice, favorite or not. For example the Linux kernel and drivers are written in C. The native API for the OS on the robot (VxWorks) is in C, all the other APIs are only a wrapper. Drivers and board support packages for VxWorks are written in C only.

I would advise a student looking to be a computer scientist that Java is a viable choice. If the student is going to be an engineer (especially in embedded systems and robotics), C/C++ is a better choice. C/C++ is not going away any time soon and C++ is not so different from Java that training in Java (which many high schools provide) is not applicable.

What are Oracle and Microsoft plans for Java? Will Java diverge? Will HTML5 and/or C# kill Java? Who knows? LabView and Python are awesome environments but not (works everywhere for everything) primary tools, they are specialized 4GL tools.

Also, (in FRC) using a language your mentor knows is a primary consideration.

HTH

Care to elaborate? What do you define as a computer scientist?

Is this a problem? FRC is a very specialized application.

Seconding this.

A student planning on getting a computer science degree rather than engineering or physics.

I was thinking the skills from FIRST can help in college and in a career.

Both my kids learned Java from an awesome teacher at the high school and C++ on the robotics team. Neither encountered a class in college (both are EEs) where they did not already know the programming language and tools. They both won the junior design contests in college and attribute their success to FIRST experience.

HTH

Truths.

I can’t address Java, but I do have experience with C++.

Thanks to ucpp, you no longer need a Windows PC for any part of the toolchain. If you can get a new gcc and libstdc++ (I’ve had issues with the cross compile for the latter :/) you don’t even need to worry about memory management thanks to std::shared_ptr<T> and std::unique_ptr<T> if you don’t want to.

C++ is also the anarchist’s programming language. It gives you plenty of power, but also the ability to do not-so-good things with that power, and it doesn’t try to stop you like Java (think pointer casts, crazy macros, abusive operator overloading, etc). In the hands of a good programmer, you can do amazing things in C++ incredibly succinctly and efficiently. In the hands of a bad programmer, C++ yields bug-ridden spaghetti code.

Lastly, you can also fall back to the raw VxWorks APIs in C++ if you want very, very easily.

LabVIEW
Advantages

  • Data flow is more intuitive than object-orientation in other languages.
  • Arguably easiest to teach among the three major supported languages.
  • Has access to the most NI vision libraries.
  • Very quick debugging tools. You can probe wires in the code while you’re running it to see what the problem is very quickly.
  • Garbage collection means no explicit memory management.

Disadvantages

  • It’s likely you know text-based languages already, so it could be harder to learn the data flow paradigm.
  • Only runs on Windows PCs.

I would say that for new programmers, LabView encourages some bad design practices. It makes it harder to define new functions (you have to make a new file, add terminals to that file, make a meaningful pixel art icon, etc. just to get a new function), the object orientation for the embedded target is incomplete (which forced us to use structs in C style OO), and those nice wires can quickly become mean when you have lots of connections and you can’t tell what goes where. Yes, I’m biased :smiley: I will say it DOES have the BEST parallel processing of any of the languages though.

Also, since it’s not text based, it’s not as friendly with version control.

Python
Advantages

  • You do NOT need to restart the cRIO to upload code, which is great for rapid development.
  • Uses the C++ cRIO image, so you can switch between the two if need be.
  • Simplest syntax of all of them. It’s quite beautiful, and it’s very easy to teach.
  • You can develop on any platform in any IDE.
  • Access to all of Python’s fantastic modules.

Disadvantages

  • Depending on your IDE, a syntax error can go unnoticed, so you have to run tests that execute every line of code.
  • This language is not supported, so you won’t get much help at the competition.

Python is an AWESOME programming language. That said, those disadvantages are two HUGE disadvantages, so tread carefully.

Honestly, write your programs in the language with which you are most comfortable. If you’re caught between two or more, figure out which is the best for what you’re trying to do. LabVIEW is much better for vision tracking than say Java, but if you need Java’s higher level features, go for that.

+1: The biggest factor in determining which programming language to use is honestly the human factor. If the mentors and students on your team have the most experience with a given language, chances are that that’s the best language to use regardless of the language’s inherent strengths and weaknesses.