Skip to content

A Constructive Look At TempleOS

08-Jun-15

TempleOS is somewhat of a legend in the operating system community. Its sole author, Terry A. Davis, has spent the past 12 years attempting to create a new operating from scratch. Terry explains that God has instructed him to construct a temple, a 640×480 covenant of perfection. Unfortunately Terry also suffers from schizophrenia, and has a tendency to appear on various programming forums with a burst of strange, paranoid, and often racist comments. He is frequently banned from most forums.

This combination of TempleOS’s amateurish approach and Terry’s unfortunate outbursts have resulted in TempleOS being often regarded as something to be mocked, ignored, or forgotten. Many people have done some or all of those things, and it’s understandable why.

TempleOS after it's booted up.

TempleOS after it has booted up.

I’m reminded of a movie I once saw called Lars And The Real Girl, in which a man buys a RealDoll and treats her as his real girlfriend. Rather than laughing at him, the residents of his town instead band together and treat her as if she were a real person too. When I started watching it, I expected some Will Ferrell-esque comedy where this guy would be played only for laughs. Instead, I found an incredibly compassionate story within. The writer, Nancy Oliver, got the idea after thinking:

“What if we didn’t treat our mentally ill people like animals? What if we brought kindness and compassion to the table?”

There are many bad things to be said about TempleOS, many aspects of it that seem poorly constructed or wouldn’t work in the “real world”. I’m going to ignore them here. It’s very easy to be negative, but you will never learn anything new by doing so.

Many might consider TempleOS a waste of time, compared to more fully-featured OSs such as Linux, because it will never have the same success. Plan 9, developed by Bell Labs, was a research OS designed to be a successor to Unix. Despite some big names and big ideas, it was never any kind of commercial success. Was Plan 9 therefore a waste of time? Many would argue not, as some of its ideas have since found their way into other products.

Perhaps we should instead look at TempleOS as a research operating system: what can be accomplished if you’re not locked into established thinking, backwards compatibility, and market demands.

What can we learn if we are only willing to listen?

Installation

Installation was incredibly painless. The supplied distribution acts as both a LiveCD and hard-disk installer. Hit ‘Y’ a couple of times and you’ve installed it. It installed faster than Ubuntu does.

Booting Windows this morning, I can’t help but notice how long it takes. And even when Windows ‘appears’ to have booted, it doesn’t actually become properly usable for perhaps another minute. If you listen, you can spot the point at which usability is declared because Windows plays the startup sound to indicate it.

TempleOS boots off hard disk in 1 second. There is no paging, so it is instantly usable.

Shell

TempleOS has its own programming language, HolyC. The whole operating system is written in it, except for x64 assembly in the lower-level parts. Perhaps unexpectedly, the same language is also used for the shell. That’s right, you execute shell commands using a C-like language, and they go directly into the compiler.

Every filename printed in the shell is a hyperlink. You can right-click to get a context menu on each one.

There is no built-in calculator application, because the shell itself is one. Just enter 5+7; on the command line and you’ll get the answer. You can even go further than this and use the shell as a REPL to build entire programs in.

You have a menu file which sits in your home directory, and it accessible at any time by hitting Ctrl-M. By editing this file, you can create any kind of launcher you wish. Most files auto-save on exit, but this one does not. This means you can also use it as a popup scratchpad.

TempleOS has system-wide autocomplete. You can hit Ctrl-F1 at any point and get a list of completable words. Not just filenames, but also symbol names. All source code is indexed and you can jump to any function from anywhere, even from the shell. The same system works in any program throughout the OS.

TempleOS’s unified hypertext really shines when presented in the shell. From the command-line, you can call Uf(“Foo”) to disassemble a function, and each symbol printed will be hyperlinked in the shell window. Click on it to go to the source. objdump can’t do that.

The Type() function is used to display files, like DOS’s type or Unix’s cat. Of course, hypertext is respected. You can even use Type to show .BMP files directly in the shell. It raises an interesting challenge for other OSs – why do shells have to be pure text? Why can’t we have a multimedia shell?

File Explorer

