Skip to content

File and symbol naming scheme

Nat! edited this page Sep 23, 2018 · 19 revisions

MulleObjC is the point where we move from the C compiler to the Objective-C compiler, coming up from mulle-objc-runtime. But there are C functions, that can be callable from C only, which we like to expose. These functions may be callable without the Objective-C runtime properly setup (like NSRange inline functions).

Symbol Naming

Classes, protocols etc. are the usual mix of lower-camel-case (e.g. retainCount) and upper-camel-case (e.g. NSObject).

The Apple ObjC Functions are written in upper-camel-case like NSExtraRefCount. Picking up on this, all functions that deal with id/Class as types are also camel-cased.

The mulle-objc-runtime doesn't really deal with id/Class, that's part of MulleObjC.

Functions dealing with structs and other scalars use lowercase and underscores, except if they are part of a family of functions that are camel-cased.

Source Name case

Objective-C files are always camel-cased for historical reasons. C files are always underscore with 'hyphen' (instead of underscore), except when they contain camel-case functions (s.a.)

Source Name prefix

Apple compatible classes/protocol need to keep the "NS" prefix, but non compatible classes should not use the "NS" prefix to keep them distinct. That where the "MulleObjC" prefix comes into play.

Apple structs like NSRange also keep the camel-case in their C files, though these are C only. Now what prefix does MulleObjC use for non-compatible C files. "mulle-objc" is unfortunately somewhat tainted by the mulle-objc-runtime already, but alas it is the logical choice.

Header Naming

What would be great to provide for C is:

  • headers that are compilable with C (no #import f.e.) that are not tied to the runtime
  • headers that are compilable with C (no #import f.e.) that are tied to the runtime (i.e. mulle_objc_get_universe, -lmulle-objc-runtime)

What would be great to provide for ObjC is a set of headers, that do not include the full runtime headers and dependents. Because of their pollution of the namespace, downstream sources are getting too many implicit definitions and dependencies (e.g. mulle-buffer could be exchanged in the future for something else).

But that doesn't work at the moment, though work has started with `<mulle-objc-runtime/mulle-objc-runtime-minimal.h>

Header Provisioning

Header Description
include.h All C libraries MulleObjC depends on and that must be exposed upwards
`MulleObjC.h Combines include.h with all public headers for Objective-C only
mulle-objc-minimal.h Does not include include.h all C headers with minimal runtime tie in
mulle-objc.h Combines include.h with all C headers

ifdef double inclusion shield

The scheme is to replace '-' with '_' and a trailing .h with __h__:

echo "mulle-objc-foo.h" | sed -e 's/-/_/g' -e 's/\.h$/__h__/'
mulle_objc_foo__h__

You should be careful with file names, since mulle-objc-runtime uses the same scheme. For the motility aspect, it's not a splendid idea to use different prefixes. Though it would be workable.