为什么斯卡拉人不喜欢注释? [英] Why scala people don't like annotation?

查看:108
本文介绍了为什么斯卡拉人不喜欢注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

属性是一个非常流行的功能. Java在1.5之后添加了注释 注释在任何地方都可以使用,请参阅Java EE和Spring. 但是很少有Scala库使用注释. lift-json不要使用它. 提升记录不要使用它. Squeryl不使用它. subcut不要使用它(它具有编译器插件的注释) ... 仅举几例.

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.

仅当需要一些编译器魔术时,才使用注释. @ tailrec,@ inline,@ BeanProperty,@ Inject(在子切口中)...

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

Scala具有超级灵活的类型系统,特征,隐式和Menifest [X].所以他们不需要运行时元数据吗?

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

是否有任何scala项目都使用注解?

Is there any scala project use annotation heavily?

p.s.我认为动态应该是注解,而不是特征.

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

推荐答案

通常,我们不使用注释,因为我们实际上并不需要很多东西.

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:

  • 其他类型的系统(例如,用于定界延续的CPS插件或效果跟踪插件.
  • 与旧版Java接口的接口. ( scala-mojo-support )
  • 强制执行/启用编译器优化,例如@inline@tailrec.
  • 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.

在Scala中,我们实际上并不需要依赖注入框架,因为有几种方法可以执行不需要外部工具的依赖注入.您可以将DI配置与核心代码分开,但是仍然可以用Scala编写.请参阅: https://github.com/jsuereth/scala-in-depth-source/blob/master/chapter11/src/main/scala/scalax/config/Test.scala

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).

这篇关于为什么斯卡拉人不喜欢注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