Why you should be writing apps for Haiku

You're not going to get rich out of this. Let's just get that out of the way so we can move onto saner ground. If you are hoping to retire at the age of twenty-five, go forth and write iPhone games, and good luck.

But if you are a computer hobbyist, if you simply enjoy playing with bits and bytes, if you just like to write a program for the thrill of seeing it work, and putting it online in case someone else finds it useful, then you should seriously consider writing apps for Haiku.

Hai-what? Glad you asked. Haiku is an open-source x86 operating system that tries to recreate the look and feel of the BeOS that you may remember from the 90s. Think of it as "like Linux, but back when Linux was still fun, before the men in the suits took over." It is partially POSIX-compatible, but not based on a Linux or BSD kernel. The file system has flat-file database built in. It does not have a "please wait" cursor built in, because it runs fast and smooth, and app sizes tend to be small. I'm not going to sing Haiku's praises in this post. Just go to haiku-os.org and read up on it.

Compared to Linux, this is a tiny community, where everybody knows everybody else. On the other hand, it is pretty much the last man standing out of what was once a flourishing field of hobbyist operating systems. Once-promising OSs like AtheOS are barely surviving. The Haiku community, like a collection of your favourite bickering relatives, keeps going on doggedly.

So why should you be writing apps for Haiku? For one simple reason: you can be the first. Does Windows need another flat-file database? Does Mac OSX need another wall-paper utility? Does Linux need another text editor? Of course not. Those systems have been around for decades and  it is really, really hard to think of a new sort of app for which there aren't already a dozen well-established alternatives.

Haiku needs EVERYTHING. Can you write a word processor? This is your chance to be a hero. Write something that will read and write the common document formats and do the basic word processing functions on Haiku, and everybody in the community will install it. You have the chance to be the first, to be the author of that program that all the other programmers have to compete against. 

You like to write tools and utilities? Have I got a project for you. Python runs on Haiku, but only in text mode. There was an app called Bethon from the BeOS days that gave Python hooks into the API, so you could write GUI apps with Python. Bethon desperately needs an overhaul. People are trying to create API hooks for Lua and FreePascal. Those people need your help.

You don't want to start from scratch, but you do like to take something that already exists, see how it works and fix it? There are hundreds of old BeOS programs, with source code available, that just need a little attention to become functioning Haiku citizens again. Or you can port QT4 and Java apps - more about that later.

You can do this on many levels. If you like to be all indie and just put up your stuff on your own website, do that. You can give your  app to haikuware.com for wider distribution. You can join haikuporter and get your apps into the official repository. Or you can start working on the OS itself. Sadly this is where we tend to lose app developers - they get sucked into the main project.

OK, what do you get to work with? Let's start with writing small command-line utilities. You get C, C++ and Python out of the box. Perl, Lua and Ruby are easily available. The command line, by the way is the same bash shell you already know from Linux, BSD and Mac OSX. FreePascal can be installed. The Go language is being ported. There are a variety of BASIC interpreters and if you really insist, you can install oddities like Cactus and Gwydion Dylan. If you can write in Assembly, you probably don't need to read this article.

Things are more restricted if you want to write GUI programs. The official way is to write in C++. That is what the Haiku API is really aimed at. And we're talking about programming the old-fashioned way, with a text editor and a terminal. On Haikuware you will find half a dozen graphical IDEs in need of maintenance. You want one, pick one up and fix it. Please?

There is an excellent tutorial available, called Learning to Program with Haiku, that takes you from absolute beginner to C++ Haiku programmer. Actually the course and the never-officially-published sequel are freely downloadable, but just go to Lulu and buy the thing, OK?

Your other option is yab. This is a version of Yabasic with Haiku API hooks, and it is entirely addictive. Hey you, stop turning up your nose. Yes, it is BASIC, but it is a modern BASIC: no line numbers, no GOTOs. yab has only recently been accepted into the official repositories. Try it, you'll be surprised at the way you can throw up a bare-bones, but fully functioning graphical text editor with 130 lines of code. Tell you what, I'll paste it in at the end of this post for you.

With C++ you can write any kind of program. yab is a little more restricted. You shouldn't try to write a graphics-heavy game with it. But the yab community is continually stretching the boundaries of what this language can do. Both the official yab IDE and my own alternative IDE were written entirely in yab.

As I've mentioned before, the possibilities of writing graphical apps for Haiku in Python, Pascal and Lua can best be described as "work in progress". But there are two other possibilities.

QT4 has been ported to Haiku, and it is possible to port QT apps to run on Haiku. This is controversial within the community. Ports that have simply been recompiled without closer attention don't look right on a Haiku system, and they ignore the features like extended attributes that make Haiku different from other operating systems. But in time. QT may well  become entrenched as Haiku's second API and people may start writing QT apps specifically for Haiku, not just porting existing ones.

