Yes, SmartPascal does not support generics yet.
But it is tempered by several features of the language:
- Its awesome array support, which makes
TList<T>appear quite limited;
- The classic object pascal factory pattern of "
type of class" and virtual constructors;
- Its support of
TDoSomeThingWith<T>,or the powerful
I'm quite confident Eric Grange (the DWS/SMS compiler main maintainer) would be able to add generics support, when he would like to, and have time to refactor the compiler AST somewhat deeply.
But are generics really mandatory for a modern language?
Why is Google not willing to introduce them in their - so trendy and modern - Go language? Isn't it because of its very good list support?
Do you really think that the following code is readable, maintainable, good OOP practice:
Fn<Integer, Integer> times3plus2 =
Currying.<Integer, Integer, Integer>compose().ap(plus2).ap(times3);
I understand when Lars Fosdal, in a comment of the Google+ post, wrote that "Once you go Generics, there is no way back".
Personally, I used to spend a lot of time in C# generics and several awesome
C# libraries - pretty close to Stephan's great library, BTW - (ab)used (of)
LINQ queries, had to fight against WCF, RhinoMock, and Unity XML configuration
files, and I still prefer "classic" object pascal code, without generics.
So it was not difficult for me go find my way back.
Today, if I need something involving multiple types, I try to follow
SOLID principles, define
several small classes, and use inheritance to share as much code as
If a template system is needed for some huge part of the code, I use SynMustache, and generate code ahead of time.
If I need a factory lazy pattern for classes, I use virtual constructors, and follow the Liskov substitution principle.
If I need stubs/mocks or factories for interfaces, a
TypeInfo(IAnyInterface)reference does the job, without the
I can see almost nothing I could do with generics, which I could not do with
Yes, I agree I can't make my code look like C#, but I can still follow SOLID principles, without being lost in some language-level "design patterns", which sounds more like Lego bricks than true computer science.
It appears that my today's mind is the following.
IMHO as programmers, we should focus on data structures, not on code.
I'm sure you know the Linus' quote, and is what I learnt by reading Knuth and others, or looking at genuine pieces of software like the SQlite3 engine itself.
Of course, this is a matter of taste.
I currently spend hours in SMS for a new project, and also on latest versions of Delphi.
In short, what I like today with SMS is that:
- I can use modern object pascal to focus on my data structures;
- I can let the SMS compiler focus on the code generation.
So, with SMS, I'm an happy programmer.
Without the need of using generics.
You are welcome to comment further these ideas on Google+, which are just my today's mood and suggestive reactions, not any definitive nor