|
|
Subscribe / Log in / New account

A look at two new languages: Vala and Clojure

June 3, 2009

This article was contributed by Nathan Willis

Some programming languages forge new ground, others are refinements of previously existing ideas, and still others tackle a specific problem in a new and better way. This article will look at two up-and-coming languages that are not yet as widely adopted as C, C++, or Java, but offer developers some intriguing benefits: Vala and Clojure. Vala is designed specifically to build native applications for the GNOME desktop environment, and Clojure brings the power of Lisp and functional programming to the Java Virtual Machine (JVM).

Vala

GNOME itself is written in C, but many of the higher-level libraries that make up the GNOME platform (such as GTK+ and Pango) make heavy use of the GLib and GObject frameworks, which implement a complete object system including types, messaging, classes, and all of the other components that make up a typical object oriented application program interface (API). GObject makes it possible to write object oriented GNOME applications in C, and also makes it simple to provide wrappers to GNOME for object oriented languages like C++ or Python.

While GObject makes object-oriented programming in C possible, it remains somewhat cumbersome. The GObject wrappers for other languages can be even worse, introducing yet another layer of dependencies which can include virtual machines of their own. Vala was created in an attempt to address these problems and make GNOME programming easier. Vala provides a C#-like syntax that integrates GObject features, but the valac compiler compiles to C output rather than assembly. The resulting C compiles normally with gcc, plus it can be distributed as source packages fully usable on platforms that do not have Vala installed. That allows the developer to use Vala's modern language features — dynamic type system, assisted memory management, and so on — while still making source releases compatible with C applications and libraries.

In addition to GLib and GObject, the Vala project produces bindings to the major GNOME libraries: GTK+, GDK, Cairo, SDL, GStreamer, D-Bus, GIO, and many more. In addition, several external projects provide their own bindings for Vala (such as Clutter), and there are third-party efforts to create bindings for other libraries, such as OpenGL. Plugins for Vala support are available for the Eclipse, Anjuta, and MonoDevelop IDEs, as well as for the editors Emacs, Vim, and GEdit. Val(a)IDE, still in development, is a dedicated Vala IDE written in Vala itself.

The latest release of Vala is 0.7.3, which went public on May 26, 2009. It is a bugfix release for the 0.7 series, which is intended to be the last development series before 1.0. The biggest change in the 0.7 series, according to developer Jürg Billeter, is to C header file generation. In previous releases, Vala would generate a .h header file for every .vala source file, which caused problems:

This caused various issues when the dependencies between the .vala source files get complex or more specifically, circular, and it did not allow us to have internal methods that can be used in multiple .vala files but remain outside the public API. Therefore we decided to move to a single public C header file with 0.7 and stop using separate header files for internal methods.

That change demanded making changes to the build system for existing Vala applications, but Billeter said it should be the last such headache for a while.

Vala 1.0 is scheduled to be released in September of 2009, coinciding with the release of GNOME 2.28. According to Billeter, the project is on track to make the 1.0 deadline, which will mark the start of a long stable release cycle during which application developers can count on language stability. The bindings to GNOME libraries are maintained separately, Billeter said, and are added to and enhanced on an as-needed basis, so they are not subject to the same schedule.

The project offers a tutorial and sample code for those new to Vala; some familiarity with GObject is expected. Benchmarks between Vala and C show no significant execution speed losses (in some cases, Vala even beats plain C).

The project maintains a list of applications developed using Vala, in whole or in part, including GNOME panel applets and full-fledged applications. The webcam utility Cheese is currently maintaining a Vala branch in addition to its main trunk, just to road test the viability of the language. Billeter noted that although people generally think of using Vala only when starting a new project, it is possible to incorporate it into an existing C code base, too. "Among our users are both, people writing C that now want to move to something higher level and also people that just start programming in the GNOME environment," he said.

Clojure

