I had been a Java programmer for quite a long time, and I didn’t really feel anything too inconvenient about the language back then.
Then I moved to Scala and quite enjoyed it, and as I started using Unity, I began to code in C#… well, now I wish I could write games in Scala everyday.
In particular, I really, really miss mixins. Just now, I was trying to write a Java Swing like wrapper around IMGUI, which didn’t look to be too much of a problem, at first.
Of course, there were moments when I had to pull my hair out, like when I saw those ugly duplicated methods between GUI and GUILayout, but I can live with that… well, it’s Unity, after all.
But when I finished writing a base class for containers(i.e. box, group, and etc), and another for those components with GUIContent(i.e. button, label, and etc), it came to my notice that a box’s title is essentially a GUIContent, but I cannot make it extend from the latter, as it’s already extending from the former… urg… ![]()
Each of those base classes contains quite a lot of template codes, so simply choosing one of the base classes means I have to copy & paste much of the content (you know… a kitten is killed everytime you do that). And I cannot mimic mixins with extension methods, because they cannot be extended. And it’d surely be an overkill if I try to create yet another components just to handle such features like handling child components, and etc.
If it was Scala, all it’d take to accomplish the task is simply making Box class implements the both of those parent interfaces (or ‘traits’, as they are called in Scala).
I almost hit such kind of a wall almost every day when I write in C#, and the lack of mixin capability has made my code base much bloated already.
I know, I’m just ranting and sorry about it. But it really frustrates me whenever this happens. And as I can’t spend too much time on my game project, I really hate it when I hate to spend precious time on weekends, just trying to find out the least ugly workaround for such a problem.