Most operating systems have something like Explorer, Nautilus or File Manager to let you browse around a directory tree just by clicking. TempleOS does have a File Manager program (Ctrl-D), but it’s kinda just an extension of the shell, and surprisingly you don’t need it for most operations. By using the hyperlink system that permeates the operating system, the shell itself can act as an explorer. Type Dir; for a listing, then you can simply click on any directory hyperlink to change to that directory and get a new listing, all within the same shell. Or click on “..” to go up. It takes a little getting used to, but after having used it for a while I have to admit growing quite attached to it.

HyperText (DolDoc)

The most notable feature of TempleOS is it’s ubiquitous hypertext system, DolDoc. This is the foundation for the both the shell and the text editor. Unlike Unix which represents everything via plain-text, everything in Temple is stored in DolDoc format. The format itself is somewhat akin to RTF, and you can hit Ctrl-T at any point to inspect the raw text directly.

But DolDoc isn’t just for text. You can store images (and even 3D meshes) directly into documents. You can put macros in there: hyperlink commands that run when you click on them. So if you want to build a menu or launcher, you just make a new text document and put links in it.

All of this allows something similar to the Oberon system developed at ETH Zürich, where the distinction of text, programs, menus and forms all blurs together into one.

HTML, JSON, XML, shell scripts, source files, text files – TempleOS replaces all of these via one unified hypertext representation.

In a file from the TempleOS source code, one line contains the passage “Several other routines include a …”, where the “other routines” part is a hyperlink. Unlike in HTML, where that perhaps may lead to a page listing those other routines, here a DolDoc macro is used so that a grep is actually performed when you click on it. While the HTML version could become stale if no-one updated it, this is always up-to-date.

It’s not every IDE that lets you embed images and flowcharts directly into your source code, that kinda makes you sit up and take notice. And yes, those flowchart boxes are hotlinked, so you can click on them to go directly to the source code that implements them.

You can press Ctrl-R at any point to bring up the resource editor, which lets you draw things. The sprites you draw are embedded directly in the document, and you can refer to them using numbered tags. There’s no standalone paint program supplied with the OS because you already have one accessible at any time, from within any program. If you want to sketch a doodle, just open a new document, draw things into it and save it out.

HolyC

The language provided, HolyC, is at its heart a reasonably complete version of C but with some notable extensions.

There is no main() function in TempleOS programs. Anything you write at top-level scope is executed as it runs through the compiler. In C++ you can do something like “int a = myfunction();”, but you can’t just write “myfunction();” and just run it. Why not?

Every piece of code in TempleOS (except the initial kernel/compiler) is JIT compiled on demand. Yes that’s right – you can run a program without compiling it, simply by using an #include statement from the command line. The program is then brought into the shell’s current namespace, and from there you can execute individual functions directly just by issuing commands.

You can tag a function with the #help_index compiler directive, and it’ll automatically appear in the documentation at the right place. And yes that’s fully dynamic. You don’t need to run a rebuild process, just compile the file and the documentation updates. Hit F1 and you can see your changes reflected in the help system.

HolyC provides an #exe compiler directive, which can be used to shell out to external commands and include their output back into the source code. This provides a way for the user to implement a certain set of functionality that would otherwise require macros or specialized compiler support.

You can attach any metdata to any class member.

You can attach any metdata to any class member.

HolyC’s class system implements full metadata and reflection support. Given a class, you can enumerate every member to get its name, offset, etc. What’s surprising is that you can also attach any custom metadata to any class member at compile time. Example uses for this might include storing its default value, min/max range, printf format string. Does your language support this?

The special lastclass keyword can be used as a default argument for functions. It causes the compiler to supply the name of the previous argument’s type as a string, allowing you to then do metadata lookups from it.

There is no ahead-of-time linker, nor object files. The dynamic linker is exclusively responsible for binding symbols together at load time. The symbol table remains accessible at runtime, and can be used for other purposes. TempleOS has no environment variables – you just use regular variables.

Programming Environment

HolyC has no formal build system. You just compile a file and you’re done. If your project spans more than one file, you just #include all the files into one and compile that. The compiler can compile 50000 lines of code in less than a second.

