Strangely, I find that one of the nice features about Ruby is the lack of keywords.
In C# I tend to end up writing things like this:
public override static bool xxx (...
And then there’s ’annotations’ that tell the CLR what to do on top of that.
On the other hand, in Ruby, there are fewer keywords, but some of the traditional functions of keywords have been replaced by methods, such as private. Other ‘pseudo-keywords’ are attr_reader and attr_writer. In fact, these are methods of Module and while you can override them you do so at your peril; they function in all respects like keywords.
But I think that ’duck typing’ ought to apply to keywords as well as code - if it looks like a keyword and behaves like a keyword, then it should be a keyword. And recognised as such by the parser.
Ruby attributes are also messy in another way. A ‘writer’ attribute is indicated by an = symbol at the end of a method declaration:
def x=;... end
...while a ’reader’ attribute looks just like a normal function:
def x;... end
In Sapphire, we’re going to do something different and, we believe, more logical. First, all instance variables will have a read and write accessor built-in. That is, you won’t have to declare any special methods to just get and set them.
So if I declare an instance variable @x in a class C, I will automatically be able to do things like this (without having to declare accessors):
a = C.new
a.x = 5
puts(a.x)
Now suppose you want to have an accessor do something more than get or set a simple value. We’ve define two keywords get and set which work in a very similar fashion to def. Like this:
get x(); @x + 1 end
set x(v); @x = v – 1 end
So get and set replace the attr_read and attr_write and the dangling = at the end of a method name. It’s more work for the parser, but it’s a whole lot clearer and neater.
For more information on Sapphire, see:
The Sapphire Programming Language - The Fundamentals
The Sapphire Programming Language: defining the grammar