3 ms·
I have no experience building languages, but as someone who has to build relatively performant code and longs for a clean, DRY language, I completely agree with
by stephth 15y ago
I have no experience building languages, but as someone who has to build relatively performant code and longs for a clean, DRY language, I completely agree with you about picking a target language that closely fits the semantics. Rolling out your own libraries and runtime seems like a gargantuan endeavor too likely to fail, and portability (not to mention performance) will likely suffer.
I think the CoffeeScript approach is the way to go: syntactic sugar that generates human readable code. I'd be happy to have an elegant language that would compile to C++ simply adding some DRYness and elegance (for example not having to write headers), but without trading it for performance/portability (for example without abstracting pointers or new/delete). I would happily use a subset of C++ if required.
This in C++:
// in file MyClass.h //////////////
class MyClass: public ParentClass
{
public:
int myInt, myInt2;
float myFloat;
Arr *myArr;
MyClass() { }
MyClass();
void doStuff();
};
//in file MyClass.cpp //////////////
#include "MyClass.h"
MyClass::MyClass()
{
self->doStuff();
int poop = 321654987;
myInt = 112233 * poop;
{
// new scope here
}
}
void MyClass::doStuff()
{
int myNum = 123;
poop *= myNum;
}
Could relatively easily be generated from this syntactic sugar:
class MyClass < ParentClass
int myInt, myInt2
float myFloat
Arr *myArr
void initialize(args)
self.doStuff()
int poop = 321654987
myInt = 112233 * poop
// new scope here
void doStuff()
myNum := 123;
poop *= myNum;
And wouldn't generating such readable code bypass the need for a debugger?
- sea6ear 15y agoI think Cython/Pyrex might be cool for this. Python(ish) syntax that generates C code when run through the compiler. I wonder how hard it is for that generated code to be portable, or if it is already optimized for the architecture that the Cython/Pyrex compiler is run on.
- stephth 15y agoIf I understand correctly, Cython generates C code that still depends on a Python runtime.
- sea6ear 15y agoAh, it looks like you are correct. Perhaps shedskin would work better for this idea, except for the fact that it produces C++ rather than C. Added: Also, I missed that you were talking about creating human readable C++. I'm not at all certain that shedskin produces C++ that is readable.
- stephth 15y agoI could live without human readable code, that was more about bypassing the need for an intermediate debugger; and readable code is a good proof that the language doesn't try to do too much. Shedskin looks like a very cool project, and it's quite fast [1], thanks for the tip. Alas, it depends on a garbage collector (not to mention a substantial library), which reduces flexibility and portability - you can't for example build a portable C++ library with it. [1] although not as fast as C, or even V8 js: http://attractivechaos.github.com/plb http://attractivechaos.github.com/plb