When you hit F5 in the editor, the program is JIT compiled and run. The top-level statements are executed in turn, and your task is now loaded and ready. If your top-level statements included any sort of loop, it’ll stay running there. Otherwise you’ll be dropped back into a new shell. However, the shell exists within your task, so you can interactively use it as a REPL and start calling functions inside your program.

Does your current IDE support links to documentation?

Does your current IDE support links to documentation?

Or, perhaps you might place a call to Dbg() somewhere in your program, or hit Ctrl-Alt-D, and be dropped directly into the debugger at that point. The debugger of course, still functions as an interactive REPL. Does your IDE support a drop-in REPL?

How much support code does it take to open a window and draw graphics into it on your operating system? In TempleOS, there is a one-to-one correspondence between tasks and windows, so a single call to DCAlias is enough to return the device context for your window. You can just do this as soon as your main function is called and draw into it. Making a window is surely the most important thing for a windowed operating system – why does it have to be hard? GDI, X11, DirectX and OpenGL could all learn something here.

Hardware & Security

There is no hardware support. By that I mean that TempleOS does not support any hardware other than the minimal core system that makes a PC. There is no support for any graphics card other than VGA, there is no support for any soundcard other than the PC speaker, and there is no support for networking.

TempleOS does not use memory protection. All code in the system runs at ring 0, the highest privilege level, meaning that a stray pointer write could easily crash the entire system. This is a very deliberate design choice:

http://www.templeos.org/TempleOS.html
“It’s fun having access to everything.  When I was a teenager, I had a book, “Mapping the Commodore 64″, that told what every location in memory did.  I liked copying the ROM to RAM and poking around at the ROM BASIC’s variables. Everybody directly poked the hardware ports.”

Terry’s philosophy is that growing up in the 1980s, successful machines like the C64 had the same approach. A standardized platform, where you just boot it up and do things on that machine locally. The C64 was a very hands-on machine where the user was all-powerful.

Terry uses the following analogy:

  • Linux is a semi-truck with 20 gears to operate.
  • Windows is more like a car.
  • TempleOS is a motorbike. If you lean over too far, you’ll fall off. Don’t do that.

He argues that Linux is designed for a use case that most people don’t have. Linux, he says, aims to be a 1970s mainframe, with 100 users connected at once. If a crash in one users’ programs could take down all the others, then obviously that would be bad. But for a personal computer, with just one user, this makes no sense. Instead the OS should empower the single user and not get in their way.

TempleOS has no file permissions. After all, if there’s only one user, who else could you give permission to? To be honest, I’ve often wondered if Unix wouldn’t be better if we just made all security happen at the mount level, instead of micromanaging it per file.

There are no such things as threads in TempleOS, as it doesn’t need them. Processes and threads are the same thing, because there’s no memory protection. If you need something in parallel, just spawn another process and let it share data with your own.

While I can appreciate Terry’s philosophy, it’s probably fair to point out that the C64 did come with one other thing – an ecosystem where it was commonplace to exchange and distribute programs on physical media, via stores and magazines. As much as I hate to say it, that bird has flown.

Conclusions

In many ways TempleOS seems similar to systems such as the Xerox Alto, Oberon, and Plan 9; an all-inclusive system that blurs the lines between programs and documents.

In this video Terry gives a brief tour of some of the more interesting features of TempleOS. At 5:50, he shows how to build a small graphical application from scratch. Now let’s just think about how you’d do this in Windows for a second. Consider for a minute how much code would be needed to register a windowclass, create a window, do some GDI commands, run a message pump, etc. You’d need to set up a Visual Studio project perhaps, and either use the resource editor to embed a bitmap, or try and load it from disk somehow. Now compare it to the tiny snippet of code that Terry writes to accomplish the same task. It certainly makes you wonder where we went so wrong.

Watching TempleOS execute its built-in test suite is a jaw-dropping experience. I can’t help but be impressed as a vast number of demos, games, graphing calculators, debuggers, and compilers all fly before your eyes. To see the sheer amount of content that’s been written here over the years, to see such effort expended on a labor of love, is wonderfully heart-warming.

