IntelliJ IDEA FRC Plugin Update Released for 2023 Season

This is interesting. My team is currently in talks about coding related choices, and our current discussion is between Java with CTRE and WPILib and Visual Studio Code or
Kotlin with CTRE and WPILib and IntelliJ IDEA.

The argument for Java is that it is easier to get help from CSA’s at events with Java, as they are all familiar with that and Kotlin is newer. I had not thought about remote debugging sessions to work with either setup. Has there been progress made on this, and if not, how big of an issue is that?

You can also use Java with InteliJ!

2 Likes

Kotlin will make it harder for the CSAs to help you with your code but it won’t make it harder to help you with WPILib, if that makes any sense. The library works the same in Kotlin as it does in Java.

I prefer Kotlin as a language to Java and think it lends itself very well to command and trigger composition.

1 Like

As a CSA (among other things) I concur with this. I suspect most Java-capable CSAs would do a quick double take on the structural changes Java–>Kotlin and then move on to the issue. I suspect while most Java CSAs can help find your Kotlin/WPILib issue, they may just tell you generically how to fix it and leave the syntax to you rather than struggle with the language translation to Kotlin.

2 Likes

Attaching the IntelliJ IDEA debugger to the robot to debug Java and/or Kotlin works fine, and has for many years. I have done it numerous times. I merely need to get the process documented. (Unfortunately an elderly parent entering home hospice has dominated my time the past 6 weeks. So I’ve not had a chance to get to documenting this. And as mentioned above, I know I need to do better at documenting my plugin. Just never enough time in the day.)

Here are the rough instructions…
If you create a robot project in IntelliJ IDEA, or go to Tools > FRC > Create Run/Debug Configurations > Create Build, Deploy and Debugging Run/Debug Configurations in a robot project created externally, you will have run/debug configurations for debugging the robot:

Basically you:

  1. Run one of the “Build & Deploy Robot for debugging” Run/Debug Configurations (the one just runs the clean task before the build & deploy)
  2. As the above finishes, you will attach the debugger via the next step. This is the part I need to refresh my memory on by doing this on a roboRIO. I can’t recall if the deploy pauses with a “waiting for debugger to attach” message, or if it continues with a “ready for debugger attachment” message.
  3. Then run, via the debug button, one of the “Debug Robot via X” Run/Debug Configurations depending on how you are attached to the robot. (“IP” is for either Ethernet tether or WiFi)
    image

As others have mentioned, you can code Java and/or Kotlin with IntelliJ IDEA. You could even code Kotlin with VS Code. There is a Kotlin extension for VS Code. I just don’t know how good (or bad) an experience it is. Kotlin coding in IntelliJ IDEA will be a much better experience. And I would argue coding Java in IntelliJ IDEA will be a better experience. But I’ve been using IntelliJ IDEA since 2003 (so 21 years now) and am thus pretty devoted to IntelliJ IDEA. (I started my IntelliJ IDEA plugin when I started mentoring because I didn’t want to use NetBean (at the time), and later Eclipse, and finally VS Code to write robot code. I’ve been using IntelliJ IDEA the entire time.)

I also love Kotlin. I worked solely in Java since it’s release in 1995. And know its ecosystem extremely well. I tried Groovy and Scala when they came out, and didn’t care for them. Then I tried Kotlin when it came out and fell in love with it instantly. I’ve began using it on the side for personal projects since it was released in beta in mid 2010. Then immediately began using it professionally and for our robots when Kotlin 1.0 was released in Feb 2016. (My company now does 100% of our coding in Kotlin.) Initially in our robots in 2016 I used it for some utility classes. in 2017 our robot was about 40-50% Kotlin, and 50-60% Java. For 2018 and beyond, we’ve been 100% (or at least 95% plus) Kotlin. Kotlin has phenomenal interoperability with Java. So you could start by writing just some code in Kotlin, such as Unit Tests and Utilities. The next year maybe write 1 or 2 subsystems in Kotlin, or maybe the commands. Or just go for it and start using Kotlin fully.

I personally think Kotlin is a much easier language to teach for a variety of reasons. Since switching to it, I can get students with no programming experience writing and understanding code much quicker than when we used Java.

I also agree with @Oblarg and @bdaroz comments… you can still get help from CSAs on “what you need to do”, then you just write it in Kotlin. Heck, the CSA can even show you in Java, and then you can convert it. (If you are not aware, you can convert any Java Class to Kotlin in IntelliJ IDEA via Ctrl+Alt+Shift+K, and if you copy Java code, say from an online code example snippet, and go to paste it into a Kotlin code, IntelliJ IDEA will convert the Java code to Kotlin.

Agree 1 Million percent. Writing command based robots in Kotlin is so elegant. For example, creating a gamepad and adding commands:

CommandXboxController(codriverPort).apply {
    povUp().onTrue(ClimberStartDecentCommand())
    povDown().onTrue(ClimberStartClimbCommand())
    povLeft().onTrue(ClimberStopCommand())
    a().onTrue(StartIntakeCommand())
    // etc
}

Anyways, I’d encourage you to go for it with Kotlin. More and more teams are moving to it. And usage of my IntelliJ IDEA plugin grows each year. I’m currently at a little over 1,200 unique users based on JetBrains Marketplace analytics. So you will be in good company.

7 Likes

Do you know some Kotlin projects that use modern command-based well?

I may be biased(*), but I think 449 did a good job of it this year:

(*) I actually don’t have that much to do with 449’s code these days.

1 Like

We made the command decorator methods (like alongWith and andThen) be infix functions, so now they no longer looks like functions and are just words that describe what the command does.

Look at collectCommand, for example: Crescendo2024/src/main/kotlin/frc/robot/commands/NoteHandlingCommands.kt at 2e1495e84f9f874645642723af692d5d0a5bd0d7 · Hamosad1657/Crescendo2024 · GitHub

1 Like

A lot of Kotlin sugars are helpful here, too. The trailing lambda sugar can combine w/ val syntax for command factories really nicely:

class FooSubsystem() : Subsystem() {
  ...
  val fooCommand
    get() = run {
      // this is a lambda body!
    }.until {
      // so is this!
    }
}

For newer programmers this can help get over the “alienness” of the arrow function syntax.

1 Like

We use kotlin, i can’t speak to the quality of our usage however.