Scala users?

I'm starting to learn Scala (see http://www.scala-lang.org/) and as more as I use it, as less I want to write Java code with all its quirks and limitations :evil:



I'm currently writing a simple 2D puzzle game, and even for this Scala feels much more convenient than Java. I think the language is pretty good suited in order to write games (I like especially the pattern matching thing and the XML support).



My next project will be definitely "three-dimensional" (probably I'll resurrect an old one), so here is my question: Is anyone here also using Scala, especially for game development, especially especially with jME? What are your experiences?

Landei,



Yes, Scale is a very nice language and it is very usefull in some contexts indeed, such as when you need functional programming constructs.



I'm using Scala to build a DSL (domain specific language) for game cinematography. Making it easier to write camera controller agents. But I do not think in using it to replace Java as the primary language.



Have you tried Groovy and Lua as well?

I've looked at the syntax of Scala and I have to say I strongly dislike it. I don't see how the extra functionality could assist in game programming. I am planning to use Python as the scripting language for my game, as it is very simple to use and understand. I have a tendency to avoid syntactic sugar in languages (the reason why I hate C++), especially when it comes to scripting, I am planning on using the scripting engine for game triggers, so I want content designers to have an easy time working with it.

Have you tried Groovy and Lua as well?

No, but when I need scripting, I would consider them. Scala is really a bad choice for scripting, and I have no idea how Scala could get that "scripting language" label. But for writing the game itself I want to stick with a statically typed language. As I had no problems using Java libraries from Scala, there is no reason to stay with Java just because of the "j" in jME.

I've looked at the syntax of Scala and I have to say I strongly dislike it.

I think some parts of the syntax are really ugly. However there is a price to pay for power, and the Scala people are working hard to fix some of the quirks. On the other hand there are some really nice constructs, e.g. I like pattern matching and for comprehensions. It's a pity that null wasn't banned from the language, but it's really easy to avoid NPEs. The XML support is A.W.E.S.O.M.E. I didn't made much with structural types, implicit definitions and curried functions, but I know that they can be very useful.

I have a tendency to avoid syntactic sugar in languages.

Yeah, there is some magic going on in Scala, but mainly in order to allow smooth interaction with Java. If you look for "cleaner" languages, you should probably have a look at Fan (http://www.fandev.org/). I would be tempted to use this language myself if they had generics (I really like generics, but not the way they are implemented in Java).

[rant]
I really like the freedom Scala gives me. Some people might like the "stability" Java gave us by limiting the features (e.g. compared to C++). Some people might even think a language without the One Right Way (tm) to do everything is a bad thing. But Java is getting old, and you start to recognize every annoying quirk. I think it will be really hard to change Java to be more convenient. The backward-compatibility thing has become too heavy to lift for the language. Java is slowly fading away, and its legacy is the JVM and that huge bunch of more or less useful libraries. Languages like Nice and Fan are, uh..., nice, but they don't do anything new, they just do the old things better. Programming in Scala just feels good. You don't have to use all the fancy functional fluff etc, but you can, if you want. You can decide yourself how far you want to go outside your Personal Java Comfort Zone (tm), but you know there is a lot more beyond the next corner...
[/rant]

I spent some more time in my Scala toy project and I'm completely sold. It's amazing how the strange syntax starts to make sense, and how all features work orthogonal together. There are simple features like "import on steroids" or the access modifier private[this] wich makes data object(!)-private (not class private as in Java), which are simply missing in Java.  And the functional stuff can be really useful, too (you have to wrap your brain around like a Klein bottle, but the code can get not only short but also very expressive).



I encourage everybody to have a look at Scala. As soon as my 2D puzzle is running, I'll extend it with a 3D view using jME to give you a first impression.



PS: The only down side is that I now really hate to write Java code at work…  :expressionless:

Sorry for resurrecting this old thread. I didn't worked on my 2D puzzle (but it is "almost" done), but I found a great blog entry about game programming in Scala.

Game programming is inherently requiring multiple inheritence: Your game object has a meaning in your model space, but it must be drawn by the graphics subsystem too, and has to react to game events and…

A great part of the ugliness in our Java code stems from the fact that Java doesn't support multiple inheritence. Scala supports a limited, "save" form of multiple inheritence called "mixin inheritence" usings Traits, which you can think of as "interfaces on steroids".  I hope giving this piece of background makes the following easier to understand:

I could arguably be called the biggest Java super-freak and anti-other-languages guy around here but Scala is quite impressive.  I'm not sure it's quite ready for prime-time yet, but I've been following it pretty closely the past couple months and in many ways it fills the holes that Java leaves in many places.



I will likely be doing future game development in Scala, but they first have to get a stable Eclipse plugin out there for me to use. :o



Let me mention that I still hate all other languages…Ruby and Groovy specifically. :slight_smile:

Game programming is inherently requiring multiple inheritence: Your game object has a meaning in your model space, but it must be drawn by the graphics subsystem too, and has to react to game events and...
A great part of the ugliness in our Java code stems from the fact that Java doesn't support multiple inheritence.

Multiple inheritance can lead to other problems, mainly bloating. In Radakan, the entity-component framework is used for managing entities. Essentially, each entity has a collection of "components" which provide certain functionality, so instead of inheriting 100 classes for each entity type you would ever have, you only have to insert the needed components inside the entity for it to contain the neccessary functions.
You can find more info about this type of framework online.

i like whitespace  :lol:



http://compsoc.dur.ac.uk/whitespace/



:wink:


Multiple inheritance can lead to other problems, mainly bloating. In Radakan, the entity-component framework is used for managing entities. Essentially, each entity has a collection of "components" which provide certain functionality, so instead of inheriting 100 classes for each entity type you would ever have, you only have to insert the needed components inside the entity for it to contain the neccessary functions.

This seems to me more like a clever workaround for Java's limitations. Multiple inheritence *reduces* code bloating, because you can stick closer to the DRY principle (don't repeat yourself). Additionaly you have much more freedom to change your hierarchy later (that's what "mixin" means: add some properties to an existing class without touching it). I don't know the details of the Radakan framework, but already the *need* for such a framework trying to simplify really common tasks shows a weakness of the underlying language.


...but Scala is quite impressive.

darkfrog is leaving the Dark Side of the Force(tm)! He shalt be blessed and known from now on as "whitefrog the wisefrog"!

Whichever principles you base a language on, coders will make it bloated  }:-@



This seems to me more like a clever workaround for Java's limitations. Multiple inheritence *reduces* code bloating, because you can stick closer to the DRY principle (don't repeat yourself). Additionaly you have much more freedom to change your hierarchy later (that's what "mixin" means: add some properties to an existing class without touching it). I don't know the details of the Radakan framework, but already the *need* for such a framework trying to simplify really common tasks shows a weakness of the underlying language.



i'd have to disagree with that statement...
having worked on a 500, 000 line+ project with c++ code multiple inhertance drove us crazy when it came to refactoring because of code bloat...at least with single inheritance and proper encapsulation the refactor may only effect the neccessary classes and not ripple uncontrollably and unexpectedly throughout the source...
plus frameworks make people, in theorey anyways, obey the rules and an aggregation framework is the very definition of the DRY principle....
plus i'm a fan of java as it may be verbose but syntactically it's very straightforward compared to other languages i've used in projects such as objective c/c++/pascal and to a certain extent flex...and in the end that means that code is easier to read and share imo....
still though, tis no http://en.wikipedia.org/wiki/LOLCODE.....
kthxbye

I agree that multiple inheritance in C++ is absolutely evil.  :evil:



Scala uses something called mixin-inheritance, which works different. You have one and only one base class, as in Java. What you can mixin are so-called Traits, which are similar to Java interfaces. The difference is that these traits can also implement functionality, but without causing the mess multiple parent classes would do.



Here is an easy example how this works. Imagine you have a class with a compareTo method. In Java you would add "implements Comparable<MyClass>" to it, so it works together with the existing APIs, which know how to use this interface. Scala has a similar Trait called Ordered, but it doesn't just declare "Hey, this class has a compareTo method!", but in fact provides you some additional funtionality. If you add "extends Ordered[MyClass]" to it, it uses the compareTo method to give you <, >, <= and >= methods for free (something you had to code in Java over and over again).

Another example is the Set-Trait in Scala, which is similar to Java's Set interface. If you want to implement a Set, why do you have to specify an isEmpty() method when you have already a size() method? The Scala Set-Trait already provides you with a default implementation for isEmpty() (which can be overridden for performance reasons). As I already said, traits are kind of "interfaces on steroids". They have enough power to do a lot of work, but on the other hand they have some restrictions (like no constructors) which avoid the C++ mess.



Doing something similar in Java requires at least a pair of an interface and an abstract class (e.g. MouseListener / MouseAdapter etc), and then the abstract class is your base class - which is often not the thing you want. E.g. if your interface has three methods isRich, isHandsome, isRichAndHandsome, you can't enforce that isRichAndHandSome is defined in a certain way (e.g. return isRich() && isHandsome()). You must use an abstract class to enforce this, and then you're stuck with it.

i strongly recommend (to everyone) to stick to the big languages (like; C, C++, Java) for if someone starts a big project with some freak of science language like Scale and such and (god forbid) has an accident, noone can resume his work. And thats just one example, you might even get fired or so  :wink:



Don't let yourself get drawn to Ruby & Co. and leave those to the unprofessional geeks.



just my 2 cents  }:-@

dhdd said:

i strongly recommend (to everyone) to stick to the big languages...


Interesting thesis.  How does a language become big do you suppose?

Would it be a logical argument to say that if everyone followed your advice no new language would ever have a chance?  Would it also be logical to say that we'd still be using Fortran or Cobol or something because we should "stick to the big languages"?

C++ would never have been adopted. Surely Java would never have been considered.

I can't speak for the merits of Scala, but I think this



if someone starts a big project with some freak of science language


is a good contender for quote of the week  }:-@

There are always pros and cons for a certain language. Beeing a "big" and well-known language is definitely a pro. But if this big language isn't really suitable for your problem type, it's still a poor choice.



Scala has the advantage of beeing conceptually (not always syntactically) similar to Java - much more similar than other functional alternatives (OCaml, Haskell, Erlang, Scheme). As Java programmer you can learn how to write serious Scala code in ten hours. Scala allows you to ignore (or better, postpone) the functional part of the language and use Scala just as "better Java", which is a big pro in my opinion. Due to the "strange" (but consequent) syntax it looks like you would need much time to get used to Scala, but this is definitely not the case.