Now I don’t claim that you should all immediately dump Windows/Linux/OSX and start using TempleOS as your day-to-day operating system. However, you might find that if you take the time to open your mind to new ideas, you might learn something from the most unexpected places.

So what can we learn from this and apply to our own endeavors?

  • There’s more than one way things can work.
    Just because your current toolsets all do things one way, doesn’t mean that’s necessarily the best way to do it.
  • There’s something worthwhile to be found in everything.
    It’s incredibly easy to just assume that because something isn’t successful, or is developed by just one guy, that there’s nothing to discover there. But if someone’s invested 12 years of work into something, is it not possible that you might find even just one interesting idea in there?
  • Don’t write things off just because they have big flaws.
    OK, so it’s 16 colors, it’s 640×480, and the author is his own worst enemy. But if you dismiss everything in life because it’s not what you’re used to, you’ll never expand outside what you already know.

If GNU is the cathedral, and Linux is the bazaar, perhaps there is a place for the temple somewhere too.

 

facebooktwittergoogle_plusreddit

Written by Richard Mitton

Software engineer and travelling wizard.
Follow me on twitter: http://twitter.com/grumpygiant

17 Comments

  1. cbortz

    Richard,
    Thank you for taking the time to point out some of the interesting and amazing things found in TempleOS. Like others I have sort of dismissed it as the product of an eccentric. I should probably know better. It seems like there are some great ideas there and it would be interesting to see how/if they could be incorporated into a more accessible system. If it had networking, or at least the ability to network (separate network shell?) then that could really be something to think about. Color me impressed. BTW, I got here via HackerNews so you have gotten the word out.

    Posted on 08-Jun-15 at 4:31 pm | Permalink
  2. Andrew Andkjar

    “If GNU is the cathedral, and Linux is the bazaar, perhaps there is a place for the temple somewhere too.”

    this was an odd analogic for myself as the cathedral vs bazaar categories (as ESR defined them in a similarly named book) were more about delineating mechanisms of software production rather than the product itself. In my understanding the cathedral was about top-down central design whereas the bazaar was practically the polar opposite where ideas came from anywhere, were judged on merit, and incorporated or discarded upon experimental results and community uptake in a decentralized fashion. I get the sort of physical reference, but it seems a stretch and unhelpful with respect to understanding how TempleOS came to be or where it really stands on that aforementioned production mechanism spectrum.

    Posted on 08-Jun-15 at 4:48 pm | Permalink
  3. Dude

    Early version of Unix were shit. I’ve seen the Version 7 sources, and ran it on a PDP-11 emulator.

    Posted on 08-Jun-15 at 6:34 pm | Permalink
  4. I beg you. Please correct your its/it’s mistakes.

    Posted on 08-Jun-15 at 8:10 pm | Permalink
  5. richard

    The its/it’s have been fixed. I seem to have a kind of “its blindness” – my brain understands the rules but my fingers do not.

    You’re not the first person to ever call me out on it. It’s strange how much it seems to anger people :)

    Posted on 08-Jun-15 at 8:38 pm | Permalink
  6. Crentflox

    As it was produced by Terry talking to God, it’s clearly a different software production model than can be described on the cathedral-bazaar spectrum. I think the temple analogy works nicely to show that it is an intensely personal but divinely inspired mode of creation.

    Posted on 08-Jun-15 at 9:41 pm | Permalink
  7. Me

    I never considered TempleOS a small feat matter of fact i was always totally impressed and amazed by how skilled the creator is, despite his mental illness no one can deny his computer skills, although i don’t like the religious aspect of the OS and of course the weird GUI but that doesn’t make it any less amazing.

    Posted on 08-Jun-15 at 10:26 pm | Permalink
  8. TempleOS definitely has some appealing ideas. Thankfully, there’s been enough interest in them elsewhere to at least get them in some places and some of the time in a day-to-day Linux desktop.

    For example:

    The Terminology terminal for the Enlightenment desktop has many of those same terminal-related features (eg. hyperlink support for absolute paths and URLs, a tycat command which can display office documents, images, video, and audio (controls) inline and a tyls command which can display thumbnail-enhanced directory listings.)

    https://www.enlightenment.org/about-terminology

    While it’s nothing on an OS-wide solution, TiddlyWiki does a beautiful job of blurring the lines between wiki and application framework.

    http://tiddlywiki.com/

    1. Internally, it’s a record-oriented key-value store with tagging, a widget-and-macro engine, and MVC-esque framework that just happens to come preconfigured to act as a wiki.
    2. It’s a microkernel-based design where 99% of the application exists in specially-tagged wiki pages.
    3. The master UI templates are just wiki pages with special names and the entire UI is built in the same widgets and macros you use.
    4. The DOM is treated more like a framebuffer and code must assume it can be discarded at any time. Click “save” on anything not written in raw JavaScript and see the app update itself immediately.
    5. It can be run as a multi-file Node.js app or as a single-file file:// JavaScript app quine and you can seamlessly convert between the two.

    For example, if you want a TODO list, you can hack it together in a minute or two.
    Take a look at the source to http://tiddlywiki.com/#TaskManagementExample

    (It’d just take one or two more widgets to add a “type here to create a new task entry” box)

    Posted on 09-Jun-15 at 2:11 am | Permalink
  9. Seems to me if this gets networking, it could become a great operating system to tinker with.

    Posted on 09-Jun-15 at 5:05 am | Permalink
  10. Cellar

    It’s not difficult to see where how we got where we are. TempleOS is
    a useful reminder if you look at it right.

    This is execellently powerful software optimised for a very specific
    use-case: That where the user wrote all (or most) of the software and
    the data. As a consequence, you don’t want this even connected to the
    public internet because then you don’t know what data or code you’re
    putting on your nice and clean system. You don’t want to run programs
    written by third party companies, and so on. The thing has no protections,
    which is just great for tinkering, but not at all nice for getting other
    tasks done using this as a tool.

    linux actually has trouble remembering its roots, perhaps since it doesn’t
    really have roots of its own. But it is true that Unix had to accomodate
    multiple users already early in its career, though on minicomputers, not
    mainframes–there’s a difference and it shows. It really is not fun sharing
    a computer that crashes all the time because your friends keep on doing
    stupid shit, so internal barriers got put up. I remember the “fun” we had
    with a roomful of linux peecees where the root password had somehow gotten
    out. There’s always somebody who needs to, say, drop forkbombs on everybody
    else’s computer.

    windows actually started out as a single user computer system too, and
    this still is the source of many of its malware and virus ailments: The
    internal barriers are too little, too late, entirely ineffectual because
    of design now set in stone. They didn’t merely get blindsided by the
    internet. They just didn’t think writing solid software was worth their
    time, and their customers keep on paying an entire cottage security
    industry for their lazy presumption.

    Beyond that, windows isn’t written by some a single person wanting to
    scratch itches or to build a beautiful system. windows is a means for
    a large many people to make money. And it does exactly that. For them
    this does not translate to code efficiency, on the contrary. They still
    enjoy good relations with the peecee industry exactly because their
    software drives new hardware sales, even if that isn’t a provable design
    goal but an emergent property of their workflows.

    A much better example of what can be had if smart people put their mind
    to it is QNX. There are several things it doesn’t do quite right, but
    some it does very right indeed. I still remember the single (1440kB)
    floppy image containing a bootable graphical environment with network
    support and web browser, in normal and snowman varieties. Its price
    tag ensured very few got to enjoy it, but it did come with a solid core.

    There are other systems that come with comparably amazing functionality
    in different aspects and ways, most or all remain unpopular and niche.
    Why that is so is one of the great questions we don’t know answers to yet.

    Posted on 09-Jun-15 at 9:19 am | Permalink
  11. Mark Smith

    Some misunderstandings about the need for different users are found here, in particular, even though a PC has one human user, user privilege seperation is a main mechanism used to confine say a web browser from being able to damage the software files on the system, the files for code on disk are owned by a different user than the user that runs them, so if a process is corrupted, it cannot damage the system.Additional layers have been added with sandboxing in the browser, you cannot have too many layers of protection here. The fact that TempleOS has no networking is a good thing, because it would be an easily exploitable disaster if it did. So, no, the point of having a multiuser OS is not limited to having many human users, but also CRITICAL for security and being able to place software into a user sandbox. About his religious views, its okay to disagree with them but on the other hand, I find it troubling how some seem to be trying to deny him the ability to express his views and suppress anyone they disagree with, pushing us towards losing freedom of speech by claiming that any views or opinions other than their own is “intolerant” and cannot be mentioned, this is a twisted and outrageous definition of “tolerance” which now in some people means that “tolerance” is not saying anything others disagree with and “intolerance” is having opinions and views others disagree with. This is Orwellian and the opposite of what of what free speech is, its a twisted and convoluted way of thinking that has turned things on its head. Really “tolerance’ is respecting the ability of others to express their own opinions, rather than being barred from expressing views others disagree with.

    Posted on 09-Jun-15 at 9:42 am | Permalink
  12. MikeB

    Many if not most of the early PCs were, in concept, like this, though at the time most interaction was through the BASIC (usually but not always MS- in some form) interpreter. After all, isn’t a JIT compiler just a grown-up interpreter? But you could do interesting things.

    I wrote one program that I wanted structured, for future maintenance and enhancement, which of course olde BASIC didn’t support well by itself. So I used an “outline processor” that came with an add-on ROM in my Radio Shack Model 100 to build the program from the top down, designing the menu and screen presentation, then iteratively building the pieces. Since all the files were text, BASIC in the target Model 1 happily interpreted the file for testing. When I was done, the only correction needed was in one section that didn’t perform well due to garbage collection; because of the structure, rewriting that section with a different design was a relatively easy plugin, and led to a couple of other improvements.

    Yes, these days you do that with huge code bases and * Studio GUIs, and the system is no longer a few system commands and a collection of (actually documented, in most cases!) POKEs and PEEKs; but that, really, is an outgrowth of IBM pushing PCs into Big Business, where the mainframe and mini aka corporate people took over. These days, there aren’t many “personal” computers any more, nor many users who would feel comfortable messing with their internals.

    Posted on 09-Jun-15 at 10:31 am | Permalink
  13. neat. i’m one of those people that really hate the current way of automatically assuming multiple users on a desktop. sure, allow it as an option for work places but for most situations, people do usually have their own (personal) computers… single user. i hate hate hate having my preferences and configurations spread all over the operating system in byzantine user directories and i do long for the days when a program installed every aspect of itself into it’s own folder.

    Posted on 09-Jun-15 at 10:36 am | Permalink
  14. Vijay Ramesh

    @Mark Smith I don’t think most of the criticism about his public posts (or why he got banned from HN) has to do with his religious beliefs. more likely the random hate-speech and racist rants he goes on.

    Posted on 09-Jun-15 at 11:54 am | Permalink
  15. rochrist

    This seems kind of like the Dwarf Fortress of OSes.

    Posted on 09-Jun-15 at 1:08 pm | Permalink
  16. Interesting post. Very curious how long ago this was written? (for example, Windows hasn’t had a startup sound in over a decade, and takes about 10 seconds to boot)

    Posted on 09-Jun-15 at 1:19 pm | Permalink
  17. richard

    This was written this week.

    The sound is definitely played – it’s called “Windows Logon Sound.wav” in the control panel settings.

    I timed it for you on my machine. I run Windows 7 x64, without anything too crazy installed.

    Measured from once the BIOS POST checks have finished:

    Time until logon dialog: 25 seconds
    Time until the desktop is presented and the logon sound plays: 33 seconds
    Time until all paging has finished and I can actually load things: 63 seconds

    That’s a total of 2m01s from bootup until I can actually get stuff done. Results may vary on your machine, but I certainly don’t think this is uncommon.

    Posted on 09-Jun-15 at 1:29 pm | Permalink

3 Trackbacks/Pingbacks

  1. […] http://www.codersnotes.com/notes/a-constructive-look-at-templeos […]

  2. […] Una mirada constructiva a TempleOS […]

  3. […] se publicó un interesante artículo en Codersnotes donde hablan del sistema y su […]

Leave a Reply