June 11, 2008The Fan programming language
I just came across a language that I never heard of before: Fan. Here is a quick snippet:
// find files less than one day old
files := dir.list.findAll |File f->Bool|
{
return DateTime.now - f.modified < 1day
}
// print the filenames to stdout
files.each |File f|
{
echo("$f.modified.toLocale: $f.name")
}
After a few hours surveying the language, I have to say that Fan seems to get a lot of things right. Here is a short list of its features:
Constructor
class Point
{
new make(Int x, Int y) { this.x = x; this.y = y; }
Int x
Int y
}
// make a point
pt := Point.make(30, 40)
Properties
class Person
{
Str name
Int age { set { checkAge(val); @age = val } }
}
In the code above, @age is used to refer to the actual field and not the property.
Facet
@version=Version("1.2")
@todo=["fix it", "really fix it"]
class Account
{
}
You can pass methods when closures are expected. For example, Thread.make expects a closure that takes a Thread in parameters and returns an Obj:
new make(Str name := null, |Thread -> Obj| run := null)You don't need to create an object to invoke that method:
static Void readerRun(Thread t) {
// ...
}
reader := Thread.make("reader", &readerRun).start
Here are some of my pet peeves about Fan:
Overall, it looks like Fan is being driven by motivations that are very similar to what started Groovy: pick the best features of the current popular languages and try to blend them into a coherent set. I find myself particularly fond of Fan because I happen to agree with a lot of the choices that the designers made, which is exactly how I felt about Groovy in the beginning. Of course, Fan has the advantage of hindsight and it borrows from a few additional languages than Groovy did (namely, C#, Scala and a bit of Erlang), so I find the result quite promising. Comments
Maybe I'm reading too much into what you wrote. You said "I find myself particularly fond of Fan because I happen to agree with a lot of the choices that the designers made, which is exactly how I felt about Groovy in the beginning." Do you still feel this way toward Groovy or was it only in the beginning. If so, what changed your feeling? Posted by: Wilson MacGyver at June 11, 2008 08:48 AMThe Fan developers introduced themselves to the JVM Languages group a few months back; see preview.tinyurl.com/3quezp. I like their approach as well; personally, I think the website is the most important first step--and they have that nailed--before the IDE support. I'm sort of hoping that IDE support will come more quickly for many interesting languages now that people are banging out plugins to support Groovy, Ruby, Scala, etc. Cheers! Patrick Posted by: Patrick Wright at June 11, 2008 12:12 PMI think Scala "lazy val" is fairly close (equivalent) to "once" functions. Posted by: Tom at June 11, 2008 07:38 PMOh, and I meant to say "equivalent?" as a question. Posted by: Tom at June 11, 2008 07:38 PMThanks for the great writeup on Fan! Not sure I really got your typing syntax issue, but you can write a function type as just |File,File->Int| - you don’t have to include parameter names in a signature. Generics is definitely a polarizing issue – but we’re really trying to find a nice middle ground between static typing and dynamic typing – so our philosophy has been to try and keep the type system really simple (and generics aren’t simple). The issue with constructors is that we don’t allow overloading methods by parameter. So if you don’t give constructors names and don’t support parameter overloading, then you can only have one constructor. Plus named constructors work well with reflection so that you write code like “type.method(“makeFoo”).call” to instantiate objects reflectively. Being able to lookup any method with a simple string makes reflection easier to use (versus having to deal with parameter overloads). I definitely agree with you on the IDE issue. In fact we’ve started wrapping the SWT with clean Fan APIs to build a custom Fan smart editor to be embedded into Eclipse or for stand alone. Thanks for your feedback! Brian TOOLING?!!! Fan looks cool. Tooling will be the make or brake of these new languages. Again this is another area where Smalltalk shows the way forward. I understand the desire to keep things looking like C, but for those willing to make a clean break with the past, then the tooling and the language can merge. This approach opens up a whole new set of possibilities. The language I find most interesting at the moment is Newspeak, which is dynamic but will also support a pluggable static type system too. Newspeak and it's IDE hopscotch are being developed in unison. So tooling will not be an after thought.
Fan looks cool. Tooling will be the make or brake of these new languages. Again this is another area where Smalltalk shows the way forward. I understand the desire to keep things looking like C, but for those willing to make a clean break with the past, then the tooling and the language can merge. This approach opens up a whole new set of possibilities. The language I find most interesting at the moment is Newspeak, which is dynamic but will also support a pluggable static type system too. Newspeak and it's IDE hopscotch are being developed in unison. So tooling will not be an after thought.
Can I return an arbitrary instance out of the 'new make' method? i.e. can I substitute the instance to implement Singleton or Flyweight (or class clusters for the Objective C heads out there). Posted by: lordpixel at June 16, 2008 11:01 AMAllowing users to define constructor's names also allows smalltalk-like code like "Collection with: anObject" or I guess in this case "Collection.with(anObject)". Of course, it's still a matter of preference. Posted by: Facundo Quiroga at June 17, 2008 01:44 PMThe problem i have with Scala is its complexity. The power of the language allows you to do many things and thus could produce cryptic non maintainable code in the long run. Of course someone could argue that maybe this could be controlled with Scala coding best practices. There probably is iron here - but for someone like me who moved from c to c++ and then finally to Java - Scala does not seem to be intuitive. Simplicity is important for the masses to use the language - for a 'Head First' book to come out - otherwise Scala will be yet another niche language with not much $ behind it. So from this perspective how does fan look ? Posted by: SomeGuy at June 23, 2008 05:00 AMPost a comment
|