Language Idea

Modules

Modules are similar to namespaces in C-plus-plus and C-sharp or modules in D. They are used to organize code and declaration names and assist visibility. Modules can be nested. When no module is given, the code gets compiled automatically into a module with the same name as the source. Otherwise nothing is allowed outside modules. Best is to show some code snippets to assist understanding.

module FirstModule {

	int SIZE = 10;

	assert(SIZE == 10);

	assert(FirstModule.SIZE == 10);
	assert(SecondModule.SIZE == 20);
}

module SecondModule {

	int SIZE = 20;

	assert(SIZE == 20);

	assert(FirstModule.SIZE == 10);
	assert(SecondModule.SIZE == 20);
}

module ThirdModule {

	using FirstModule;
	using SecondModule;

	assert(SIZE == 0)
	// abigousity error
}

Note the using keyword in the FourthModule. In this example I show the nesting behaviour. As expected, the base module does not see the sub module members, while the sub module can see the base module members. Also note that modules can be written in multiple parts and sub modules can be declared with the dot.

module SubModule {

	int a = 10;
	int b = 20;
}

module FirstModule {

	int c = 30;

	module SubModule {

		int a = 50;

		assert(b == 20);
		assert(c == 30);
	}

	assert(SubModule.a == 10);
	assert(SubModule.b == 20);

	assert(FirstModule.SubModule.a == 50);
	assert(FirstModule.SubModule.b == 60);
}

module FirstModule.SubModule {

	int b = 60;

	assert(a == 50);
	assert(c == 30);
}

So looking up a symbol is done in this order: Search in current module, then search in base modules, then search in used modules, then search in used modules base modules. In case more used modules on the same nesting level contain the symbol, an ambigousity error occures.

Tradicional Class Concept

As in usual object oriented languages, there are interfaces and classes. They have members and methods, and classes can inherit from one other and they can implement intefaces. The usual visiblities exist on class and module level and they can be written before the member or as a block.

Methods are coded inside the classes body. They get an implicit this parameter when not declared static. The virtual keyword makes them to be dispatched runtime based on the this argument and maybe others. Interfaces can declare but not implement implicitly public abstract methods.

interface Bar {

	void doSomeThong(int argument);
	// asks implementing classes to implement it

	void doOtherThing(double argument);
	// asks implementing classes to implement it
}

Methods can be normal, override, virtual or abstract. Abstract methods can not be implemented and private abstract methods are not allowed. Overriding methods have to use the override keyword and they will carry the overriden methods visiblity. Abstract, virtual and override methods can only be overriden.

class One {

	public void doSomeThing(int argument) {
		// here goes an implementation
	}

	public virtual void doOtherThing(double argument) {
		// here goes an implementation
	}

	public abstract void doThirdThing(bool argument);
	// asks inherited classes to implement it
}

class Two : One {

	public void doSomeThing(int argument) {
		// no runtime dispatch here
	}

	override void doSomething(int argument) {
		// not allowed to override
	}

	public void doOtherThing(double argument) {
		// not allowed without override
	}

	override void doOtherThing(double argument) {
		// here goes an implementation
	}

	override void doThirdThing(bool argument) {
		// here goes an implementation
	}

	override void doLastThing(bool argument) {
		// override not allowed
	}
}

Radical Class Concept

In many languages it is allowed to call any function with the method call syntax. This can result readable code in some cases. Also somtimes methods are not declared or implemented in the class body. See the Nim language. We could simply forget about methods and let functions to be virtual based on their polymorphic parameters. Then writing functions inside the class would only add implicitly the this parameter and its members.

We either let private members to bee seen in the same module or the module visibility should be added. Visibilities could also be manipulated on module level. So either private and public or module and public could be used outside classes.

class A {
	private or module:

		int x;
		int y;
}

class B : A {
	private or module:

		int u;
		int v;
}

virtual void addassign(A one, A two) {

	one.x += two.x;
	one.y += two.y;
}

virtual void addassign(A one, B two) {

	one.x += two.x + two.u;
	one.y += two.y + two.v;
}

virtual void addassign(B one, A two) {

	one.x += two.x;
	one.y += two.y;

	one.u += two.x;
	one.v += two.y;
}

virtual void addassign(B one, B two) {

	one.x += two.x;
	one.y += two.y;

	one.u += two.u;
	one.v += two.v;
}

void test() {

	A one = new B();
	A two = new B();

	addassign(one, two);
	// calls the last

	two.addassign(one);
	// calls the last
}