Architectural Philosophy
The overall philosophy of CIDLib is to be as hip and pure a C++ development
environment as I can possibly create, given my available time and abilities.
However, this does not mean its a huge, experimental pig. I very much keep
performance in mind, and being into things like ray tracing I cannot afford
to have piggy code. I want it to be as fast as it can be without unduly
affecting the architecture.
Actually, the side effects of the purity approach mostly manifest
themselves as an insularity that declines to participate in any standard
or technology that cannot be incorporated seamlessly. CIDLib is NOT intended
for legacy work or to use in conjunction with other libraries or subsystems.
It is intended to be a totally self contained world, where all objects must
understand and participate in standards and API sets. This makes for much
magic but limited interaction with the outside world. Its about as far
from an OpenDoc approach as possible, closer to the Taligent CommonPoint
approach.
* You can of course wrap many passive procedural APIs in an
an OO shroud relatively cleanly, so its not like CIDLib is totally
insulated. It itself obviously encapsulates some basic interfaces to the
operating system, but it keeps them very low level and minimizes their
impact upon the cleanliness of the architecture.
This is of course only possible because I don't have to make money off of
it. Its a long term view, not likely to pay off immediately, but very much so
over the long term (even if only indirectly in the depth of my experience and
its effect on my market value.) There are plenty of more immediately practical
systems out there, all of them extreme compromises attempting to gain the most
use from the underlying OS regardless of how it affects the architectural
consistency. I'm not putting them down, its a necessary thing in their
positions. I just want to do the other thing, and I'm willing to accept that
it means it might never be a mainstream product.
Stylistic Philosophy
You are probably going to hate my coding style, since almost everyone hates
almost everyone else's style. Since mine is pretty agressive, you might hate
it even more. Although one can justify stylistic issues in many ways, I won't
bother. In the style guide I explain
it and my intentions and reasons, but I make no attempt to justify it beyond that.
Some stylistic mechanisms are really aimed at self documentation, not for
aesthetic purposes. CIDLib uses a good many of these because C++ does not
allow the developer to encode semantics in many cases. Comments and stylistic
standardization must make up for these limitations. These are also covered
in the style guide. Even if you don't like them, understanding them will
help you read the CIDLib code and get the most out of what its telling you.
System Requirements
Contrary to what some people often might think, writing for smaller systems
is often much harder than writing for larger ones. Smaller systems (such
as Dos) require many compromises and manual optimizations to get around its
limitations. Under OS/2 and NT type systems, these are lifted pretty much
but there are other compromises driven by the desire to operate reasonably
on memory constrain systems or disk constrained or video constrained systems.
CIDLib assumes a relatively high end machine (Pentium, 32Meg, 24bit color: for
development, somewhat less for target machines) and makes no compromises to
accomodate lesser machines.
This approach does not mean that I don't care about those people on the
smaller machines, it just means that I cannot afford to do that work. By
sticking to a purer architecture, and taking some performance and footprint
hits, I can get a much safer, cleaner, hipper, more flexible system. In the
end, my approach will result in a much better, though often less politically
practical architecture. The abstraction that makes OO systems so powerful is
the primary culprit in the overhead. It requires more virtual (indirectly
accessed) functionality and more layering.
So obviously its not a system for writing small games or utilities. Its
more designed for larger suites of apps that gain massively from sharing
a common, full featured object framework between them. Since a lot of the
code of such a system would be in CIDLib Dlls, the code pages will be
shared for heavy savings in memory usage per-process. To be fair also, even
something MFC (a heavily compromised system) is still not very appropriate
for such small, standalone applications either.
* In the future, when the hardware is faster, and the OS itself
is an object oriented framework, then it will probably be ok for games. In
this scenario, everyone shares the code because its in the OS itself, not
another product layered over an OS.
Platform Specificity
CIDLib right now is hosted on OS/2. According to how well OS/2 manages to
hold on, this will continue. However, CIDLib only uses OS/2 as a 'micro'
kernel and is not terribly dependent upon it. It is not though intended to
be portable. To be honest, my grossly overblown designs for CIDLib are for
it to become the interface to an operating system. Throw a real micro kernel
and graphics subsystem underneath it and it would make a pretty cool OS
when its had a few more revisions of development. Ok, I'm dreaming...
For this reason, CIDLib provides its own standard controls. It also does
so because trying to write the PM controls is a huge excersize in futility,
if purity of architecture is your desire. Been there, done that, bought that
TShirt. But this scheme is also in keeping with the need to minimize the
dependence upon the host OS. Because of this stance, CIDLib is only dependent
upon the ability to do the basic graphics operations required to draw the
controls (and the very basic window messaging capabilities of the underlying
OS.)
In other areas, such as semaphore management for instance, the CIDLib
classes are basically modelled after and directly based on the OS/2 semaphore
scheme (though of course CIDLib makes them fully OO.) The semaphore API is
very passive so its easy to encapsulate cleanly, and its a fine basis for
any future native version of CIDLib. So there is no need for me to try to
build that kind of functionality myself. Where it is possible to do so
cleanly (and without undue dependence upon the OS, this approach is taken.
The windowing system just happened not to meet those criteria.
After this release, I must sit down and really do some soul
searching and see if I will be forced to move the development to NT and VC++.
It would be a sad day if this happened, but even I must be pragmatic to some
degree.
Brief List of Other Philosophical Stances
Here is a small list of some of the salient points of the CIDLib philosophy
that drives its architecture and style. This is not meant to be a full
discussion of these issues by any means (they are covered in more detail in
various places), but this is to give you a feel for it.
- Consistency is a very good thing. Consistency makes a developer's
live easier because knowledge in one area is likely to be leveragable in
another. Having a whole class library designed and implemented by one person
obviously makes this easier. Its a rare development manager who can sync up
a randomly selected group of developer's and make them subsume their personal
visions of style and architecture into a totally consistent whole.
- Multiple Inheritance is a good thing if controlled and used in the
'mixin' style.
- Though some magical stuff like RTTI and polymorphic streaming are
exceptions to the rule, make as much use of compile time static typing
as possible. Multiple inheritance, in conjunction often times with templates,
can do a lot in this area. Doing lots of RTTI is usually a sign of bad
design in the C++ world.
- It doesn't help to be too Nazi about returning references and pointers
to object members, because anyone can toast anything else in memory pretty
much anyway. Just control it by making good use of const and implement it
consistenty.
- Objects which retain references and pointers to other objects (i.e. they
optionally become responsible for them) are a tricky subject and all stylistic
tools must be brought to bear in order to encode the semantics of such
transactions into the code itself.
- RTTI is a blessing to be used sparingly, not a major architectural piece
to become the basis for elaborate schemes.
- 8.3 sucks. CIDLib requires HPFS and assumes long file name support in
all things (though of course it can be used to selectively read and write
files on FAT partitions, you just have to be responsible for making sure
your file names are appropriate.)
- Frameworks are a good thing. Where possible, frameworks are used to
encapsulate large amounts of common functionality, with the user providing
just the application specific functionality.
- Templates are a necessary evil. They can be misused and they are very
much a pain the rear sometimes. But, they have that one big, hairy advantage
of making a whole class of previously runtime checked problems become compile
time, statically checked problems. This is a difficult thing to argue against.
- Although a minimal interface is theoretically something to strive for,
in the end the convenience of the user must be taken into account. Having
extra common functionality, often implemented in terms of the minimal
interface, can make the user's life very much more comfortable and avoid
performance issues in many cases.
- Also, any commonly used functionality not performed in the class will be
performed over and over out in the outside world, where it is more prone to
error over time and often loses performance because of its need to do
everything via the public API of the object instead of directly.
- A method that returns a copy of a value is a 'query method'. For instance,
a method that returns the size of a file. This is in contrast to a method that
returns some kind of magic cookie that must be given back (i.e. closed,
unlocked, etc...) Methods that return anything that must be given back are
'get methods'. CIDLib is very strict about the use of Get and Query in the
names of methods for this reason.
- Query/get/set methods should be named after the members they query, get,
or set.
- A single rooted system has enough advantages to justify its use,
therefore CIDLib is a single rooted system (except for the mixin classes
and a couple of very, very fundamental classes.)
- Exceptions are the only way to live. CIDLib is a purely exception driven
system, except for the tiny kernel Dll which is still procedural. Even this
might change soon. A single exception class is used by all, but it has plenty
of means to store any needed information.
- A limited form of hungarian prefixing is a useful means for achieving
self documentation. CIDLib uses 'family' prefixes, in which a base class
provides a family prefix used by all derivatives, e.g. 'str' for all string
classes. This limits the profusion of prefixes but provides critical info
about the overall type of objects when reading code.
- If a derivative becomes extremely specialized, it might warrant its own
type prefix, but I avoid this usually.
- All types must be enclosed in a namespace. At this time, my abilities here
are limited by the development environment. However all fundamental and enum
constants and global variables are encapsulated within pseudo name spaces (i.e.
structures.) Classes are in the global space at this time. This will be fixed
when Name Space support is available.
- Spelling it out is usually better than making up some cryptic short
name, unless its done very consistently. I still have not managed to totally
live by this rule, but I continue to update the style to be better.
- Extensive (but not constricting) use of const is always a good thing. This
goes a long way towards the holy grail of maximum compile time checking.
- Unless there is a strong reason to do otherwise, make all data
private. The except is constant data, which can often be just made public
if its needed by the outside world.