Is it possible to programming Haiku GUI natively in C language?

All the question is in the title, can I use C language to develop a GUI application natively on Haiku Operating System? Or I must learning C++?

Sorry maybe that’s appear to be a noob question :melting_face: but I prefer have a feedback about it.

No, it is impossible unless you want to access C++ ABI directly by using mangled symbols and constructing vtables. Haiku GUI API is C++ only. Other languages need API bindings.

2 Likes

Speaking less of the technical implications, if you are just starting to learn C and are afraid it would be more difficult to learn about C++ features (classes & objects notably), I can tell you that 25 years ago when I was learning C with a book I found that writing GUIs in C++ on (on BeOS) was easier than on other platforms at the time…

4 Likes

This is precisely my case, I learn C at school. And indeed, classes and objects are quite abstract terms for me. Thank you for your feedback.

2 Likes

A class is just a C structure which has functions inside it. There are a few additions to that, but it’s really not that much more complicated, especially in Haiku where we don’t use a lot of the options offered by C++ at all.

Also, what you learn from C, can still be applied beoause the languages are otherwise very similar.

4 Likes

That the Haiku API is object-oriented doesn’t mean you have to define classes in your own code, beyond the minimum required to interface with the operating system. For the most part you can stick to the language you know. Though modern C++ is easier in my opinion; in fact (if you’ll excuse the shameless plug) I wrote a language tour earlier this month to show off this side of it.

P.S. Also, what PulkoMandy said: a C++ class is literally just a struct by another name. The only difference is the default visibility of members (protected versus public). There’s nothing magical about it.

1 Like

Well, the “minimum” is still a lot especially if you want a graphical user interface.

But, anyways, it’s not just about C++: you also have to learn about Haiku/BeOS specific things, such as BMessage and MessageReceived, loopers and handlers and how to pass data from one thread to another safely, using the layout kit, …

I don’t think removing the programming language “barrier” is actually going to be of that much help. On the contrary, I think the result will be that you have to understand the C+±oriented way of working and how it does (or doesn’t) translate into the language you are using. So, in the end, yes, you write in a language you know better, but then you still have to “think in C++” in addition to that.

I may be wrong, we will see what the people working on bindings come up with.

2 Likes

The problem with C++ is not just that it’s hard to learn a language, but also that it’s hard to develop in C++, even for developers with decades of C++ experience. C++ is an almost guarantee that you have to spend an enormous amount of time fixing bugs that simply wouldn’t occur otherwise. Even KDE with its corporate funding is still a crash fest.

Oh, for sure. The reason to write stuff in a different language, is that you have stuff written in a different language. With C it’s kind of a non-issue, because you can just declare it “extern C” and you’re done.

I have an application that I use to read my email, and I don’t want to parse IMAP etc. in C++. Or C. I gave it a try, had it more or less done, but … no. I’ve been through a number of iterations in various languages - it’s for my own entertainment. At present it’s Ocaml. From there, it’s better to do the foreign interface “down” - the C++ called from Ocaml. Or Python, Rust, whatever - that’s where the protocols are implemented, and the application logic, and it’s awkward to try to run the interface through a narrow application specific library, easier to use a slightly awkward non-idiomatic interface to the native API.

If you were doing applications that were all UI, then C++ would certainly be the way to go.

True, but with C this problem is even worse.

The best way to get rid of this feeling of “too abstract” in C++ is to do some exercises using concrete real like examples.

These terms are hard to understand out of context or even with user interface elements but if you pick simple examples where you understand stuff in practice it becomes easier to figure out.

Like create a basic RPG game. You create a “Person” class, then subclass it as Warrior, Magician etc. Then you realize object oriented programming is somehow closer to a human mindset than pure procedural programming.

1 Like

Well, whatever. For me, OOP is vastly over-rated as a doctrine, but it works out pretty well for a typical graphic user interface, so that’s where I’d point someone who already has a firm grasp on C programming and already has an introductory understanding of C++ - the interface kit.

Maybe the most helpful simplification would be to let them know, what you don’t need. Do you need to get acquainted with operator member functions? No. Template programming? Nope. cin & cout? Nope. Pass by reference? hm, that could come up … but really possible it won’t. A real C++ enthusiast could probably make a much larger list of what’s in this heaping pile of a language that you don’t need, to write a basic application with the interface kit.

1 Like

I am interested in this type of exercises. If you have tutorials links in mind about it, I’m interested. It’s learning while having fun

I am afraid I can’t recommend anything recent as I haven’t been following these resources for learning lately. Surely a lot has changes in the last 25 years :slight_smile:

Hopefully someone else can provide options ?

If not there are quite a few out there which are still C++ and use such “real life objects” examples but not necessarily using the Haiku API. I am thinking of SDL tutorials (which have the advantage of bein portable to other platforms).

1 Like