🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Tangent: Generic Method Sneak Peek!

Published November 05, 2008
Advertisement
Had the evening free to work on added implementation of generics. Generic methods are pretty much a hojillion more times difficult to implement than their class brethren. To complicate matters a bit, I'm looking to modify the standard syntax a bit to better support phrases.

There are three things that I'm looking to do with Tangent generic methods that deviates from the norm:

- Generics defined alongside the variable.

This one is kinda straightforward. Instead of public void foo(T x, T y) the declaration will be public void foo( x, y). Should make reading the things a little easier, but it's mostly done to disambiguate the syntax. Multiple declarations of the same name are the same variable (as above).

- Constraints defined alongside the generic identifier

A little less straightforward, but again, hopefully something that's not too weird. This moves the simple type constraints within the angle bracket declaration. Example:

// C#public void foo() where T:HasName { }// Tangentpublic void foo(){}


I'm not quite sure if I'll go with that syntax or more of the Identifier:Constraint style. Either way, keeping the simple stuff declared alongside the generic itself. Again, declaration closer to the usage should be a little more readable, but the gain is mostly in aiding phrase usage.

- Types as params

Speaking of phrases, I'd like to allow type parameterization in phrases more naturally. print foo to string instead of print foo.ToString() or even print foo to(). This will aid in consistency within the language, allow for more straightforward specializations, and aid in the psuedo DSL programming.

And combined with the way method groups pick specializations it should allow me to construct stuff like is and as or even parameterized constructors within the language itself rather than needing hooks under the hood.


But for now, back to work.
Previous Entry Tangent: Generics Part 1
Next Entry While I think...
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement