C* (C Star)
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language.
C++ support multiple programming styles like procedural programming (similar to C), object-oriented programming and generic programming (templates).
C* focus on procedural and object-oriented programming, inspired by Embedded C++.
The following language features have been removed in Embedded C++
- Multiple inheritance
- Virtual base classes
- Run-time type information (typeid)
- New style casts (static_cast, dynamic_cast, reinterpret_cast and const_cast)
- The mutable type qualifier (used on class data member to make modifiable even if member part of
const object)
- Namespaces
- Exceptions
- Templates
The only exception to this list for C* is the use of namespaces for better organization of the code. Bjarne Stroustrup (C++ inventor) also wanted to keep this, as it gives no runtime overhead in space or speed.
Removing the use of templates is probably the decision with the biggest consequences. Templates are very powerful, and can give you extra performance if used correctly. The standard template library also gives you many useful utility classes. However, templates are very complex, are very different from the "traditional" C/C++ syntax, and very often increases the compilation time significantly.
By removing the generic programming (templates), using object-oriented programming for the AI Framework primarily, and using procedural programming (using framework objects) in the application code, the development is simplified and more focused.
To obtain the fast feedback cycle of scripting languages we removed templates and optimized the organization of the
source/header files. Changing a single file and re-compiling is performed in less than 2 seconds, giving a very fast feedback cycle.
In addition to removing C++ features, the C* "language" has some other additions and features like:
- Command Guards: Wrapping individual commands with commands like aia and aib to automatically
check for error codes and jump to error handling or cleanup.
- Design by Contract: Using pre- and postconditions to verify that required conditions are met for
running a procedure, and verify that the procedure did what it was supposed to do before exiting.
- Aspect-oriented programming (AOP): AOP is used for cross-cutting concerns such as identification
of each module, automatic tracing and logging, error handling and additional metadata when
debugging. AOP is used for inspiration and as a convention, meaning it is fixed rather than dynamic (to avoid the downsides of AOP).
- Error handling using error codes and conventions (aih, aie, AIE, AICleanup etc) to make it easier to use and more consistent.
The AI Framework
Inspired by the research done for Python and other scripting languages, the AI Framework is a very ease-to-use wrapper for Win32 that provides higher-level abstraction and "requires less code to do more".
The AI Framework also provides three powerful datatypes for strings, lists and maps/dictionaries that are often used in scripting languages (and which are also in the removed Standard Template Library).
Example code (AI Framework level – lower level code):
Notice the use of colors in the code. There is one example bug here – it should be very easy to spot due to the use of colors.
Comments are very subtle and "out of your way" because of the dark color.
AIA (assertion) is a Design by Contract pre-condition that must be valid and will result in an error if not. In this example it is acceptable with an empty in-string, so we use AIB (barrier) instead of AIA to jump out of the function without an error.
aih will check the handle, and aie will check error codes and jump to error handling if incorrect. AIE is shorthand for an empty AIErrorhandling (and AIC is shorthand for an empty AICleanup).
Example code (C* level (application) – higher level code)
If you look at the two code samples, you’ll notice that they’re a bit different. The first example communicates directly with Win32 (CreateFile, ReadFile etc) and uses additional error checking and handling (AIA, aih, aie, AIE, AICleanup) that the second example does not use.
The first example is part of the AI Framework, and it is therefore very robust and error-safe.
The second example is the "application code", and is easier to use and read. It uses the powerful datatype AIString, the standard object Ribbon, the global variable structure r (r.Zoomsize) for registry values, the global ribbon control font_zoom_list (g.ribbon.font_zoom_list) and calls the function refresh which is part of the Main::editor namespace.
It also calls the Win32 function UpdateWindow directly (it could have used winApp.Form.Update () instead, but this demonstrates that you can use Win32 directly if you want to). In addition, it uses the built-in macro is which is used for emulating named parameters (the order of the arguments is still important, but it makes it much easier to describe what a certain parameter means).
The combination of C* "language"/embedded C++, AIFramework, standard objects and use of conventions results in an "emulated" Very High-level language enabling great programming productivity combined with the speed of C/C++.
External links
- Teach yourself programming in Ten years
- Language Wars (Joel On Software)
- Wasabi (Joel On Software)
- Succinctness is power (Paul Graham)
- Making wrong code look wrong (Joel On Software)
- Objecting to Objects
- What makes a good programming language ?
- If programming languages were cars... (fun)