Alex Rivera | Logout

Why scala people don't like annotation?

Asked 2011-12-22T20:13:52.700
23

Attribute in .NET is a very popular feature. And Java added Annotation after 1.5 Annotations are used everywhere, see Java EE and Spring. But few scala library use annotation. lift-json don't use it. lift-record don't use it. Squeryl don't use it. subcut don't use it.(it has annotation for compiler plugin) ... Just named a few.

They use annotation only when they need some compiler magic. @tailrec, @inline, @BeanProperty, @Inject(in subcut) ...

Scala has super flexible type system, trait, implicit and Menifest[X]. So they don't need runtime meta-data?

Is there any scala project use annotation heavily?

p.s. I think the Dynamic should be annotation but not trait.

Edit
Report

1 Answer

29

In general, we don't use annotations because we don't really need them for a lot of things.

The few places I've seen annotations used:

  • Extra type systems (e.g. the CPS plugin for delimited continuations or the effect tracking plugin.
  • Interfacing with legacy Java interfaces. (scala-mojo-support)
  • Enforcing/enabling compiler optimisations, like @inline or @tailrec.

In Scala, we don't really need a dependency injection framework, as there's a few ways to do dependency injection that doesn't require an external tool. You can have the DI config separate from core code, but still be written in Scala. See: https://github.com/jsuereth/scala-in-depth-source/blob/master/chapter11/src/main/scala/scalax/config/Test.scala

So the basic answer is, there's nothing wrong with annotations, we just don't need them that often (yet).

answered 2011-12-22T20:36:47.717

Your Answer