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

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.

主站蜘蛛池模板: 若尔盖县| 鄂温| 平邑县| 榕江县| 平定县| 凉城县| 青河县| 德江县| 遂平县| 保定市| 巨野县| 呼伦贝尔市| 临海市| 抚顺市| 凯里市| 柏乡县| 衡东县| 黎平县| 湖北省| 繁峙县| 淳安县| 安庆市| 郧西县| 河池市| 东乡| 武邑县| 宝山区| 宁安市| 乾安县| 衢州市| 高淳县| 农安县| 桦甸市| 东平县| 淮阳县| 稻城县| 忻城县| 长寿区| 济南市| 阳新县| 武川县|