What type is a var?

Java 10 introduced “var” where the type of the variable is implied. This leads to some tricky scenarios.

We first learn that “var” can replace the type. That means these two code blocks are equivalent.

int a = 9;
int b = a;
var a = 9;
int b = a;

Ok. So far so good. Now we have this code:

short a = 9;
short b = a;

So we substitute var and the code no longer compiles!

var a = 9;
short b = a;

What’s going on? Well, Java is only using the one line to figure out the type. Since int seems like a reasonable default, variable a is an int. Until of course, we get to the next line and it isn’t.

This would compile, but defeats the purpose of using var. So be careful!

var a = (short) 9;
short b = a;

Calling from an airplane

I wanted to listen to a phone call while I was in the air. I wasn’t sure if it would work, but worth a shot!

I tried Skype, but it dropped the call after just a few tries due to a poor network connection  While the JetBlue wifi isn’t weak (you can watch video on Amazon Prime), you arent supposed to be doing phone calls  so maybe they block it.

My second attempt worked.  I used wifi calling on my iPhone. It is off by default.  What I did:

  • turn on airplane mode (did before plane)
  • connect to jetblue wifi
  • go to flyfi.com in a browser and accept terms on service
  • go back to settings.  Go to the cellular section (you can leave cellular off to do this)
  • go to wifi calling and turn on
  • accept the two prompts

That’s it.  I was able to make a call from my phone.  After the call, I turned off wifi calling since im not familiar with the impact.  And it isnt as if I am running out of minutes!

Nite that you arent supposed to make phonecalls in the air lest it annoy your neighbors.  However, listening to a call is like listening to a podcast.  I’m on mute the whole time  and my headset doesnthsve a mic anyway.

 

 

FRC using VS Code and Eclipse together for WPILIb programming

I’ve tried using VS Code. I enjoy uisng it for things like JavaScript, Python and Markdown. With Java, I feel like I’m hitting my head against the wall. I’m too used to a “full powered IDE” so an editor makes me aware of what I rely on. (I tried IntelliJ as well and that felt productive easily.)

The nice thing is that 2019 FRC projects are “just” gradle projects. So there is no reason I can’t use both VS Code and Eclipse together! VS Code for creation a new project and deploying. Eclipse for virtually everything else.

Creating a project from VS Code

Just like when I was first trying VS Code, creating a WPILib project is easy. Just like the screensteps say!

  1. Click “W” icon in top right
  2. Choose template for a new project
  3. Choose Java
  4. Choose command based project (or whatever you prefer)
  5. Enter directory – this can be the same directory for all projects since they each get their own folder.
  6. Enter project name
  7. Enter team number
  8. Click generate project

Importing the Project in Eclipse

Since the project is just a Gradle project, you can import it into Eclipse

  • File > Import
  • Existing Gradle Project
  • Enter the root directory that the project is in. For example suppose your directory was “frc” and project name was “NewRobotProject”. Then the root directory would be “…/git/frc/NewRobotProject”. In other words, the directory with your build.gradle file.
  • Click Finish
  • Wait a minute or two. The bottom right will say “Synching Gradle project workspace”. It will show the percentage as the import occurs.

Editing in Multiple IDEs/Editors

At this point, you have a normal Eclipse project.   All the features and keyboard shortcuts from Eclipse are there. For example, open a command and click on the super class name (Command.) Press F3 and it takes you right to the source code. Eclipse knows where it is because Gradle told it.

If you edit in multiple tools, you just need to know how to refresh from disk in each one.

In Eclipse, right click the project and choose refresh. (Or click F5)

In VS Code,mouse over the project name and choose the circle refresh arrow.

Deploying the Project from VS Code

Since the VS Code and Eclipse projects are pointing at the same directory, you only have one project. This means you can simply:

  1. Click “W” icon in top right
  2. Choose “Deploy Robot Code” from the menu