- 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.
- Advanced Machine Learning with Python
- Mastering NetBeans
- Microsoft Exchange Server PowerShell Cookbook(Third Edition)
- OpenCV for Secret Agents
- MATLAB 2020 從入門到精通
- 跟小海龜學Python
- 深入理解Java7:核心技術與最佳實踐
- Hands-On Automation Testing with Java for Beginners
- Spring+Spring MVC+MyBatis整合開發實戰
- 青少年信息學競賽
- JavaCAPS基礎、應用與案例
- Mastering Unity 2D Game Development(Second Edition)
- Microsoft Dynamics AX 2012 R3 Financial Management
- HTML+CSS+JavaScript網頁制作:從入門到精通(第4版)
- Go語言入門經典