Need planning for Cobra (my opinion)
Posted: Fri May 29, 2009 10:17 pm
I apologize for the length of this post. Further I apologize if I step on any toes or cover material already trodden (I've only been aware of Cobra for three weeks now so I don't know everything that's been done/previously discussed). I just wanted to get discussion and planning started.
As Cobra approaches a version 1 release, I think there are some things that need to be worked out:
1) Front End - Back End architecture
2) Portability of Cobra programs (Cobra libraries)
Topic 1: Front End - Back End architecture
The whole idea of adding back ends to Cobra is really cool. If the language takes off, I think you can expect back ends to developed as projects independent of the compiler (really this means independent of the front end as you can't have a compiler without a front and a back end). This is totally natural. Just look at Python. The reference implementation is CPython but the ports to .NET (IronPython) and the JVM (Jython) is sort of equivalent to a new back end for Cobra. There's even CLPython which compiles Python programs into executables via Common Lisp (I haven't tried it yet, but I love the idea).
In order to allow easy integration and creation of new back ends, there needs to be a document that specifies the language (versioned and tied to the front end) and a document that describes how to implement a back end (especially in terms of dealing with the front end and what it is required to be there outside the code generation as well as how to bootstrap a new back end). A versioned front end allows the back end to say what version(s) of the front end it will work with (and that essentially means what version(s) of the language it supports). I envision that the front end will have basically three phases: tokenizing, parsing, and validation (like an XML validator, it would make sure the program was well-formed....note: this does not mean correct). The back end would do the rest. The main reason that the front end wouldn't do more is because it wouldn't be aware of the specific platform's APIs (and it shouldn't be).
The question is how would the front end and back ends be compiled? Would the front end be one executable (and which back end would you build it with...probably multiple ones) and the back end another? Or would you build one executable for each platform (in that case the back end could basically be a library...or the front end could be....but probably not since you'll want basically the same switches available no matter the platform)?
Also from a command-line perspective, what about building libraries and linking statically or dynamically (passed on to the back end)? Include/source directories?
Topic 2: Portability of Cobra Programs
Obviously it is very important to allow access to platform-specific libraries. However, writing portable programs is important too. This portablilty is obviously achieved with having standard parts to the language (especially the standard library). Picking the contents of the standard library greatly impacts what Cobra third party libraries get written. I would suggest that part of the standard library is written in Cobra and comes with the front end and is pulled from a common directory by the back end. Other parts will be implemented in a platform-specific manner (possibly with the use of third-party libraries like CPython using tkinter) and will be provided by the back end. I'm thinking Cobra.Core for pure Cobra stuff, Cobra.Standard that will mix Cobra with native platform implementation and Cobra.StandardExtended that is most likely pure native platform implementation. Also a back end would have to provide all of Cobra.Standard to be considered a basic Cobra platform. Implementing Cobra.StandardExtended would allow it to be considered a full-featured Cobra platform. For example, sorting algorithms might be in Core or Standard while Web and GUI namespaces might be in StandardExtended. The GUI one makes a good example: it could be implemented with WinForms in .NET/Mono, with Swing on the JVM, with Cocoa for Objective-C, and with a third-party library (such as Qt or something built on top of SDL) for C++.
Conclusion
Basically planning on these issues needs to be done. This planning should be captured in some sort of documentation. Obviously it's too early to have to make everything a change proposal (or PEP like Python), but certainly planning and design documentation would be good things.
As Cobra approaches a version 1 release, I think there are some things that need to be worked out:
1) Front End - Back End architecture
2) Portability of Cobra programs (Cobra libraries)
Topic 1: Front End - Back End architecture
The whole idea of adding back ends to Cobra is really cool. If the language takes off, I think you can expect back ends to developed as projects independent of the compiler (really this means independent of the front end as you can't have a compiler without a front and a back end). This is totally natural. Just look at Python. The reference implementation is CPython but the ports to .NET (IronPython) and the JVM (Jython) is sort of equivalent to a new back end for Cobra. There's even CLPython which compiles Python programs into executables via Common Lisp (I haven't tried it yet, but I love the idea).
In order to allow easy integration and creation of new back ends, there needs to be a document that specifies the language (versioned and tied to the front end) and a document that describes how to implement a back end (especially in terms of dealing with the front end and what it is required to be there outside the code generation as well as how to bootstrap a new back end). A versioned front end allows the back end to say what version(s) of the front end it will work with (and that essentially means what version(s) of the language it supports). I envision that the front end will have basically three phases: tokenizing, parsing, and validation (like an XML validator, it would make sure the program was well-formed....note: this does not mean correct). The back end would do the rest. The main reason that the front end wouldn't do more is because it wouldn't be aware of the specific platform's APIs (and it shouldn't be).
The question is how would the front end and back ends be compiled? Would the front end be one executable (and which back end would you build it with...probably multiple ones) and the back end another? Or would you build one executable for each platform (in that case the back end could basically be a library...or the front end could be....but probably not since you'll want basically the same switches available no matter the platform)?
Also from a command-line perspective, what about building libraries and linking statically or dynamically (passed on to the back end)? Include/source directories?
Topic 2: Portability of Cobra Programs
Obviously it is very important to allow access to platform-specific libraries. However, writing portable programs is important too. This portablilty is obviously achieved with having standard parts to the language (especially the standard library). Picking the contents of the standard library greatly impacts what Cobra third party libraries get written. I would suggest that part of the standard library is written in Cobra and comes with the front end and is pulled from a common directory by the back end. Other parts will be implemented in a platform-specific manner (possibly with the use of third-party libraries like CPython using tkinter) and will be provided by the back end. I'm thinking Cobra.Core for pure Cobra stuff, Cobra.Standard that will mix Cobra with native platform implementation and Cobra.StandardExtended that is most likely pure native platform implementation. Also a back end would have to provide all of Cobra.Standard to be considered a basic Cobra platform. Implementing Cobra.StandardExtended would allow it to be considered a full-featured Cobra platform. For example, sorting algorithms might be in Core or Standard while Web and GUI namespaces might be in StandardExtended. The GUI one makes a good example: it could be implemented with WinForms in .NET/Mono, with Swing on the JVM, with Cocoa for Objective-C, and with a third-party library (such as Qt or something built on top of SDL) for C++.
Conclusion
Basically planning on these issues needs to be done. This planning should be captured in some sort of documentation. Obviously it's too early to have to make everything a change proposal (or PEP like Python), but certainly planning and design documentation would be good things.