10 votes

A version of Python called "Snek" targeting embedded processors

7 comments

  1. [4]
    skybrian
    Link
    From reading the manual, it seems you get functions and a few useful datatypes. It looks better than BASIC was in the 80's and is probably good for the classroom experience it was designed for,...

    From reading the manual, it seems you get functions and a few useful datatypes. It looks better than BASIC was in the 80's and is probably good for the classroom experience it was designed for, where there isn't enough time to go into much depth anyway.

    Since I'm writing code for microcontrollers now, sometimes I think about what a small language designed for embedded programming might look like. I think it would be defined in terms of trees or maybe graphs of statically defined objects that are initialized when the board is reset. There would be little runtime memory allocation needed (objects not passed as parameters have no lifecycle; they live forever), but lots of flexibility in defining the graph and its initial state at "compile time". But as a developer you could tinker with the compile-time structure interactively using "hot reload". (Influences: Inform 7, VCV Rack.)

    6 votes
    1. [3]
      just_a_salmon
      Link Parent
      I’m not a microcontroller programmer, but the static objects initialized at startup reminds me of Smalltalk.

      I’m not a microcontroller programmer, but the static objects initialized at startup reminds me of Smalltalk.

      1. [2]
        skybrian
        Link Parent
        In Smalltalk everything is mutable. But maybe you're talking about saving and restoring the object graph from a snapshot? I guess could be some similarities with programming a device.

        In Smalltalk everything is mutable. But maybe you're talking about saving and restoring the object graph from a snapshot? I guess could be some similarities with programming a device.

        1. just_a_salmon
          Link Parent
          You’re right; I thought about saving and restoring the program state.

          You’re right; I thought about saving and restoring the program state.

          1 vote
  2. [3]
    enticeing
    Link
    I'm curious what exactly the differences are between this and CircuitPython. Snek seems a bit more pared down to me. Has someone written an article comparing them?

    I'm curious what exactly the differences are between this and CircuitPython. Snek seems a bit more pared down to me. Has someone written an article comparing them?

    2 votes
    1. [2]
      Diff
      (edited )
      Link Parent
      The name, and Snek is much slimmer according to the article: And with different design goals in mind. Snek's goal is to be Python as simple as BASIC, no need to learn complex background to get...

      The name, and Snek is much slimmer according to the article:

      There are other options for implementations of Python that run on small devices: MicroPython and its descendant, CircuitPython. ... Those two are "fantastic", he said, but they are much larger than Snek. CircuitPython (256KB) is roughly four times the size of Snek (64KB) for the same board, he said.

      And with different design goals in mind. Snek's goal is to be Python as simple as BASIC, no need to learn complex background to get started tinkering:

      He showed a CircuitPython version of the code to turn an LED on and off based on a switch, which was nearly as complex as an Arduino version, though it is written in a language with much simpler syntax. There are various imports required along with configuration of the switch and LED, but the six-line Snek version dispenses with all of that. CircuitPython is as capable as the full Arduino, but that also means he has to teach a bunch of preliminaries before the students can actually make the robot do anything. Snek internally sets up and configures the device so that students can do things with it right away, including directly from the interaction window.

      Seems like lots of design decisions are based on accessibility for someone who doesn't know programming yet, like the choice to get rid of integers entirely:

      Instead of having an integer type, which is actually an unnatural thing to students of that age since they have already learned about fractions and decimal numbers, Snek only has 32-bit floating point numbers.

      6 votes