- 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.
- Python快樂編程:人工智能深度學習基礎
- Access 數據庫應用教程
- Full-Stack Vue.js 2 and Laravel 5
- 網店設計看這本就夠了
- Mastering JavaScript High Performance
- Mastering openFrameworks:Creative Coding Demystified
- Creating Mobile Apps with jQuery Mobile(Second Edition)
- Kubernetes源碼剖析
- ASP.NET 4.0 Web程序設計
- Mastering VMware Horizon 7(Second Edition)
- Julia High Performance(Second Edition)
- Mastering Drupal 8
- Learning Alfresco Web Scripts
- SAP HANA Cookbook
- C語言解惑:指針、數組、函數和多文件編程