More recently, OpenJDK was ported, and the Haiku community is still cautiously feeling its way into the world of Java porting and programming. Right now, Java apps look even less Haiku-like than those ported from QT. But that too may change.

And that is why you should write apps for Haiku: a small but fanatically devoted community that will snap up your program, the satisfaction of being the first to bring a new kind of app to the platform, and mostly, well, it's just more fun.



Teditor ss


yab example program: Teditor, a yab text editor in 130 lines of code

I could squeeze this down to 100 lines, but readability would suffer. your browser will probably wrap some of the longer lines.


#!yab

############# Prologue #############

ProgramName$ = "Teditor"

AuthorName$ = "Joe Bloggs"

ProgramVersion$ = "V0.1"

ProgramBriefDescription$ = "My unbelievable first yab program."

ProgramLicense$ = "Public Domain"

ProgramAcknowledgements$ ="With thanks to clasqm for creating Teditor!"

 

//*****Global Variables****

## Technically, yab does not require you to declare global variables, it just is a really, really good idea to do it anyway.

// set DEBUG = 1 to print out all messages on the console

DEBUG = 1

//change this to DEBUG = 0 when you are ready to bind the program for distribution


OpenWindow()

#######End of Prologue#######


############# Main Message Loop #############

dim msg$(1)

while(not leavingLoop)

    nCommands = token(message$, msg$(), "|")

    for everyCommand = 1 to nCommands

        if(DEBUG and msg$(everyCommand)<>"") print msg$(everyCommand)

        switch(msg$(everyCommand))

            case "_QuitRequested":

            case "MainWindow:_QuitRequested":

            case "MainWindow:File:Quit":

                leavingLoop = true

                break

            case "MainWindow:File:Save":

                SaveFile()

                break

            case "MainWindow:File:New":

                NewFile()

                break

            case "MainWindow:File:Open":

                OpenFile()

                break

            case "MainWindow:Edit:Undo/Redo":

                textedit set "EditSpace", "undo"

                break

            case "MainWindow:Edit:Cut":

                textedit set "EditSpace", "cut"

                break

            case "MainWindow:Edit:Copy":

                textedit set "EditSpace", "copy"

                break

            case "MainWindow:Edit:Paste":

                textedit set "EditSpace", "paste"

                break

            case "MainWindow:Edit:Select All":

                textedit set "EditSpace", "select-all"

                break

            case "MainWindow:Help:About":

                Alert ProgramName$ + " " + ProgramVersion$ + "\n" + "by " + AuthorName$ +"\n\n" + ProgramBriefDescription$ + "\n" + ProgramLicense$ + "\n" + ProgramAcknowledgements$, "OK", "none"

            default:

                break

        end switch

    next everyCommand

wend


CloseWindow()

end

#######End of Main Loop#######


sub CloseWindow()

    //Close down the main window

    NewFile()

    window close "MainWindow"

end sub


sub MakeMenu()

    //Create menu in MainWindow

    menu "File", "Quit", "Q", "MainWindow"

    menu "File", "New", "N", "MainWindow"

    menu "File", "Open", "O", "MainWindow"

    menu "File", "Save", "S", "MainWindow"

    menu "Edit", "Undo/Redo", "Z", "MainWindow"

    menu "Edit", "Cut", "X", "MainWindow"

    menu "Edit", "Copy", "Z", "MainWindow"

    menu "Edit", "Paste", "Z", "MainWindow"

    menu "Edit", "Select All", "A", "MainWindow"

    menu "Help", "About", "", "MainWindow"

end sub


sub NewFile()

    local sos

    if  textedit get$ "EditSpace" <> "" then

        sos = alert "Save Current Text First?", "Yes", "No", "", "none"

        if sos = 1 SaveFile()

        textedit clear "EditSpace"

    endif

end sub


sub OpenFile()

    local file2open$, anewline$

    NewFile()

    file2open$ = filepanel "load-file", "Open Which File?", "/boot/home"

    if file2open$ <> "" then

        open file2open$ for reading as #1

        while(not(eof(1)))

            line input #1 anewline$

            textedit add  "EditSpace", anewline$ + "\n"

        wend

        close #1

        textedit set "EditSpace", "gotoline", 1

        endif

end sub


sub OpenWindow()

    //Setup the main window here

    window open 100,100 to 600,500, "MainWindow", "Teditor"

    textedit 0,20 to 499, 399, "EditSpace", 3, "MainWindow"

     textedit set "EditSpace", "wordwrap", 0

    MakeMenu()

end sub


sub SaveFile()

    local file2save$, filename$

    file2save$ = textedit get$ "EditSpace"

    if file2save$ <> "" then

        filename$ = filepanel "save-file", "Save File As ...", "/boot/home"

        if filename$= "" return

        open filename$ for writing as #1

        print #1 file2save$

        close #1

    endif

end sub



bookbanner


© Michel Clasquin-Johnson 2014-2017