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

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.

主站蜘蛛池模板: 太湖县| 英德市| 芒康县| 安平县| 拜城县| 新沂市| 廉江市| 株洲县| 开远市| 安义县| 灌云县| 陈巴尔虎旗| 广州市| 凤凰县| 新沂市| 云浮市| 渝中区| 德阳市| 云和县| 蒙自县| 界首市| 凤凰县| 彭州市| 惠东县| 仲巴县| 萝北县| 信宜市| 彰化市| 班玛县| 旅游| 青川县| 涟水县| 隆安县| 明溪县| 环江| 合作市| 什邡市| 拜泉县| 司法| 贵阳市| 泾川县|