Over a million developers have joined DZone.

Creating an Operating System With 5 Lines of Code

DZone's Guide to

Creating an Operating System With 5 Lines of Code

This developer has created an OS that only requires very little code. Don't believe it? Read on to learn more.

· Web Dev Zone ·
Free Resource

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

A modularized operating system has a single job: dynamically load up and initialize its installed modules, period! Everything else your operating system does, beyond this simple function, makes it "bloatware" and monolithic in its design. Below are 5 lines of code. This is the smallest possible amount of Hyperlambda that allows you to do just that.


The above code, first of all, lists all folders inside of your "/modules/" directory. Then it lists each file inside of those folders with the name "startup.hl," implying an initialization file. Then it loads these files, and evaluates them or "executes" these files.

This allows me to literally x-copy a new "module" or "component" to my operating system's "/modules/" folder, put it into my "/modules/" folder, and immediately have it functioning and collaborating with all other components in my system. The startup time (think "boot time") for an average installation of my operating system is some few hundreds of milliseconds.

Since the core feature of Hyperlambda is to dynamically invoke functionality, by referencing "functions" (Active Events actually) as simple strings, this creates no static dependencies between my modules, yet still allowing all of my modules to invoke functionality in any of the other modules. It also allows me to exchange any single "function" with any other "function" by simply creating a "function" with the same name, and have my new functionality easily replace any existing implementation, without breaking existing usage. I can even change my "functions" signatures, often times also their return values, and (obviously) their entire implementation, without breaking existing components with this technique. Effectively allowing me to apply "polymorphism" on functions, without any inheritance, virtual functions, interfaces, or OOP at all.

The above code actually *is* my operating system. Don't believe me? Check it out for yourself. Now I have three additional lines of code in my current implementation. This is just because I often times want to use the "Micro" and "Desktop" modules inside of the initialization logic of my other components, to keep my code "DRY." However, I can still delete or "uninstall" both the "Desktop" and the "Micro" module, without breaking my operating system's core code, since this will result in the equivalent of a "function() {}" function invocation (empty function invocation). In fact, I can also use the same code to create a web operating system and a desktop operating system. It simply doesn't care. And, in theory, I could exchange two simple C# assemblies, and have all my existing Hyperlambda code create WinForms apps instead. Or Xamarin apps for that matter. So I could (in theory) use the same code base for my WinForms apps, and my web apps. Though, I have to confess, I don't recommend doing this. Just because something is possible, doesn't imply we should do it - which is kind of the philosophy of this article ...

The file I linked to above, dynamically loads up all of my modules, and initializes these. What each module actually does from an individual point of view is irrelevant. Some of my modules create Ajax Widgets, such as a modal window, tree view controls, menu controls, etc. Other modules are entire apps and suites of applications by themselves. And creating your own module simply requires you to create a folder, and a single file named "startup.hl." This allows you to extend your operating system, kind of the way we used to create libraries or COM modules before. Below is a screenshot of one of my pre-installed "modules," which is a complete web-based IDE.

Image title

For the record, I can instantiate my entire IDE as a "widget" too, by simply creating a "widget" of type [hyper-ide.widgets.ide], at which point I can reuse my entire IDE as if it was a C# "UserControl."

In fact, you can even store your "module" in your MySQL database, since Hyperlambda after all, is simply nothing but a file format, and it doesn't even care where you store it. At which point your "load-file" invocation about, must be exchanged with a "load-from-database" invocation. However, my actual operating system is actually 5 lines of code. Or 8 to be accurate. Sorry for exaggerating... 

Want to play around with an operating system, containing only 8 lines of code? It's open source, and you can find it here.

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

architechture ,operating systems ,web dev

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}