Skip to content

Commit d5e1006

Browse files
committed
docs: adding more content
1 parent 460d76d commit d5e1006

File tree

5 files changed

+147
-10
lines changed

5 files changed

+147
-10
lines changed

doc/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
* [Overview](overview.md)
66
* Basics
7-
* Adding DynaMix to a Project
7+
* [Adding DynaMix to a Project](basics/adding.md)
88
* [Elements and Glossary](basics/glossary.md)
99
* C++ Basics
1010
* C Basics
1111
* Advanced Topics
1212
* Custom Allocators
1313
* Creating Plugins
1414
* Mutation Rules
15-
* Custom Features
15+
* Creating Custom Features
1616
* [Dangerous Functionalities](advanced/danger.md)
1717
* Working with DynaMix
1818
* [Performance](working-with/perf.md)

doc/basics/adding.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Adding DynaMix to a Project
2+
3+
To build DynaMix you need a C++17 capable C++ compiler and a C11 capable C compiler. Respectively C++17 is required to use the C++ interface and C11 is required to use the C interface. MSVC 2022, gcc 9+, and clang 10+ are regularly tested and known to work.
4+
5+
Currently the only supported way to add DynaMix to a project is as a [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) package. Other ways are listed below, though they are not tested.
6+
7+
## As a CPM.cmake package
8+
9+
The recommended and the easiest way to add the library would be as a [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) package. If you are using this package manager (and you should be), you only need to add the package `iboB/dynamix` like `CPMAddPackage(gh:iboB/dynamix@2.0.0)`
10+
11+
## As a submodule/subrepo
12+
13+
DynaMix uses [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) to handle its own dependencies, but also bundles CPM.cmake itself. If you add dynamix as submodule of your repo and simply `add_subdirectory` it in CMake, everything will very likely work as intended. The CMake configuration of DynaMix will fetch the needed dependencies and everything will be configured as intended.
14+
15+
The danger here would be if the project already uses some of these dependencies. In such a case there will be a Clash of Targets™ and things will very likely won't build (or worse yet, it will build but will contain strange bugs due to ODR violations and ABI differences)
16+
17+
The dependencies are:
18+
19+
* [iboB/splat](https://github.com/iboB/splat) `~> 1.3.1`
20+
* [iboB/itlib](https://github.com/iboB/itlib) `~> 1.9.0`
21+
* CMake only: [iboB/icm](https://github.com/iboB/icm) `~> 1.4.4`
22+
* Tests only: [iboB/doctest-util](https://github.com/iboB/doctest-util) `~> 0.2.0`
23+
* Tests only: [iboB/doctest-lib](https://github.com/iboB/doctest-lib) `~> 2.4.9a`
24+
* C Tests only: [ThrowTheSwitch/Unity](https://github.com/iboB/doctest-util) `~> 2.5.2`
25+
* Benchmarks only: [iboB/picobench](https://github.com/iboB/picobench) `~> 2.04`
26+
27+
## More
28+
29+
As a whole the build of DynaMix is pretty straight forward. The core dependencies are header-only. So if you fetch them and build all .c and .cpp files in `/code` into a library, everything should be OK.
30+
31+
Creating build scripts for the library only with any build system should be easy.
32+
33+
The tests and benchmarks involve a bit more CMake scripting, but their build is mostly straight-forward as well.
34+
35+
The v1compat library generates code through a ruby script and thus its build is a bit more involved, but new users should not be using v1compat anyway.

doc/basics/glossary.md

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,87 @@
11
# Glossary
22

3-
## Mixin
3+
## Object
44

5-
A mixin is a building block of objects.
5+
An object in terms of DynaMix is an instance of the class `dynamix::object`. By itself it's not much more than an empty class. Its main purpose is to be a "container" of mixin instances. You can construct an empty object and then add or remove mixins from it via *mutations*.
66

7-
## Domain
7+
The particular set of mixins in an object defines its *type*. An object mutation (adding or removing mixins) changes the objects type.
88

9-
## Object
9+
"Type", as mentioned above, has nothing to do with the concept of type in C++. A `dynamix::object` naturally always is a `dynamix:object`. "Type" in this case is a runtime concept, which contains information for the composition of an object and its interface or list of *abstract features*.
10+
11+
An object *has* mixins and *implements* features.
1012

1113
## Object Type
1214

15+
The type is basically a list of mixin infos, which is used to create objects. It also has indexes to those infos and a materialized index of *features* called a `ftable`. Thus looking up concrete mixins and features in a type (or object) is always O(1).
16+
17+
The object type is ordered. A type composed of mixins `{a, b, c}` is different from a type composed of `{b, a, c}`.
18+
19+
The type provides utitliy functionalities to make these lookups and other queries.
20+
21+
Like the object, the type *has* mixins and *implements* features.
22+
23+
## Mixin
24+
25+
A mixin is the building block of types and objects. It not a specific type, but a definition. It the jobs of the library's users to define their own mixins.
26+
27+
Once you have mixins, you can combine them into objects. Adding or removing mixins will internally allocate and instantiate them, and destroy them. This means that a mixin instance is bound to an object instance. Objects cannot share mixin instances and only a single instance of a specific mixin can be part of an object.
28+
29+
You can loosely think of mixins as the parents of a class in a multiple inheritance scenario.
30+
31+
Mixins are defined through [`mixin_info`](../../code/dnmx/mixin_info.h). Utilities exist for common ways to define it. In the vast majority of cases a mixin will be defined as an existing type (`class` or `struct`).
32+
33+
The mixin *provides* feature implementations.
34+
1335
## Mixin Feature
1436

37+
The mixin features are a list of abstract features which are provided by a mixin to a type. Using the multiple inheritance example from above, much like a class inherits methods, static members, and typedefs from multiple parents, types and objects obtain the *abstract mixins features* of the mixins they are composed of.
38+
39+
A feature is a definition. A *feature implementation* is a provided by a mixin. An implementation on its own is nothing but a completely type erased (`void`) pointer.
40+
41+
DynaMix provides some feature types, and others can be created by the users. Defining a feature type would involve creating utility functionalities which reify the feature to what it needed.
42+
1543
### Bid and Priority
1644

17-
### Message
45+
Features have two signed integer properties, called bid and priority which are used to sort them in the `ftable`. If a feature is provided by a single mixin in a type, bid and priority are ignored, but if many mixins provide the same feature, they are used to disambiguate.
46+
47+
Bid is the major sort key. The higher the bid, the earlier the feature will be added in the `ftable`. Features with a higher bid (say 34) *overrides* features with a lower bid (say -5).
48+
49+
Priority is used as an additional sort key for features with the same bid. It is however treated with the oposite value. The smaller the priority, the earlier the feature will be added in the ftable. With a same bid, a feature with a smaller priority (say -1) *precedes* features with a bigger priority (say 10).
50+
51+
When bid *and* priority are the same, the order in which the implementations appear in the `ftable` is the opposite of the mixin order in the type. The last mixin in the type will add the first features in the `ftable`.
52+
53+
### Messages
54+
55+
Messages are a feature type provided by the library for the C++ interface. The term "message" here is used in the same way as it is in Smalltalk or Objective C. The message is what is called, while the method is what is executed.
56+
57+
The message implementation is a function.
58+
59+
A message is a feature which is associated with function. Calling a message for an object, will lead to a function being executed with the mixin which provided it as a first argument or, if the mixin is associted with a C++ type, it can lead to a method of that type being executed.
1860

1961
#### Multicast
2062

63+
Multicast messages make use of bids and priority to execute all top bidders in the ftable for a single message call.
64+
2165
## Mutation
2266

67+
Mutations are what is used to compose types and change object types.
68+
69+
This is basically a way to add, remove, or reorder the mixins in a type.
70+
71+
Type mutations work on types, while object mutations can work on an object and its type at the same time.
72+
2373
### Mutation Rule
2474

75+
Mutation rules are functions which are applied to all mutations in a domain. The most common case would be to associate a mixin with another, but they can do anything for example prevent mixins from being added, or replacing mixins with others.
76+
77+
The library offers some mutation rules, but users can define their own.
78+
2579
## Type Class
80+
81+
A type class is a boolean function for a type. It can be used to categorize objects based on their mixin or feature composition.
82+
83+
## Domain
84+
85+
The domain is a library instance of sorts. The domain contains registries for mixins, features, and types (but not of objects!) and should be used to contain a specific, well... domain of use of DynaMix.
86+
87+
It is not possible to create types or objects using mixins from different domains.

doc/overview.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,52 @@
11
# Overview
22

3-
DynaMix is a new approach to dynamic polymorphism. It is a library which allows the composition of polymorphic objects at run time. The objects are composed of building blocks called *mixins* which provide *abstract features* to the objects and allow client code to make use of them while remaining oblivious to the concrete composition.
3+
DynaMix is a new approach to OOP and dynamic polymorphism. It is a library which allows the composition of polymorphic objects at run time. The objects are composed of building blocks called *mixins* which provide *abstract features* to the objects and allow client code to make use of them while remaining oblivious to the concrete composition.
44

5-
The result is similar to [multiple inheritance in C++](https://www.learncpp.com/cpp-tutorial/multiple-inheritance/), but more closely resembles [mixins in Ruby](https://www.tutorialspoint.com/ruby/ruby_modules.htm), [Dart](https://dart.dev/language/mixins) and [Scala](https://docs.scala-lang.org/tour/mixin-class-composition.html), traits in [Self](https://handbook.selflanguage.org/2017.1/glossary.html), [PHP](https://www.php.net/manual/en/language.oop5.traits.php), and [others](https://en.wikipedia.org/wiki/Trait_(computer_programming), the [roles in Perl](https://docs.raku.org/language/objects#Roles) or [inheritance in Eiffel](https://www.eiffel.org/doc/eiffel/I2E-_Inheritance).
5+
The result is similar to [multiple inheritance in C++](https://www.learncpp.com/cpp-tutorial/multiple-inheritance/), but more closely resembles [mixins in Ruby](https://www.tutorialspoint.com/ruby/ruby_modules.htm), [Dart](https://dart.dev/language/mixins) and [Scala](https://docs.scala-lang.org/tour/mixin-class-composition.html), traits in [Self](https://handbook.selflanguage.org/2017.1/glossary.html), [PHP](https://www.php.net/manual/en/language.oop5.traits.php), and [others](https://en.wikipedia.org/wiki/Trait_(computer_programming), the [roles in Perl](https://docs.raku.org/language/objects#Roles) or [inheritance in Eiffel](https://www.eiffel.org/doc/eiffel/I2E-_Inheritance).
66

77
It must be noted that the library is a means to create a project's *architecture* rathern than implement its purpose. The library doesn't *do* anything, but introduces idioms and a paradigm by which one can create the interface for what's being done. In a way it can be viewed as a language extention rather than a utility.
88

9-
It can be compared to [COM](https://en.wikipedia.org/wiki/Component_Object_Model) which is a library that introduces more orhtodox (in the style of Java or C#) type of dynamic polymorphism to C. This documentation has a [list of more comparisons](misc/dynamix-vs-x.md) of DynaMix to existing solutions.
9+
It in this regard it can be compared to [COM](https://en.wikipedia.org/wiki/Component_Object_Model) which is a library that introduces more orhtodox (in the style of Java or C#) type of dynamic polymorphism to C. A [list of more comparisons](misc/dynamix-vs-x.md) of DynaMix to existing solutions is available.
10+
11+
## Library name
12+
13+
DynaMix is a portmanteau which stands for "dynamic mixins".
14+
15+
In C++ circles the term "mixin" has gained some popularity. In this context a mixin is a building block for a type, which interacts via other building blocks via [CRTP](https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern). This is a way to accomplish static polymorphism and everything is resolved at compile time.
16+
17+
The purpose of DynaMix is to accomplish something very similar, but at run time, in a dynamic manner, and hence the name is Dynamic Mixins.
1018

1119
## Key library features
1220

21+
* Compose objects from mixins at run time
22+
* Physically separate interface and implementation
23+
* Non-intrusive – mixins don't need to have a common parent or any special code inside
24+
* Mutate "live" objects by changing their composition at run time
25+
* Use `std::polymorphic_allocator` to allow fine-tuning allocations and achieving cache locality in critical parts of the code
26+
* Create shared libraries and plugins which can enrich or modify objects without modifying (or even rebuilding) the executable.
27+
* Add "hotswap" to a project while developing
28+
* Have complete runtime reflection by symbols or strings
29+
* Messages:
30+
* Fast polymorphic calls – comparable to `std::function`
31+
* Allow multicast messages – ones that are handled by many mixins within an object
32+
* Thread safe message calls – as thread safe as the underlying methods.
33+
34+
In classic OOP terminology, DynaMix is a solution with the following features:
35+
36+
* Dynamic type composition
37+
* Runtime polymorphism
38+
* Singular dispatch
39+
* Open methods
40+
* Late binding
41+
* Multicast
42+
* Reachable overrides
43+
1344
## When (and when not) to use DynaMix
45+
46+
The more complex the objects in a piece of software are, the more beneficial it will be to use the library. Pieces of software that typically have very complex objects include games (especially role-playing ones or strategies), CAD systems, enterprise systems, UI libraries, and others.
47+
48+
As a general rule of thumb: if you need complex polymorphic objects, DynaMix is a likely good choice.
49+
50+
We should emphasize on the polymorphism. In many very high-performance systems polymorphism is avoided at the cost of code that is (at least somewhat) harder to write and maintain (this is most often the case with high-end games). Since such systems will try to "squeeze" every possible piece of processing power out of the CPU, cache locality and lack of cache misses are critical in some parts of their code. As is the case with all instances of polymorphism, including C++ virtual methods and `std::function`, uses of DynaMix will almost certainly lead to cache misses. Of course, you may still rely on the library in other parts of your code, like the business (or gameplay) logic. For more information about the library performance, see [Performance](working-with/perf.md).
51+
52+
Of course, small projects with simple objects, even if they are polymorphic, may end up not finding any particular benefits in using the library, since their size makes them fast to compile and easy to maintain as they are. If a piece of software can be created in a couple of days, by one or two programmers, there will hardly be any need for DynaMix.

doc/roadmap.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ Here's a list of notable planned new features and updates for DynaMix
1616
* Demo: lua integration
1717
* Demo: JS and wasm integration
1818
* Possibly never, but sounds nice
19+
* Lazy mixin registration
1920
* Create a preprocessing tool (like Qt's moc) that can be used instead of the macros for mixin and feature definition

0 commit comments

Comments
 (0)