While Vala is a language designed around a particular object system, targeting a particular desktop environment, Clojure could not be more different. It is a dialect of the functional-flavored programming language Lisp, implemented on the Java platform. That makes it cross-platform; Clojure applications are compiled to Java bytecode, so they can run on any platform with a well-supported JVM.

Creator Rich Hickey has explained that building on top of the JVM grants Clojure automatic platform stability from a broad user and developer community, but that itself was not the goal of creating the language. Hickey's primary interest was concurrency — he wanted the ability to write multi-threaded applications, but increasingly found the mutable, stateful paradigm of object oriented programming to be part of the problem. "Discovering Common Lisp after over a decade of C++, I said to myself — 'What have I been doing with my life?', and resolved to at some point code in Lisp. Several years of trying to make that practical, with 'bridges' like jFli, Foil etc, made it clear that bridges weren't going to be sufficient for the commercial work I was doing."

Hickey became less enamored of object oriented programming and started adopting a functional-programming style in his work, which he found to make the code more robust and easier for him and for his coworkers to understand. Eventually, maintaining that style in other languages like C# became more trouble than it was worth:

The idea of a functional Lisp integrated with a commercially accepted host platform just seemed like chocolate and peanut butter. It can be hard to remember the exact time in which you decide to do the crazy thing that is designing a new language - you just find yourself doing it because you have to. Coming up with persistent data structures that were fast enough was the tipping point for my considering it viable.

Clojure does provide persistent data structures, although it does considerably more. For those unfamiliar, functional programming (the style from which Lisp and Clojure originate) places a greater emphasis on functions as first-class objects, meaning that functions can be placed into data structures, passed as arguments to other functions, evaluated in comparisons, even returned as the return value of another function. Moreover, functions do not have "side effects" — the ability to modify program state or data. This paradigm focuses on computation in the mathematical sense, rather than procedural algorithms, and is a completely different approach to programming.

As a language, Clojure is a Lisp-1, part of the same family of Lisp variants as Scheme, notable for sharing a single namespace between functions and variables. Clojure differs from Scheme and other Lisp dialects in several respects documented at the Clojure web site. For application developers, the most significant distinction is that Clojure defaults to making all data structures immutable. To maintain program state, developers must use one of four special mutable structures that are explicitly designed to be shared between threads: refs, vars, atoms, and agents. Clojure uses software transactional memory (STM) to coordinate changing these mutable structures while keeping them in a consistent state, much like a transactional database. This model makes it considerably simpler to write thread-safe code than it is in object oriented languages. No locks are required, therefore there are no deadlocks or race conditions.

Like other Lisp implementations, Clojure is interpreted through a console-like read-eval-print-loop (REPL). The user launches the REPL from a .jar file and is presented with the REPL command prompt, from which he or she can load Clojure programs or directly write and execute functions and macros. The code is compiled on-the-fly to Java bytecode, which is then in turn executed by the JVM. The REPL environment is much like an interactive IDE and debugger all rolled into one, but for distribution purposes, Clojure code can be compiled ahead of time into ordinary Java applications. Because it is hosted by the JVM, Clojure can automatically make use of its features, including the type system, thread implementation, and garbage collector, rather than having to re-implement each of them. Clojure code can also call Java libraries, opening up a wealth of classes and interfaces to Clojure programmers.

Clojure 1.0 was released on May 4, 2009. There are several good resources online for learning about the language and for getting started, although a general introduction to Lisp is probably warranted for those with no experience in functional programming. Though there are not large-scale projects using Clojure, an active community is growing around it, including several local users' groups. The Clojure site offers documentation of the language syntax and examples (including example code), there is a very active Google Groups discussion forum, and Mark Volkmann's Clojure page at Object Computing tracks articles, slides, and wikibooks about Clojure.

Two-way interoperability

