Page 1 of 1

Objectively: OO framework for GNU C

Posted: Mon Jan 12, 2015 2:01 am
by Jay Dolan
Recently I had the idea of building an MVC framework atop SDL2 and OpenGL for (primarily) games. I'm fond of Apple's Foundation and UIKit frameworks, and thought modeling mine after those might be wise. To do that faithfully, retaining most of the idioms that make those frameworks sing, I needed OO, but I'm not a fan of C++.

So I started hacking on an OO implementation in C:
https://github.com/jdolan/objectively

Features:
  • Single-parent inheritance through starts-with structure composition
    Class and instance methods with strongly typed interfaces
    Automatic class loading and lifecycle management
    Automatic memory management with reference counting
    Object primitives for Boolean, Date, Null, Number, String
    Mutable and immutable collections variants such as Array and MutableDictionary
    JSON parsing, marshaling and introspection with JSONSerialization and JSONPath
    Low-level concurrency constructs such as Lock, Condition, and Thread
    High-level concurrency with Operation and OperationQueue
    Resource loading via Internet protocols with URLSession and URLSessionTask
API Documentation:
http://jaydolan.com/projects/objectively/hierarchy.html

With Foundation mostly implemented, I'll be starting on UIKit soon. It should get really fun from there on in. So that's that. Questions, feedback, etc.. very welcome.

Re: Objectively: OO framework for GNU C

Posted: Mon Jan 12, 2015 11:10 am
by frag.machine
Plain C with OO and a nice collection lib ? Woah.
Still reading the documentation, but so far I like what I see.
I'll download and play a bit with this later.
Impressive work. Thanks for sharing.

Re: Objectively: OO framework for GNU C

Posted: Mon Jan 12, 2015 2:21 pm
by mh
Personally I'd just use C++, picking and choosing the bits of it I like, or that make sense to use, or that don't have a syntax that makes Brainfuck look sensible. There seems a huge element of "Not Invented Here" involved in designing your own OO framework on top of C.

Re: Objectively: OO framework for GNU C

Posted: Mon Jan 12, 2015 10:40 pm
by Jay Dolan
frag.machine wrote:Plain C with OO and a nice collection lib ? Woah.
Still reading the documentation, but so far I like what I see.
I'll download and play a bit with this later.
Impressive work. Thanks for sharing.
Right on! Looking forward to your feedback. I'm on a Mac, but I've been compiling it on Debian periodically to make sure that it's Linux-friendly. Hopefully it Just Works for you.

Re: Objectively: OO framework for GNU C

Posted: Mon Jan 12, 2015 10:56 pm
by Jay Dolan
mh wrote:Personally I'd just use C++, picking and choosing the bits of it I like, or that make sense to use, or that don't have a syntax that makes Brainfuck look sensible. There seems a huge element of "Not Invented Here" involved in designing your own OO framework on top of C.
No, it's not like that. I'm the first programmer to use libraries where appropriate. For example, Quake2World is one of the most stripped-down Quake engines out there, leaning heavily on glib and SDL. But in order to write OO code in C, I really wasn't very impressed with the options:

GObject? Huge, awkward and gross. And at the end of the day, even after you jump through all of its hoops, you don't get OO semantics. You just get a really longwinded C API to manipulate an object-centric data model. GObject becomes useful if you bind to it from, or wrap it with, a higher-level language (Vala), but I wanted to stay in C.

Mowgli? Small and not gross, but again, no OO semantics even after you complete all of the [runtime!] boilerplate to build your Object model.

Objectively is different. It's strongly typed with compile-time checking of all method invocations, because the interfaces are structs. It's concise, there's no boilerplate to initialize types at runtime, and it offers real OO semantics.

Did you take a peek at the test cases? They do a decent job of showing off the syntax and API.
https://github.com/jdolan/objectively/t ... bjectively

Anyway, people who like C++ will generally not like this project.. so there's that.