Scratch Can Even Do Linux Kernel
Written by Nikos Vaggalis   
Monday, 11 July 2022

Is writing a Kernel module in Scratch, the block-based programming language used primarily by kids, possible? Absurd it may be, but yes, it is absolutely possible!

Scratch is the original block-based programming language and still the best known and most widely used. It was invented in 2003 at MIT to make kids' introduction to coding a much smoother experience. That said, the educational value of block versus regular text based languages is highly debated with strong arguments on either side.

I encountered the case made for using text-based languages opinion when reviewing CodeGuppy, a platform that teaches kids (and teens and "creative adults") to code by writing Javascript. 

Visual Blocks languages such as Scratch have their own merits to introduce very young kids to the world of coding. However our opinion is that kids should transition as soon as possible to text based languages. A text based language will help a kids develop not only real coding skills but also other important skills such as spelling. If kids in the 80s were able to learn coding using BASIC (a text based language written in rudimentary editors), we believe that contemporary children can also learn JavaScript using the advanced Codeguppy environment.

Furthermore, a recent official report of research carried out for the UK government found that:

Block-based programming languages can be useful in teaching programming, as they reduce the need to memorise syntax and are easier to use. However, these languages can encourage pupils to develop certain programming habits that are not always helpful. For example, small-scale research from 2011 highlighted 2 habits that ‘are at odds with the accepted practice of computer science’.The first is that these languages encourage a bottom-up approach to programming, which focuses on the blocks of the language and not wider algorithm design. The second is that they may lead to a fine-grained approach to programming that does not use accepted programming constructs; for example, pupils avoiding ‘the use of the most important structures: conditional execution and bounded loops’.This is problematic for pupils in the early stages of learning to program, as they may carry these habits across to other programming languages.

Further research has highlighted that, although block-based languages may help novices to overcome the difficulties with syntax that they can face when learning to program, they do not necessarily help pupils with the semantic and conceptual difficulties. It is therefore important that, if schools use block-based languages, they consider how to design the curriculum to mitigate these potential pitfalls.

On the plus side, block based languages have been found to carry the following benefits:

Since it's visual it's very easy to get started and is highly accessible;you just have to connect visual blocks in a logical way.Then its syntax-free programming takes the clutter out of the way to let students focus on doing something useful while reducing the time to get onto that.

Kid-students aside there's also been attempts to engage block based programming in more sophisticated endeavors.Take for example BlocklySQL, a block-based visual programming tool like Scratch but for SQL.The advantage is that while students use blocks to enter SQL, they can then see, and also export, the auto-generated SQL in order to learn the actual syntax.

The Scratchnative project has gone even further. Taking a Scratch project and converting it to C++ has enabled Scratch to be used for writing kernel modules, which is beyond the ordinary. 

The stated goal of the project is to:

 "Compile scratch3 code to native executables".

In other words, it takes this

and turns it into this

To work with it, first you need to build the program using cmake, and then invoke it as

scratchnative [OPTIONS] [INPUT]

There's also a Python wrapper which can download the Scratch .sb3 project and invoke scratchnative.

To get a more in depth picture, let's download the Scratch Linux Kernel Modules project from the Scratch website, which gets us a "Scratch Linux Kernel Modules.sb3" file. Renaming it to .zip and opening it we find the project's .json file that describes the project, the one that scratchnative works on. With that we dive into the internals of the native scratch format.

Why that is interesting is that we can observe scratch's opcodes used like :

scratch4

Scratchnative currently supports the following opcodes:

event_whenflagclicked
data_setvariableto
data_showvariable
operator_add
operator_substract
operator_multiply
operator_divide
operator_lt
operator_equals
operator_gt
operator_and
operator_or
operator_not
control_if
control_repeat
Extern C functions through procedures_call

The "procedures_call" looks especially interesting...

The dev who built scratchnative even created an operating system, ScratchOS, with it.

While these examples have little practical value, they serve as a strong proof of concept of what is feasible in the modern day of transpilers or cross-compilers.

Is that the breakthrough that low or no-code paradigms have been waiting for in order to hit a higher level of sophistication, getting capable of building previously out of reach application even under the realm of system level programming?

Time will show but scratchnative has certainly opened Pandora's Box...

 scratchlogo

More Information

UK Gov-Research review series: Computing

scratchnative

 scratch-linux-modules

ScratchOS

Scratch Linux Kernel Modules


Related Articles 

Scratch At 15 - Worth Knowing About

Scratch Not To Be Sniffed At!

BlocklySQL - Visual SQL Programming

CodeGuppy - Coding For Kids in Javascript

Scratch Back In Top 20 Of TIOBE Index

Programming Book Choices For Fun

 

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


GitHub Universe AI Announcements - Copilot And Spark
30/10/2024

GitHub has announced several improvements for developers at Universe, its annual conference. Developers will get multi-model Copilot and GitHub Spark, an AI-native tool for building applications in na [ ... ]



TestSprite Announces End-to-End QA Tool
14/11/2024

TestSprite has announced an early access beta program for its end-to-end QA tool, along with $1.5 million pre-seed funding aimed at accelerating product development, expanding the team, and scaling op [ ... ]


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Saturday, 16 July 2022 )