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

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

问题描述

.NET 中的属性是一个非常流行的特性.并且Java在1.5之后添加了Annotation注解无处不在,参见 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(in subcut) ...

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

Scala 拥有超级灵活的类型系统、trait、隐式和 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?

附言我认为 Dynamic 应该是注释而不是特征.

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.

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

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

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