scala best practise

随便看看https://github.com/alexandru/scala-best-practices/

以下是我觉得讲得有意义的。


1. avoid using "return" in nested function.

2. avoid using mutable variables in most scenario unless you know that will only be using in single actor/thread.

3. avoid using exception for validation user input, the exception should only indicate the error.

4. avoid using "null", always using Option instead.

5. never use Option.get, this will throw the NoSuchElementException, using getOrElse or fold instead.

6. Use joda-time instead of java Date.

7 avoid using Any or AnyRef or isInstanceOf or asInstanceOf

8. no shared state, if really need it, we might can use Scala-STM for optimistic concurrency control / atomic reference.

9 case class should not nested in other class, otherwise ,the case class with serialize the whole class into it.

10. profiling with YourKit profiler, or VisualVM is also good enough.

11. must use scala blokingcontext on blocking I/O.

12. we can also use Scala-aync for better Await.result style.

13. should use a separate thread pool for blocking I/O such as JDBC operation.

14 avoid hardcode the thread pool or the execution context.

15 should mutable state in actors only with context.become.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值