Ferite, Why?

Ferite is a scripting language, the creators describe it as follows:

ferite is a scripting engine and language written in c for complete portability. For more information please see the about page. We have finally reached a 1.0 release — this has only taken us since Summer 2000 to get here so far.

ferite is a clean language with influences from various places: objects from Java/C++, functions from C/php, closures from scheme, block calling from ruby, namespaces from C++, as well as its own a sane loose typing mechanism, variant type and set of nice APIs. Here is an example:

uses “console”;
Console.println( “Hello World” );

This is the famous “Hello World” program in ferite, to see more examples have a look at this example page. To view the scripts click on the version number. ferite features a wealth of features including explicit global variables, namespaces, normal functions, exception handling, perl like regular expressions, variable argument lists, plus all sorts of other goodies to provide a pleasant programming experience.

So, yet another scripting language, waiting to revolutionize the world of programming huh? I was a bit sceptical, so I decided to have a closer look.

Ferite adopts a syntax that is Java/C++-like, so the curly braces and the semi-colons are there, for all those that love them. Ferite is not a purely object-oriented language, sadly. It mixes the object-oriented and linear programming paradigms, just like for example C++ and PHP. The language reference can be found here.
Something I noticed while reading through the section about comments in ferite, is something I like. They allow nested commenting, like this:

/*
/* Print out some information */
Console.println( "Today" );
*/

I like that, quite often in a language like Java you want to comment out a whole section of code which is a bit hard when it contains comments itself. Nested commenting is a nice feature that solves this problem.

Types

Ferite is a bit of a typed language. I say a bit because it handles typing in a strange, inconsistent way, in my opinion, or at least I don’t see the consistency. Ferite forces you to declare types of variables and arguments of functions. Great. But look at this:

// This is all ok
number n = 3;
string s = "bla";
// But look at this:
array a = [n, s, 232];
// or this:
object o = new MyClass();

That looks very odd to me. Ferite has only 5 types, they are number, string, array, object and void. The first two are called “simple types”, the others “complicated types”. It turns out that the classes you define are not types they are just, well, classes. So you cannot write:

MyClass o = new MyClass();

Huh? Another thing I think is odd that they force you to type your variables, but when you define a variable as an array you don’t have to tell ferite an array of what, just saying it’s an array is fine. Is it an array of strings, numbers, objects? All of the sudden it doesn’t seem to matter. But there are more gaps, you define a function like this:

function foo( string bar ) {
bar += "foo";
return bar;
}

Notice something odd here? I do, where’s the return type of the function? There is none. The typing of the language is supposed to help you debug, and it might, a bit. But I feel the typing support is paper-thin. In a language like Java, the whole thing can be type-checked, if it compiles you eliminated a whole lot of typing mistakes (pun intended), but you cannot do such checks in ferite, because the typing is only required on some places.

function foo2( string bar ) {
/* Secret */
}
number a = foo2("Zef"); // Is this allowed?
array ar = [1, 2, "Pete"];
foo2(ar[0]); // Allowed? No, ferite will only know at runtime
foo2(ar[2]); // Allowed? Yes

I think it’s quite odd. But one thing I have to say, requiring function parameter typing does allow you to do function overloading:

uses "console";
function print( number n ){
Console.println( "Number: $n" );
}
function print( string s ){
Console.println( "String: $s" );
}
print( 10 );
print( "Hello World" );

Now if only I could also distinguish between my classes, like this:

function print( MyClass s ){
Console.println( "MyClass: ${s.getName()}" );
}

But as far as I understand, I can’t, MyClass is not a type.

If you wondered what the void type is, it’s a place-holder type. It can be turned into any of the other four types by assigning a value to it, once it has been assigned the type cannot be changed anymore:

void v = 3; // Now it's a number
void v2 = "Zef"; // Now it's a string
v = v2; // Not allowed!

Operators

