- 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.
- 基于粒計算模型的圖像處理
- Visual Basic編程:從基礎到實踐(第2版)
- Java EE框架整合開發入門到實戰:Spring+Spring MVC+MyBatis(微課版)
- PHP 7底層設計與源碼實現
- Python爬蟲開發與項目實戰
- Servlet/JSP深入詳解
- Mastering Python Networking
- Kali Linux Wireless Penetration Testing Beginner's Guide(Third Edition)
- SAP BusinessObjects Dashboards 4.1 Cookbook
- RSpec Essentials
- Windows內核編程
- C# and .NET Core Test Driven Development
- HTML+CSS+JavaScript網頁設計從入門到精通 (清華社"視頻大講堂"大系·網絡開發視頻大講堂)
- Unity Character Animation with Mecanim
- SpringBoot從零開始學(視頻教學版)