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.
Using the annotation @inline does not ensure that a method will be inlined, but it will cause the compiler to do it if and only if some heuristics about the size of the generated code are met. When writing Scala code which interoperates with Java, there are a few differences in annotation syntax to note.
Let see why Scala is a beneficiary language to learn and what it offers that you. You can share your own reasons to why Scala with us. 1. Type Inference Scala automatically infers (detects) the data type of an expression partially or fully. This means that we don’t need to declare it ourselves.
Scala automatically infers (detects) the data type of an expression partially or fully. This means that we don’t need to declare it ourselves. Such a facility lets the programmer leave out type annotations while still allowing type checking.
Scala is a language of a functional paradigm. It treats its functions as first-class citizens. This is why it also lets us create higher-order functions- ones that can return a function, or take it as a parameter.
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:
@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).
For me it's often an issue of compiler enforced type safety. Take a look at Squeryl and how it differs from a Java ORM like Hibernate. Where Hibernate would use an @Id annotation to denote a primary key, in Squeryl you create an id member, which is specified by the KeyedEntity trait. Methods that require an entity with a primary key (update & delete for instance) will crash loudly at compile time if one hasn't been defined. There are several other places within Squeryl where typesafe constructs replace annotations like collection mapping and date/time handling.
I think that this is a common way of thinking in the Scala community. Annotations are more of a run time feature and aren't as well regarded. The Scala compiler is very powerful and pushing more of your code into constructs it can validate makes sense for those who are willing to accept the complexity that comes along with that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With