Hi guys,
Well this is meant as a little introduction for those who haven't heard about eC yet...
eC is yet another multiparadigm procedural/object-oriented language which has C for its foundation.
This puts it alongside Java, C++, C#, D, Objective C and probably countless others less famous programming languages.
Now you probably wonder what makes eC of any interest... And this is what I will try to demonstrate.
C COMPATIBILITY
Unlike all the other languages aforementioned (with the exception of Objective C), eC goes to great lengths to maintain the full usability and compatibility with C. Although Objective C maintains absolute full C compatibility because it does not introduce new keywords which might conflict with identifiers (such as 'class'), the Objective C syntax will look unfamiliar to a programmer of of the other C-like languages). eC offers the familiar syntax, with yet an excellent compatibility support.
What this means:
- You can include C library headers directly in your .ec code, without any special keyword (like extern "C" in C++)
- There is no special mangling going on for normal functions (C binary compatibility), which means you can interface in both directions with any language supporting C bindings.
- Simply put, eC does not take anything away from C, it only adds useful features to it
ELEGANT AND SIMPLE OO
The presence of pointers everywhere for handling objects allocated on the heap in C++ is a bit cumbersome at best. The use of the & declaration specifier to pass objects by reference is also somewhat confusing... What eC proposes is an elegant syntax similar to that of Java or C#, yet keeping the power and flexibility of C pointers behind. It also offers different tools for different usages which will automatically be passed appropriately, either by value or by reference.
A particular instantiation syntax is used in eC. Say you wish to instantiate a MessageBox:
MessageBox hello { };
In this case, 'hello' is the name of the instance (it is actually a pointer, as the MessageBox is a class allocated on the heap). 'MessageBox' is the name of the class to be instantiated. Note that we didn't have to explicitly declare hello as a pointere here. The equivalent C++ declaration to the above would be:
MessageBox * hello = new MessageBox();
Now if we simply wanted to declare a handle to the object, we would simply write:
MessageBox hello;
This would not result in any instantiation taking place.
hello could then be assigned a newly instantiated MessageBox as such:
hello = MessageBox { };
Because the concept of a pointer is a rather low level construct of directly accessing memory, it shouldn't be in the way of the every day object oriented paradigm. You don't need to learn about pointers to use the object oriented constructs in eC efficiently, but they are still there if you ever need them. Instead of the C++ hello->Modal(), function calls on instances is simply:
hello.Modal();
Furthermore in eC there is very little to no requirement to use header files, and it offers great control of what is exposed outside of a an API. (eC was designed primarily to build API/class libraries).
ALTERNATIVE FOR OVERLOADING: CLEAR EXECUTION POINTS
In order to easily find your way in the code, eC encourages clear single execution points for a particular action. Therefore only one constructor can exist in an eC class, and functions cannot be overloaded for different data types. However eC offers great alternatives which makes for very readable code:
MessageBox hello { contents = "Hello, World!!" }; // This is a full GUI hello world program if you add import "ecere" at the top
Inside the instantiation syntax brackets, both data members and properties (member assignment which can execute code, with set/get methods) can be assigned, either anonymously (following the proper ordering), or by name.
This replaces the use of constructors taking various parameters.
eC has a powerful data type system (where everything is in fact an object: all data types are a form of class). One nice feature is a construct which allows a function to accept any type of parameters, let's see for example what you can do with the builtin PrintLn function:
int a = 2, b = 3;
PrintLn("a = ", a, " b = ", b, " a + b = ", a+b);
Here we just passed PrintLn a mix of integers and strings and will be able to print all of these properly.
DYNAMIC TEMPLATES
The generic system of eC is unique in that a class template is in fact not different than a regular class. The templates in eC were designed primarily for building the containers classes, and there is currently no "function" templates, only classes. It is compiled only once, but is made adaptable to any parametrization which can occur later on in the future, for example with data types which didn't exist at the time the template was compiled. This allows templates to be bundled within a shared library, and lets you use templates with new data types which can even be loaded at runtime from a plugin in the form of a shared library.
Here's an example where class A inherits from a class B parametrized with itself (class A):
class A : B<A> { int a; }
class B<class T> { T test; }
Here's some examples of the templates/containers in action:
Arrays:
Array<int> array { [ 1, 2, 3 ] };
for(i : array; i > 1) PrintLn(i);
Iterators:
Iterator<int> i { array };
while(i.Next()) PrintLn(i.data);
Maps:
Map<String, int> wordCounts { };
wordCounts[s]++;
The Ecere SDK
One of the thing that makes eC great is what it was built for: the Ecere SDK. It includes a cross platform GUI toolkit (an alternative to wxWidgets/GTK/Qt...), 2D/3D graphics engine, networking engine, an IDE and much more... eC was designed simply because no other languages suited the goals of the projects.
The Ecere SDK including all the eC compiling tools are now all open source under a revised BSD license, which means you can do pretty much anything you want with it as long as derived works tags alone the original copyright and BSD license with it.
For screenshots of Ecere in action checkout http://www.ecere.com/action.html.
Feedback welcome
Cheers
A little introduction to eC
Re: A little introduction to eC
this is a BIG help for new users on C, eC also in programming! (like me)
Thank you jerome!
Thank you jerome!