- Julia 1.0 Programming Complete Reference Guide
- Ivo Balbaert Adrian Salceanu
- 321字
- 2021-06-24 14:21:49
More on Types, Methods, and Modules
Julia has a rich built-in type system, and most data types can be parameterized, such as Array{Float64, 2} or Dict{Symbol, Float64}. Typing a variable (or more exactly the value it is bound to) is optional. However, indicating the type of some variables, although they are not statically checked, can provide some of the advantages of static-type systems as in C++, Java, or C#. A Julia program can run without any indication of types, which can be useful in a prototyping stage, and it will still run fast. However, some type indications can increase the performance by allowing more specialized multiple dispatch. Type assertions also help the LLVM compiler to create more compact, better optimized code. Moreover, typing function parameters makes the code easier to read and understand. The robustness of the program is also enhanced by throwing exceptions, in cases where certain type operations are not allowed. These failures will manifest themselves during testing, or the code can provide an exception handling mechanism.
All functions in Julia are inherently generic or polymorphic, that is, they can operate on different types of their arguments. The most appropriate method (an implementation of the function where argument types are indicated) will be chosen at runtime to be executed, depending on the type of arguments passed to the function. As we will see in this chapter, you can also define your own types, and Julia provides a limited form of abstract types and subtyping.
A lot of these topics have already been discussed in previous chapters; for example, refer to the Generic functions and multiple dispatch section in Chapter 3, Functions. In this chapter, we broaden the previous discussions by covering the following topics:
- Type annotations
- The type hierarchy—subtypes and supertypes
- Concrete and abstract types
- User-defined and composite types
- Types and collections—inner constructors
- Type unions
- Parametric types and methods
- Standard modules and paths
- Instant Testing with CasperJS
- Spring Boot+Spring Cloud+Vue+Element項目實戰:手把手教你開發權限管理系統
- 基于免疫進化的算法及應用研究
- Learning FuelPHP for Effective PHP Development
- 程序設計基礎教程:C語言
- Arduino家居安全系統構建實戰
- Python機器學習算法: 原理、實現與案例
- Hadoop 2.X HDFS源碼剖析
- Magento 2 Beginners Guide
- Unity Android Game Development by Example Beginner's Guide
- Mobile Forensics:Advanced Investigative Strategies
- SEO教程:搜索引擎優化入門與進階(第3版)
- 數據結構:Python語言描述
- Puppet Cookbook(Third Edition)
- Practical Time Series Analysis