Thursday, November 04, 2004

Mumbling to myself under my breath

So I've been toying with the idea of writing a complier for a really long time now. I actually really like Microsoft's CodeDOM that's part of .Net, but I got really frustrated by a couple deficiencies I found in it. For starters, there is no way to declare a function that exists as exernal - not "extern" in the C sense, but "native" in the Java sense. I don't have a problem with being unable to use language features that are not supported in a given language ("native" has no meaning in Javascript, for example), but if I want to programmatically generate code that the language supports, well, I want to be able to actually do it. I am toying with the idea of trying to make a CodeDOM of my own that fully supports msil, and throw exceptions if a given provider indicates that a language doesn't support a desired feature. Not sure on the best way to go on that.

I also want to target multiple platforms. GPCP is a flavor of Pascal that targets both .Net and the JVM, so they are a lovely example, but I also want to target Win32/x86. Clearly the way to go is to take some other language and write a compiler that targets only one of those 3, and use that as the basis to write one that can bootstrap itself. Then add other targets, refactoring as I go.

I've decided I don't like aspect oriented programming. The ability to inject behavior into a class without modifying the original class makes it impossible to determine what a given class will do without knowing the full context. I think this is a bad thing. Attributes, like Microsoft has created with .Net, are similar, but require you to inject them into the code of the class they apply to. In this situation you can tell what it's supposed to do in a given situation when you read the code in isolation. A good language exists for the code writer, not the computer or the compiler.

Generics? I probably should, right from the start. There was screaming for them right away in Java, and they only just now got them. C# didn't have them, but it will in version 2.0. Done right, they are ridiculously powerful. My only concern is that I'm not sure how to implement them in a compiler. I can see classes, interfaces, inheritance, etc., but generics sort of hurt my brain. That's just me whining, though, so feel free to ignore it. Like I said, a good language exists for the code writer. If a feature makes it easier to write good code, it should be there.

That's a good point, though. If a feature is really easy for a code writer to use improperly, it either shouldn't be in the language, or it has been implemented wrong. Pointers are really really powerful that are also easy for many people to get wrong, so you see many newer languages lacking direct access to them.

So anyway, I'll stop here for now. More later.

No comments: