Skip to content

Choosing a Language

William Wood edited this page Aug 9, 2019 · 14 revisions

Choosing a Language

Since JISA can be used in a multitude of different languages, it can be quite hard to pick which one to use!

This page will hopefully serve to help you decide out of the three main "target" languages:

  • Java
  • Kotlin
  • Python

Language Overview

Out of the three target languages, Kotlin and Python appear quite similar, with some minor (but key) differences. On the other hand, Java stands out as the more traditional C/C++ style language.

Here's a quick preview of what the same, simple voltage sweep, JISA program looks like in each. This program connects to a Keithley 2450 connected via GPIB at address 25 and performs a voltage sweep from 0 V to 60 V in 61 steps, recording voltage and current at each step after a 500 ms delay.

The result will look like this:

and after running the sweep by pressing the "Run Sweep" button:

Java

import jisa.addresses.GPIBAddress;
import jisa.devices.K2450;
import jisa.devices.SMU;
import jisa.experiment.Col;
import jisa.experiment.ResultList;
import jisa.gui.*;

public class Main {

    private static ResultList results = new ResultList(
            new Col("Voltage", "V"),
            new Col("Current", "A")
    );

    public static void main(String[] args) {

        Table table      = new Table("Table of Results", results);
        Plot  plot       = new Plot("Plot of Results", results, 0, 1);
        Grid  mainWindow = new Grid("Voltage Sweep", table, plot);

        mainWindow.addToolbarButton("Run Sweep", Main::run);
        mainWindow.setExitOnClose(true);
        mainWindow.show();

    }

    private static void run() throws Exception {

        SMU smu;

        try {

            smu = new K2450(new GPIBAddress(25));

        } catch (Exception e) {

            GUI.errorAlert("Could not connect to SMU: " + e.getMessage());
            return;

        }

        try {

            results.clear();

            double[] voltages = Util.makeLinearArray(0, 60, 61);

            smu.turnOn();

            for (double v : voltages) {

                smu.setVoltage(v);
                Util.sleep(500);

                double voltage = smu.getVoltage();
                double current = smu.getCurrent();

                results.addData(voltage, current);

            }

        } catch (Exception e) {

            GUI.errorAlert(e.getMessage());

        } finally {

            smu.turnOff();
            smu.close();

        }

    }

}

Kotlin

import jisa.Util
import jisa.addresses.GPIBAddress
import jisa.devices.K2450
import jisa.devices.SMU
import jisa.experiment.Col
import jisa.experiment.ResultList
import jisa.gui.*

val results = ResultList(
    Col("Voltage", "V"),
    Col("Current", "A")
)

fun main() {

    val table      = Table("Table of Results", results)
    val plot       = Plot("Plot of Results", results, 0, 1)
    val mainWindow = Grid("Voltage Sweep", table, plot)

    mainWindow.addToolbarButton("Run Sweep", ::run)
    mainWindow.setExitOnClose(true)
    mainWindow.show()

}

fun run() {

    val smu: SMU

    try {

        smu = K2450(GPIBAddress(25))

    } catch (e: Exception) {

        GUI.errorAlert("Could not connect to SMU: " + e.message)
        return

    }

    try {

        results.clear()

        val voltages = Util.makeLinearArray(0, 60, 61)

        smu.turnOn()

        for (v in voltages) {

            smu.voltage = v
            Util.sleep(500)

            val voltage = smu.voltage
            val current = smu.current

            results.addData(voltage, current)

        }

    } catch (e: Exception) {

        GUI.errorAlert(e.message)

    } finally {

        smu.turnOff()
        smu.close()

    }

}

Python

from jisa import Util
from jisa.addresses import GPIBAddress
from jisa.devices import K2450
from jisa.experiment import ResultList, Col
from jisa.gui import GUI, Table, Plot, Grid
from java.lang import Exception

results = ResultList([
    Col("Voltage", "V"),
    Col("Current", "A")
])


def main():

    table      = Table("Table of Results", results)
    plot       = Plot("Plot of Results", results, 0, 1)
    mainWindow = Grid("Voltage Sweep", [table, plot])

    mainWindow.addToolbarButton("Run Sweep", run)
    mainWindow.setExitOnClose(True)
    mainWindow.show()


def run():

    try:

        smu = K2450(GPIBAddress(25))

    except Exception as e:

        GUI.errorAlert("Could not connect to SMU " + e.getMessage())
        return

    try:

        results.clear()

        voltages = Util.makeLinearArray(0, 60, 61)

        smu.turnOn()

        for v in voltages:

            smu.setVoltage(v)
            Util.sleep(500)

            voltage = smu.getVoltage()
            current = smu.getCurrent()

            results.addData(voltage, current)



    except Exception as e:

        GUI.errorAlert(e.getMessage())

    finally:

        smu.turnOff()
        smu.close()


main()

As a general overview:

  • If you are used to traditional languages like C/C++, then you will want to use Java (it's also a very employable skill...).
  • If you are looking to extend the JISA library itself you MUST use Java (for my sanity if nothing else).
  • If you are used to more modern-style languages (like Python), you probably want Kotlin.
  • You probably only want Python if you're already very used to it since it's more of a pain to set-up for using JISA than Kotlin (and comes with a raft of draw-backs compared to Kotlin despite being very similar).
  • Performance hits will become quite noticeable in Python if you intend to do anything with large amounts of data.
  • If I catch you writing a JISA program in MATLAB I will get you arrested for high treason.

Java

Attribute Pros Cons
Verbose Makes it easier to follow the logic of a program Makes your code longer to write
Statically Typed Makes it easy to spot where a variable is first declared and what type it is, also faster to run Extra words to write and think about, generics can be confusing
Traditional Syntax Tried and tested, very standard and similar to other languages, robust Can look scary since it looks like C++
Input/Output Streams Gives more precise control over terminal input and output Slightly more complex to use
Strong Object Orientation Forces you into good practices, leads to well organised code Can seem a bit much for simpler programs
Compiled Runs fast and can be compiled into a single executable .jar file Code needs to be compiled when changed

Kotlin

Attribute Pros Cons
Concise Makes it quicker to write programs Can make it harder to follow the logic of your code
Static Inferred Typing Fast to run, still easy to spot declarations but removes need to remember type names Harder to tell which variable is of what type
Simplified Traditional Syntax Very standard and similar to other tried and tested languages but more human readable than most None really, unless you are conditioned to expect Python syntax
Input/Output Methods + Streams Far simpler to use terminal input/output than in Java but you can also use streams like in Java if you wish None, best of both worlds really.
Fair Object Orientation Forces you into good practices, leads to well organised code but doesn't require your main method to be inside a class None really
Compiled or Interpreted Your choice, you can compile to run fast or write Kotlin scripts that run in an interpreter None, you can choose whatever best suits your needs

Python

Attribute Pros Cons
Concise Makes it quicker to write programs Can make it harder to follow the logic of your code
Dynamically Typed No need to explicitly declare variables Hard to see where variables are first declared, what type they are and gives rise to scoping issues
Reinvented Syntax Designed to be human readable, commonly used in scientific community Completely different from almost all other languages, sacrifices functionality, can become messy easily
Input/Output Methods Far simpler to use terminal input/output than in Java Less control and precision
Weak Object Orientation Lets you do it your way(tm) Missing some very useful OO features, often leads to huge messes of code without proper discipline
Interpreted No compilation needed, allows straight-forward interactive shell usage Slow and memory-hungry execution, up to roughly 30x slower than the likes of Java/Kotlin

MATLAB

Attribute Pros Cons
Don't Don't Don't
Clone this wiki locally