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

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

主站蜘蛛池模板: 榕江县| 丰台区| 洪湖市| 大安市| 扶绥县| 张北县| 宁远县| 罗城| 嵊泗县| 西宁市| 洮南市| 龙游县| 宣恩县| 武胜县| 佛坪县| 阿克陶县| 陈巴尔虎旗| 营山县| 惠安县| 恩平市| 吉安市| 公安县| 龙江县| 敖汉旗| 亚东县| 民县| 肇源县| 大名县| 天全县| 永安市| 华阴市| 泌阳县| 武乡县| 兴城市| 咸阳市| 湖州市| 盐池县| 丽水市| 合水县| 南陵县| 双柏县|