Ferite adopts most of Java/C++’s operators like +, -, /, %, ++, — etc. For array slicing, however, they do something, in my view, incomplete. Ferite allows you do array slicing, like this:

string s = "Hello";
string t = s[-1..0]; >> a slice of the entire string and reverse it
string u = s[..2]; >> a slice of the first 3 characters in the string s
array a = [ 1, 2, 3 ];
array b = a[1..]; >> a slice of a containing [ 2, 3 ]

But from the documentation I don’t get the impression you can also assign values to slices, they are read-only. In Python you can do something like this:

ar[2:4] = [3, 2]

But not in ferite.

Control structures

The control structures in ferite are pretty much Java and C++’s. With the exception of the very peculiar exception handling (that is for the rest not described):

iferr {
statements
} fix {
statements to clean up in case of an exception
} else {
statements if no exception has occurred
}

As I understand it, the iferr functions like Java’s try and the fix is a catch(Exception e). The else is executed when no exception occurs, there is no equivalent of Java’s finally. From a naming standpoint I think this is odd. If I felt I had to change the keywords in this construct (and I really don’t see why), I would’ve called the fix iferr, not the the try. Like this:

try {
statements
} iferr {
statements to clean up in case of an exception
} else {
statements if no exception has occurred
}

Logically this makes more sense to me. “Try this and if error (iferr) do this, else do that.” Right? The question that remains is where you get more information about the exception that occured, and how you throw an exception. This is not described in the language manual, but in the beginning of the manual, when they talk about global variables. They say there is a variable called err used for exception handling, hmm. That sounds very dangerous and not thread-safe.

Talking about thread-safe.

Thread-safe features

The ferite manual describes some variable modifiers. Modifiers can change the behaviour of a variable, like make it a constant (which cannot be changed after a value has been assigned), another modifier is atomic:

atomic — all accesses on the variable (getting the value and setting the value) are atomic, i.e. thread safe, which means that it is unnecessary to create an explicit lock for it. It is important to note that this does have an execution time, and space, overhead to the variable and should therefore be used wisely.

Think about this for a second. What do we use locks for? Where do concurrency problems often occur? Well, when you execute code like this simultaneously:

temp = a
temp = temp + 10
a = temp

and

temp2 = a
temp2 = temp2 - 5
a = temp2

Say a = 10 to begin with. If you execute these two pieces simultaneously, what will be the value of a afterwards. Is it 15? Is it 5? Is it 20? If you don’t get it, this may help. The question is, how does this atomic keyword help with your concurrency problems? It doesn’t really, I don’t see how it helps any kind of problem to be honest.

OOP

Ferite supports the usual set of OOP features like classes, single-inheritance and interfaces, ehm I mean protocols. Protocols? Yes, protocols. They are interfaces, they just call them protocols. Why? I don’t know, people have been calling them interfaces for so long, it’s time for a change I suppose.

There are also some special methods like attribute_missing and method_missing. If an attribute is being accessed that cannot be found in the object, the attribute_missing method is activated to retrieve its value. Retrieve its value, yes, it only works for reading from non-existing attributes, not writing to them.

Ferite also allows you to change classes after they’ve been defined. There are means to add, rename, and create aliases to methods in a class. I’m not convinced of the usefulness of this, but they say it has applications, could be.

Additional features

Ferite also has support for closures and also passing them to method calls so you can do things like this:

Array.each( argv ) using ( argument ) {
processArgument( argument );
};

Which is reasonably nice. Just wished that arrays were also objects with an each method, but ok.

Conclusions

Ferite is a bit of a strange language. It’s typing system is odd and there are some more oddities. Beyond that it seems like a nice hobby project, but in no way made me want to use it for future projects. Languages like Ruby and Python seem to be far more well thought-out and consistent and are more popular. And if you’re not a curly braces and semicolon fetishist these languages seem a much better choice for those interested in learning a scripting language.

But this is just what I found and think, the best it always to have a look for yourself, go ahead, here is the website.