Shop Learn
SPIN talking points — Parallax Forums

SPIN talking points

This is NOT intended to be a “blood-in-the-water” thread starter. Far from it. But today I was hit with a question from an educator that I bungled rather badly. Here it is: “Why would we teach SPIN? What does it do better than any of the other languages?”. And I had nothing to say, because I’m just not a SPIN programmer. So I confessed my ignorance promptly, and said I’d put out a call to some forumistas who use it and absolutely love it.

Help me here, lads. I need some talking points.

Btw: The context related to teaching robotics on the P2.


  • Peter JakackiPeter Jakacki Posts: 10,159
    edited 2021-03-02 00:46

    If you want to use a "language", then use the one that is best for you. If you want to use the Propeller, then use the language that is best for you and the Propeller.

    Educators teach languages, although in general, just one language with the assumption that it will be something like a PC that you will be using it with. What we are doing is more Electronics Engineering than Computer Science or IT etc. Embedded systems normally have to run 24/7 without rebooting. Think of traffic lights, think of pacemakers, think of aircraft, and even cars because if the MCU (yes, microcontroller) hiccups even once during high revs it can cause a lot of damage. The list goes on and on while PCs have thousands of times the resources but nowhere near the realtime control and reliability of their humble MCU cousins.

    EDIT: Just saw your btw - yes robotics - we choose an MCU to control that robot not based just on what we prefer but on what gets the job done. The same likewise with the language. If you program in Python on the PC, can you program in Python on the MCU and get the job done and have it run fast enough and reliably?

    “French is the language of love, Italian is the language of music, German is the language of war, English is the language of business, Spanish is the language of prayer etc"

  • Spin is weird.

    What I really like about it and what really drives up the educational aspect is that it is easy to see all the involved code. There are no hidden libraries, just the code you put in.
    Also being able to just do assembler-style data definitions in DAT sections is great.
    On the other hand, most languages have a few warts, yet Spin is a wart that somehow is executable. Any code that'd use a struct in C turns into absolute brap when you write it in Spin. The end in a repeat loop always being inclusive is pretty annoying. Somehow Spin1 and Spin2's operator sets are both obnoxious in their own way. Half the features you want are only in flexspin (preprocessor, access to nested objects, object pointers...) .

    I don't think Spin is really a good language for teaching programming in general, but it is an excellent language to teach low-level microcontroller things to someone who already knows the basics programming.

    As for actual applications, it has some where it shines and some where it just falls apart. See the thing about structs above

  • Cluso99Cluso99 Posts: 17,660
    edited 2021-03-02 02:05

    Here's my modern take on it.

    • A simple high level language to program multicore microcontrollers (micro), namely the Parallax P1 and P2 8-core micros
    • Designed for programming micros, not microcomputers or PC's
    • A modern indented language very much like python
    • Simple and easy to learn
    • Users can get running with just a line or two of code
    • Does not require massive library support like C
    • Has methods to directly control the I/O pins and peripherals on the micro
    • Has methods to directly launch and interact with other cores on the micro
    • Can run interpreted or compiled
    • Can use assembler objects that implement specific functions that make the hardware more versatile and may interface to other hardware to simplify access
    • Supports easy debugging (Chip needs to add to this)
    • Makes it easy to write and mix assembler if desired
    • Teaches the fundamentals of programming micros
  • Dave HeinDave Hein Posts: 6,288
    edited 2021-03-02 03:58

    @JRoark , it is useful to program in Spin on the P1. The chip boots up running the Spin interpreter, so it is essential to know some Spin just to get going on the P1. The Spin language for the P1 is a very compact language that one can learn in a few hours or days. Spin on the P1 can be mastered within a month. Compiled Spin bytecodes produces compact code which works well with the limited amount of RAM available on the P1.

    On the P2, there are fewer reasons to use Spin versus other languages that are available. The Spin2 language that was developed for the P2 has introduced some of the operators and features that are in C and C++. In my view, Spin2 implements a subset of C++. This makes it a more powerful language than Spin1. Since the P2 has 500K of RAM, there is less need for a compact interpreted version of Spin2. Given all of this, I would say it would be better to teach a beginner one of the standard languages instead of Spin2. Eric's FlexProp supports C with a subset of C++. It integrates PASM code almost as well as Spin2 does. So I would recommend FlexProp with C as a teaching tool for the P2.

    And finally, if neither a P1 or a P2 is being used, then there is little reason to consider Spin. It is possible to run Spin on other platforms by using FlexProp to convert it to C/C++, but I don't see much motivation for running Spin on other platforms.

  • Mike GreenMike Green Posts: 23,027
    edited 2021-03-03 03:08

    Spin was developed as a "high-level programming language" for the P1. It compiles into a very compact bytecode form that is normally interpreted (very efficiently) by an interpreter built into the P1's ROM. It "follows in the footsteps" of PL360. Where Spin is partially derived from Python, PL360 was derived from Algol and provided a very efficient, yet easy to understand and use "high-level programming language" for the instruction set of the IBM 360 series of computers. Note: The compiler and an operating system for the IBM 360 were both written in PL360.

    As Dave Hein mentioned, Spin is less useful on the P2 where a variety of programming languages are available in addition to an extended Spin (Spin2) and the P2's resources (memory and speed) are so much greater.

  • lardomlardom Posts: 1,659

    I like Spin because the Propeller makes my projects less expensive. In many cases I can write my own device drivers for multiple devices. Also, don't overlook the benefit of a very active, helpful forum. This forum made the difference for me because in the beginning I got stuck a lot!

  • Many thanks to each of you for giving me this feedback! I knew I could get what I needed here. Discussion (with all of these talking points duly printed) will be had tomorrow.

Sign In or Register to comment.