官术网_书友最值得收藏!

  • Mastering Elixir
  • André Albuquerque Daniel Caixinha
  • 178字
  • 2021-08-05 10:42:49

Typespecs and behaviours

As already mentioned in the beginning of this chapter, Elixir is a dynamic programming language. As such, we don't declare the type of each variable, as it depends on the value each variable is bound to at each moment.

Usually dynamic programming languages yield higher productivity, as programmers don't need to declare types and can focus on developing the logic of an application. However, this comes at a cost: Certain errors, which in statically-typed languages would be caught at compile-time, may only be caught at runtime in dynamic languages. The time saved by using a dynamic language is then used (often in excess) on debugging in production.

We're not advocating for statically-typed languagesthis book is about Elixir, after all. But what if you could have the best of both worlds?

It turns out you can! Type specifications, or typespecs, are a mechanism to annotate function signatures with the respective types (arguments and return values). Typespecs are also used to create custom data types. Let's explore them in more detail, before jumping into behaviours.

主站蜘蛛池模板: 清河县| 区。| 滨海县| 乐安县| 观塘区| 灌阳县| 扶沟县| 新民市| 石家庄市| 乌审旗| 元谋县| 常州市| 栾川县| 灵宝市| 独山县| 上虞市| 共和县| 临泉县| 荣成市| 岳阳市| 安乡县| 桐梓县| 宁晋县| 灌阳县| 福泉市| 天柱县| 屯门区| 平罗县| 寿阳县| 栾城县| 天祝| 澄城县| 龙州县| 崇左市| 滕州市| 奉化市| 南部县| 集贤县| 区。| 天门市| 通河县|