Vala and Clojure seem to have little if anything in common; one is object oriented and the other functional, one aimed at a specific desktop system and the other intentionally cross-platform. They are kindred spirits in one sense, however — they seek to build a more modern, robust language implementation on top of an existing, established platform. Vala's goal is to let C programmers more easily take advantage of the power of GObject and GNOME, and Clojure's is to let developers easily write concurrent applications on top of the stability of the JVM.

What is equally important is that both projects maintain bi-directional compatibility with their underlying languages and platforms. A Vala program can use any C library, and a C program can use any library written in Vala. Likewise, Clojure code can be compiled to Java, and Clojure applications can use any Java class or interface. Such interoperability will likely increase adoption of both of these languages, and it is a welcome sight in any project.


Index entries for this article
GuestArticlesWillis, Nathan


to post comments

A look at two new languages: Vala and Clojure

Posted Jun 4, 2009 0:57 UTC (Thu) by JoeBuck (subscriber, #2330) [Link] (1 responses)

The resulting C compiles normally with gcc, plus it can be distributed as source packages fully usable on platforms that do not have Vala installed.

Careful. It's a nice feature that users who don't have Vala can build a program from the C output from the Vala compiler. But one of the functions of source packages is license compliance, and it's important to remember that for purposes of GPLv2 or GPLv3, the source code is defined as the preferred form for modification, thus the Vala code is the source and the C code produced by the Vala compiler is not. Vala source must be made available for license compliance.

A look at two new languages: Vala and Clojure

Posted Jun 4, 2009 11:03 UTC (Thu) by njh (subscriber, #4425) [Link]

Yes - hopefully what was meant by the original comment was that one can have a source distribution which contains both the Vala sources and the generated C files, such that someone who just wants to "./configure && make install" can do so with only a C development environment installed.

Someone who wants to exercise "freedom 1" can do so, but will need to get a Vala development environment (much as someone who wants to do non-trival hacking on a project that includes a YACC parser will need Bison installed, but if they just want to build the program unmodified then they only need a C compiler).

A look at two new languages: Vala and Clojure

Posted Jun 4, 2009 1:05 UTC (Thu) by flewellyn (subscriber, #5047) [Link] (3 responses)

>> Like other Lisp implementations, Clojure is interpreted

Ah, careful, you'll get a lot of Lispers' backs up with that one. Modern Lisps like Common Lisp and Scheme are not "interpreted". They are interactive, but most of them include compilers; the Common Lisp standard requires a minimal compiler, in fact, and many CL implementations don't have interpreters at all, instead compiling code as it's read in (to bytecode or machine code, depending).

A look at two new languages: Vala and Clojure

Posted Jun 4, 2009 9:50 UTC (Thu) by wingo (guest, #26929) [Link]

In fact, Clojure compiles to java bytecode as well. It's as good as java inside functions, but values leaving functions have to be boxed.

Clojure - many Lisp implementations compiled, syntax alternatives

Posted Jun 8, 2009 14:24 UTC (Mon) by dwheeler (guest, #1216) [Link] (1 responses)

Quite true. Many Lisp-based implementations include compilers, and many can generate very nice code (especially if given some type hints).

Some people are put off by Lisp's syntax ((((((lots of parens, no built-in infix)))))). If you're one of them, you might want to check out this page on making Lisps readable, in particular, sweet expressions.

Clojure - many Lisp implementations compiled, syntax alternatives

Posted Jun 8, 2009 15:30 UTC (Mon) by flewellyn (subscriber, #5047) [Link]

Personally, I find the parens much less difficult to deal with than the soup of braces, brackets, angle-brackets, semicolons, and the like that you get with languages like C++, Java, or C#. And the fact that there is no operator precedence (because there is no infix) means that there is no precedence lossage, and I can tell at a glance which operators will be called just by their position, without having to remember precedence rules.

Granted, the parens would be hard to keep track of without a good editor like Emacs, but I find the same to be true of other languages, be they braces-and-semicolon languages like C\C++\Java\PHP\Javascript\whatever, or whitespace-significant like Python. A good editor is essential no matter what.

Clojure and JVM languages

Posted Jun 4, 2009 3:18 UTC (Thu) by rfunk (subscriber, #4054) [Link] (4 responses)

It's worth noting that Clojure is far from the only non-Java language
running on the JVM. That space seems to be getting a lot of activity these
days, most notably (besides Clojure) with Scala, Groovy, and JRuby. The
dynamic-language support planned for the next major JRE release will
likely accelerate this trend.

Clojure and JVM languages

Posted Jun 4, 2009 6:05 UTC (Thu) by tnoo (subscriber, #20427) [Link] (3 responses)

and Jython, of course.

Clojure and JVM languages

Posted Jun 4, 2009 9:03 UTC (Thu) by rwmj (subscriber, #5474) [Link]

And OCaml ...

Clojure and JVM languages

Posted Jun 4, 2009 11:58 UTC (Thu) by rfunk (subscriber, #4054) [Link] (1 responses)

Yes, but my understanding is that Jython is well behind CPython, with
somewhat slow development. The languages I mentioned are either JVM-only
languages or are current and competitive with the C equivalent.

Clojure and JVM languages

Posted Jun 4, 2009 12:45 UTC (Thu) by tnoo (subscriber, #20427) [Link]

well, version 2.5 is under way, which is not bad considering that language changes small between versions.

Transactional Memory

Posted Jun 4, 2009 4:06 UTC (Thu) by wahern (subscriber, #37304) [Link] (15 responses)

Everybody talks about how STM removes locking. This is bollocks. I read all the relevant theoretical papers, and poured over the code of existing implementations. I tried to implement a simple STM mechanism, and it's not possible for any amount of data more than 16-bytes (the largest atomic xchgcmp on the ubiquitous x86). This is because pure STM requires the LL/SC (load-linked/store-conditional) processor capability. But NO EXISTING CPU DOES FULL LL/SC, and x86 doesn't even have LL/SC, period (cmpxchg was _proven_ insufficient as a universal primitive for STM 20 years ago). LL/SC requires complicated and non-performant chip circuitry to guarantee the LL/SC requirements. Basically, _any_ write--no matter the op--to an LL address needs to set a flag so a following SC can fail and the code can restart the copy operation; in practice this costs too much. Chips which nominally support LL/SC only make the guarantee for the width of a cache line, IIRC.

Every existing STM library actually uses locks internally. Period. Please, stop the cargo cult hyperbole. The only real STM implementations are on paper, or maybe in a lab w/ a custom ASIC.

Transactional Memory

Posted Jun 4, 2009 5:18 UTC (Thu) by jamesh (guest, #1159) [Link]

Well Clojure isn't running on a real CPU, so the capabilities of real CPUs are not directly relevant.

The language's home page seems to be saying that STM is the concurrency model provided to programs written in the language (and that those semantics are limited to a single type of variable).

I am sure you are correct that it is implemented via locks internally -- it'd use the primitives provided by the JVM.

Transactional Memory

Posted Jun 4, 2009 9:44 UTC (Thu) by farnz (subscriber, #17727) [Link]

For those who want to be accurate about it, STM moves responsibility for locking from the application developer to the STM implementor; the contract is that STM applications cannot deadlock, and as a quality of implementation issue, should not livelock.

As with many things in programming, the hope is to trade off the possibility of more performance (given a high enough standard of programmer), for reliability now.

Transactional Memory

Posted Jun 4, 2009 13:15 UTC (Thu) by zdzichu (subscriber, #17118) [Link] (2 responses)

What about Sun's Rock CPU?

Transactional Memory

Posted Jun 4, 2009 18:37 UTC (Thu) by wahern (subscriber, #37304) [Link] (1 responses)

From the Wikipedia entry I think this is closer to hardware transactional memory. STM is a way to get transactional semantics by the use of a simple primitive and fancy algorithms where parallel threads do a complicated dance to arrive at the completion of a [compound] transaction.

The Rock CPU ops would seem to mostly obviate the need for the dance.

Transactional Memory

Posted Jun 11, 2009 14:10 UTC (Thu) by tvld (guest, #59052) [Link]

Note that the Rock CPU's TM is a best-effort implementation. Even if there are no data conflicts, it does not guarantee that all transactions run without being aborted for some reason. The guarantee they seem to give is something close to an DCAS.

Transactional Memory

Posted Jun 4, 2009 14:38 UTC (Thu) by mitchskin (subscriber, #32405) [Link] (3 responses)

The only real STM implementations are on paper, or maybe in a lab w/ a custom ASIC.
It sounds like you're thinking about hardware transactional memory. Software transactional memory (STM) may indeed be implemented using locks, but it does provide an interface that means client code can avoid using locks directly. You're right that there still may be locking somewhere, but that can still be a win since it isolates locking to one widely shared piece of code.

Transactional Memory

Posted Jun 4, 2009 17:51 UTC (Thu) by wahern (subscriber, #37304) [Link] (2 responses)

Actually, Software Transactional Memory is the correct term. To wit:

"Software Transactional Memory", Nir Shavit and Dan Toutiou, 1997.

The confusion is part of what I'm raging about ;) You can't simply say, "well, by 'software' I mean whatever I want it to mean, and not what I'm implying".

Fact is, real STM does not exist. It doesn't exist in the JVM, it doesn't exist anywhere in production (notwithstanding the Rock CPU mention). It can only exist w/ a universal primitive like LL/SC, as proven by, I believe, Herlihy.

Everything else can deadlock, and can livelock (if you're providing STM semantics).

Now, as pointed out elsethread, yes, STM can provide conceptual amelioration regarding the semantics of a language. But when that new language is running on your desktop, there is no way to "fake" it.

Existing STM is analagous to Perl5/6's "quantum" operators. Conceptually useful, but it's not literally doing it.

But don't take my word for it. Here's a small list of relevant material. These are the papers I still have in my research directory:

"Software Transactional Memory", Shavit and Toutiou, 1997.

"A Methodology for Implementing Highly Concurrent Data Objects", Herlihy, 1993.

"A Methodology for Implementing Highly Concurrent Data Structures", Herlihy, 1990.

"A Practical Multi-Word Compare-and-Swap Operation", Harris, Fraser, Pratt, 2002.

"Impossibility and Universality Results for Wait-Free Synchronization", Herlihy, 1988.

"Practical Lock-Free and Wait-Free LL:SC:VL Implementations Using 64-bit CAS", Michael, 2004.

"Wait-Free Synchronization", Herlihy, 1991.

Transactional Memory

Posted Jun 4, 2009 20:08 UTC (Thu) by Frej (guest, #4165) [Link]

I think your angle on (software) transactional memory is lockfree/nonblocking/wait-free stuff (the terms are somewhat vaguely defined imo).

But it's not the only point of STM (today). It's about safety and ease of concurrent programming on shared memory architectures.

Secondly, you missed the paper that inspired Software TM:
Transactional Memory: Architectural Support for Lock-Free Data Structures
Herlihy & Moss (1993)

Note that transactional hardware as an idea goes further back. But the above paper is pure hardware. Shavit and Toutiou later introduced Software Transactional Memory in the paper you posted.

So it is correct to distinguish between Transactional Memory and Software (assisted) Transactional Memory. Also, it does not make it pen and paper because the implementation uses locks. So surely STM exists, there are many implementations - The best are compiler/language assisted.

Transactional Memory

Posted Jun 11, 2009 14:06 UTC (Thu) by tvld (guest, #59052) [Link]

First, compare-and-set (CAS, cmpxchg,...) is universal, as is LL/SC.
Therefore, you can build nonblocking STMs, and people actually do (see, for example, the paper describing DSTM (one of the first STMs)).

Assuming that your memory transactions don't block by waiting for external events to happen, no sane (S)TM will deadlock. Some might live-lock, but that is just a question of contention management, and not a principal limitation (remember that CAS is universal...).

Please actually do read the relevant literature.

Transactional Memory

Posted Jun 4, 2009 18:01 UTC (Thu) by ekmett (guest, #58940) [Link] (4 responses)

<start lock-free STM cargo cult hyperbole>
STM _can_ remove locking on modern hardware, but you're using the wrong primitives.

To implement a fully lock-free STM you use an atomic n-CAS. You are correct that LL/SC or DCAS isn't available on a modern CPU directly. However, you CAN build an n-CAS out of that very same x86 cmpxchg16b-style CAS operation. The derivation isn't very straight forward, so I'm not surprised that you didn't come up with it by yourself, but a construction exists. You wind up comparing and swapping the values of n 'slots' atomically, rather than swapping n machine integers directly.

http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.1...

Once you have that, the derivation is straightforward.

The reason almost all transactional memory implementations fall back on ordered locks is because in practice the n-CAS STM is slower than the lock-based STM, not because no such construction exists.

<end lock-free STM cargo cult hyperbole>

Transactional Memory

Posted Jun 5, 2009 17:29 UTC (Fri) by wahern (subscriber, #37304) [Link] (3 responses)

I am/was aware of that paper.

There are other DCAS algorithms, too, including (IIRC) one which is probabilistic (but strong). One problem I encountered is that early Opterons don't implement a 128-bit CAS.

Also, my particular task was implementing POSIX signals for pthreads-win32, which ruled out dynamic allocation (requiring locking) of context structures--required by many (all?) of these CAS algorithms.

Transactional Memory

Posted Jun 6, 2009 1:34 UTC (Sat) by ekmett (guest, #58940) [Link] (2 responses)

You can get by with the 8 byte version of cmpxchg by using an array of slots
rather than raw pointers, it is just less elegant.

But even so thats a far cry from no implementation being possible. ;)

Transactional Memory

Posted Jun 8, 2009 19:52 UTC (Mon) by wahern (subscriber, #37304) [Link] (1 responses)

How many slots?

Should I just tell pthread-win32 users, "POSIX signals work without any trouble... just don't use more than N threads"?

That's not STM per the theory, is it? That's something very close to STM, but still requires workarounds and caveats. And w/ that attitude, Intel or AMD will never give us the hardware support that's needed.

Unless STM is simple and straightforward (which, even if the algorithm is complicated, it's _universal_, and so you won't have to roll your own everytime), then people will still mostly just _talk_ about STM rather than actually _using_ real STM, w/ the concomitant _realized_ benefits.

Transactional Memory

Posted Jun 11, 2009 12:33 UTC (Thu) by ekmett (guest, #58940) [Link]

Well, ~4 billion slots seems pretty flexible. ;)

Transactional Memory

Posted Jun 11, 2009 8:24 UTC (Thu) by ketilmalde (guest, #18719) [Link]

> Everybody talks about how STM removes locking. This is bollocks.

Really? I think there's a lot of talk about how STM is bollocks. While I haven't read the literature (as) extensively (as you seem to have), I've yet to see any rationale for this. More specific pointers than just a ream of research paper titles would be great.

> This is because pure STM requires the LL/SC

I'm sorry, but isn't this SOFTWARE transactional memory we're talking about? What's stopping the run-time system from abstracting away the underlying hardware?

> Every existing STM library actually uses locks internally. Period.
> Please, stop the cargo cult hyperbole. The only real STM implementations
> are on paper, or maybe in a lab w/ a custom ASIC.

While I've only made toy implementations using it, Haskell's STM library seems awfully real to me. I'm not aware of any locking, but I could be misunderstanding how it works, of course.

Further down, you go on to claim:

> Fact is, real STM does not exist.

and

> Everything else can deadlock, and can livelock

While I love unsubstianted claims as much as the next guy, your opinions would be more enlightening if you provide actual example code that demonstrates this.

A look at two new languages: Vala and Clojure

Posted Jun 4, 2009 9:05 UTC (Thu) by rwmj (subscriber, #5474) [Link] (7 responses)

Vala is a bit of a lost opportunity.

It could have been a great step forward: type inference, non-intrusive static typing, ideas from functional languages, strong emphasis on safe programming practices ... All things which are needed by the free software community.

Instead we got a warmed-over C# clone with a syntax more verbose than Java, and none of the innovations in language design which have happened in the past decades.

Rich.

A look at two new languages: Vala and Clojure

Posted Jun 4, 2009 13:30 UTC (Thu) by walters (subscriber, #7396) [Link] (6 responses)

It's not clear to me that type inference is a huge win for an imperative OO language in general. The general imperative/OO versus FP debate aside, in the specific domain Vala originated from (GUI programming for GNOME), OO languages are just a much more natural fit than FP, since the GUI is a massive chunk of state. Certainly all of the libraries are heavily OO and imperative.

Not clear what you mean by "safe programming"? Memory safety/garbage collection? In that case true, but it was a design goal of Vala to be independent of higher level runtimes and thus usable for lower level libraries in the stack.

A look at two new languages: Vala and Clojure

Posted Jun 4, 2009 13:54 UTC (Thu) by rwmj (subscriber, #5474) [Link] (4 responses)

Type inference is possible with OO languages. Ironically recent versions of C# have a rather pathetic form of type inference. Anyway, OCaml has type inference, duck typing, strong typing and excellent OO.

GUI toolkits can be designed on pure functional principles, although that wasn't what I was advocating. Look up Functional Reactive Programming. There are various toolkits for Haskell implementing these techniques.

Safety is always a good thing to build into modern languages, not just because no one wants their programs to crash so much, but because in some cases it really matters - errors and inaccuracies in GUI programs can have all sorts of effects from wasted time right up to death. Languages should be designed to reduce programmer mistakes. Garbage collection is one of many techniques in this area. Others include: design contracts, modularity, strong typing, phantom types, test-driven development.

Unfortunately all of this research seems to have passed over the heads of the developers of Vala.

A look at two new languages: Vala and Clojure

Posted Jun 4, 2009 14:11 UTC (Thu) by walters (subscriber, #7396) [Link] (3 responses)

Type inference is possible with OO languages. Ironically recent versions of C# have a rather pathetic form of type inference.
Sure (and what is ironic about it?), but what I am claiming it that it's not overly useful in a heavily imperative/OO context, given that C++/Java/C# programmers have gone many years without it. Eclipse does a good enough job at filling out generics right now for me.
Unfortunately all of this research seems to have passed over the heads of the developers of Vala.

You missed by point that garbage collection would have been incompatible with a key Vala design goal. It didn't "pass over their head".

We can't use GC in the lower level components of the GNOME stack because then if you wanted to use a higher level language (like OCaml!) on them, you'd have two different garbage collectors in the same process which is a recipe for disaster.

design contracts, modularity, strong typing, phantom types, test-driven development.

Vala definitely has modularity and strong typing. I'd argue test-driven development is not a language feature but a cultural feature. I'm not familiar with phantom types.

Anyways, you seem to be essentially saying that because Vala isn't OCaml it must be broken, when there are actual engineering tradeoffs that you're not recognizing.

A look at two new languages: Vala and Clojure

Posted Jun 4, 2009 14:13 UTC (Thu) by rwmj (subscriber, #5474) [Link]

You really should read this essay!

Are you sure all the language developers are mad?

Posted Jun 4, 2009 19:28 UTC (Thu) by khim (subscriber, #9252) [Link] (1 responses)

Sure (and what is ironic about it?), but what I am claiming it that it's not overly useful in a heavily imperative/OO context, given that C++/Java/C# programmers have gone many years without it.

Then why it's added to C#, C++ (gcc 4.4 at least does have it), etc? Are you sure developers do it because they all are mad?

Eclipse does a good enough job at filling out generics right now for me.

Yup. Basically you are using type inference - just implemented not in compiler as sane people are doing but in editor. And it produces tons of useless clutter because it's implemented in wrong place.

We can't use GC in the lower level components of the GNOME stack because then if you wanted to use a higher level language (like OCaml!) on them, you'd have two different garbage collectors in the same process which is a recipe for disaster.

Why is it a disaster? You can combine compiled Java code (GCJ) and Scheme code (Guile) in a single process - and everything "just works". Sure, it's not exactly super-fast (you are scanning some small regions of memory twice), but no other problems are shown...

Anyways, you seem to be essentially saying that because Vala isn't OCaml it must be broken, when there are actual engineering tradeoffs that you're not recognizing.

Nope. If you want to see the language designed around existing OO-system, but which is done right - take look on Groovy. It's not perfect (no language is perfect) but it adds a lot of usefull features to Java while reusing the same JVM. Sure, JVM does have richer set of features if you compare it with GLib/GObject, but still the Vala is pretty pathetic language.

Are you sure all the language developers are mad?

Posted Jun 5, 2009 18:53 UTC (Fri) by amaranth (subscriber, #57456) [Link]

Vala does have some type inference, btw. Just like C#, it supports things like this:

var reader = new Reader ();

A look at two new languages: Vala and Clojure

Posted Jun 4, 2009 14:01 UTC (Thu) by alankila (guest, #47141) [Link]

I'd like to say that type inference makes it somewhat possible to write code without an IDE. Static languages like C# and Java are chock full of classes, and you'd be dipping into the manuals all the time to figure out which returns what and so on.

With a C# keyword like "var" you can make the type information implicit, which makes it easier to write and change the code. Plus there's just something about:

Reader reader = new Reader()

collapsing to:

var reader = new Reader()

that makes the code much more readable to me. It's removing the type information that looks and feels like noise to me.

Then again, when there's a typo somewhere and the compiler can't figure out what the implicit type stands for, the errors that result are almost incomprehensible. I'm hoping Mono people can fix the parser to abort earlier instead of filling "var" with "object" and proceeding until it crashes and burns 5 lines later with missing methods and wrong types for calls etc. Usually the first thing to debug problems like this is to add some type information back so you'll pĆ­npoint the line where it goes wrong.

A look at two new languages: Vala and Clojure

Posted Jun 4, 2009 13:23 UTC (Thu) by NAR (subscriber, #1313) [Link]

No locks are required, therefore there are no deadlocks or race conditions.

Famouos last words :-) Erlang doesn't have mutable variables, so there's no need to use locks, still it's fairly easy to introduce deadlocks and race conditions as long as there's message passing between threads.

A look at two new languages: Vala and Clojure

Posted Jun 6, 2009 14:03 UTC (Sat) by aanno (guest, #6082) [Link]

Just to be complete, there is another functional language that compiles to Java bytecode called CAL. CAL is inspired by Haskell and hence strongly typed.

Transactional Memory does not require functional languages

Posted Jun 11, 2009 14:17 UTC (Thu) by tvld (guest, #59052) [Link] (1 responses)

Please note that transactional memory does not require a functional language. In fact, the majority of publicly-available software implementations of TM target C/C++ applications.

Transactional Memory does not require functional languages

Posted Jun 17, 2009 6:53 UTC (Wed) by j1m+5n0w (guest, #20285) [Link]

Very true, there's no technical reason why STM would require a functional language. The main advantage some functional languages have is purity, which means the type system can guarantee that a particular block of code does not cause side effects or otherwise interact with shared, mutable state in ways that aren't allowed by STM. In an impure language, the programmer would need to be extra vigilant.


Copyright © 2009, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds