Immutable

At first this sounds like a mere restriction — how come I’m not allowed to modify one? — but what it really means is that the object is identified with its contents, rather than its memory address. A mutable object has “behavior”; it changes over time, and there may be many references to the object, all of which can observe those changes. An immutable object, on the other hand, has only a value, and no time-varying behavior. Its location does not matter. It is “just some bits”.

It is rare in practice for immutables to slow down code, but there are two cases where it might happen. First, if you have a large immutable type (say 100 Ints) and do something like sorting an array of them where you need to move them around a lot, the extra copying might be slower than pointing to objects with references. Second, immutable objects are usually not allocated on the heap initially. If you need to store a heap reference to one (e.g. in an Any array), we need to move the object to the heap. From there the compiler is often not smart enough to re-use the heap-allocated version of the object, and so might copy it repeatedly. In such a case it would have been faster to just heap-allocate a single mutable object up front.

Julia is dynamically typed

Type annotations in method signatures have a slightly different meaning: instead of asserting the type of an existing value, they indicate that the method only applies if the corresponding argument is of the indicated type.

Julia methods are very much templates

Julia methods are very much templates (albeit implicitly). However staging adds a totally different dimension --- when you are not writing code to run directly, but rather writing code that generates code, a certain line has been crossed. The term "template" does not capture this distinction at all. Multiple dispatch is already a much closer analog of templates. Heck, basically every function in julia is a C++ templates function. —— timholy For functions, this code generation is based on the types of the arguments, for types, this code generation is based on the values of the parameters.

results matching ""

    No results matching ""