- 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 languages–this 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.
- Learning Neo4j
- Mastering Zabbix(Second Edition)
- Visual Basic編程:從基礎(chǔ)到實(shí)踐(第2版)
- VSTO開(kāi)發(fā)入門教程
- 機(jī)器人Python青少年編程開(kāi)發(fā)實(shí)例
- Python王者歸來(lái)
- C++ 從入門到項(xiàng)目實(shí)踐(超值版)
- Android項(xiàng)目實(shí)戰(zhàn):手機(jī)安全衛(wèi)士開(kāi)發(fā)案例解析
- C++寶典
- Hands-On Neural Network Programming with C#
- Xamarin Cross-Platform Development Cookbook
- Web前端開(kāi)發(fā)最佳實(shí)踐
- Spark技術(shù)內(nèi)幕:深入解析Spark內(nèi)核架構(gòu)設(shè)計(jì)與實(shí)現(xiàn)原理
- Test-Driven iOS Development with Swift
- 面向?qū)ο蠓治雠c設(shè)計(jì)(第3版)