Coding in jython

Have any teams tried to code the FRC robot in jython?

I was thinking about trying this to help explain coding to the new programmers, but I don’t know if it works. Has anyone tried it?

I would be interested in hearing about this as well. It sounds like it could work - supposedly jython compiles directly to Java bytecode, and a JVM won’t be able to tell the difference. But I wonder if our use of Java ME and CLDC affects that.

Not that I’d use it, personally; I don’t see how Python makes “explaining coding” to new programmers easier than any other language, contrary to popular opinion.

THink, no brackets, no semicolins, no parentheses unless they are req’d, its easier

I’ve been working on a Jython interpreter port (alongside a rhino JS interpreter)…
It’s a little tricky however, because these things are all written for Java 5/6 and have to be retrowoven/hacked back to be 1.3 compliant…
The bigger issue, however, is getting java bindings working(which you will need if you want to use anything in WPILibJ) because J2ME does not allow dynamic class loading…something both rhino and jython rely on in their java bindings.
Thus, my rhino intepreter works but it pretty much justs prints stuff for the moment…Jython is a bit more tricky to work with.

If you’re trying to explain code to new programmers, shouldn’t you use a language that is well-supported?

In other words, I don’t know many FIRST teams (or anybody, really) using Jython. What if they have problems?

Getting new programmers to remember their brackets, semicolons, and parentheses is by far the easiest part of teaching them to be good programmers. The difficult is getting them to use simple and effective design patterns, which Python (/Jython) does not do a good job of encouraging, IMO.

Python is very close to pseudo-code (and if that means that we get close-to-pseudo-code-but-actually-work-examples in Python instead of BASIC, I’m not complaining). This makes it fairly easy to understand what the code is doing, without having a ton of experience with coding.

However, I do feel that using high-level languages and not having to deal with the low-level stuff is something you can only do properly after you are capable of actually doing that stuff yourself.

I’d say that the rationale for python should not be that it is syntatically easier for students to learn, but more that as a dynamically typed and fully interpreted language it allows advanced developers to utilize some neat python features…

I can’t say i don’t agree. I did port this year’s code to jython:

from edu.wpi.first.wpilibj import SimpleRobot, Timer
from com.shadowh511.mayor.inputs import Xbox, Switch, DomBoard, GreenAsia
from com.shadowh511.mayor.outputs import Driver, FiringThread

class RobotMain(SimpleRobot):
    """
    This is the main robot class, hopefully the robot is smart enough to load
    it :S
    """
    def __init__ (self):
        """
        Makes the robot class variables
        """
        self.driver = Xbox(1)
        self.gunner = GreenAsia(2)
        self.motors = Driver(1,2,3,4,True)
        self.firing = FiringThread()
        self.switch = Switch(4,4)
        self.DomBoard = DomBoard()
        self.watchDog = SimpleRobot.getWatchdog()

    def robotInit(self):
        self.watchDog.setEnabled(False)
        self.watchDog.kill()

    def autonomous(self):
        robotInit()
        print "Autonomous Starting"
        balls = 2

        while SimpleRobot.isEnabled() and balls > 0:
            if switch.ternaryGet():
                self.motors.stop()
                self.firing.autoFire()
                Timer.delay(3)
                balls -=1
            else:
                self.motors.drive(0.5)

        self.motors.stop()

    def operatorControl(self):
        robotInit()
        print "Starting Teleop"

        while SimpleRobot.isEnabled():
            self.motors.mecanumDrive(driver)

            if self.gunner.getCross():
                self.firing.autoFire()
            elif self.gunner.getSquare():
                self.firing.autoTap()