From 964dc654668a4a863448d91d157526973984a5e4 Mon Sep 17 00:00:00 2001 From: StephenVavasis Date: Thu, 22 Jun 2017 13:36:32 -0400 Subject: [PATCH 1/5] Update performance-tips.md New paragraph about the use of `convert` and type stability. --- doc/src/manual/performance-tips.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/src/manual/performance-tips.md b/doc/src/manual/performance-tips.md index 02f609b77dd1c..2c0ac0148aa35 100644 --- a/doc/src/manual/performance-tips.md +++ b/doc/src/manual/performance-tips.md @@ -477,6 +477,12 @@ Here, we happened to know that the first element of `a` would be an [`Int32`](@r an annotation like this has the added benefit that it will raise a run-time error if the value is not of the expected type, potentially catching certain bugs earlier. +A slightly more generic way to annotate the type of `x` is `x = convert(Int32,a[1])::Int32`. The +use of the `convert` function allows `a[1]` to be any object convertible to an `Int32` (such as `UInt8`). +Notice that the `convert` function itself needs a type annotation in order to achieve type stability. +This is because the compiler cannot deduce the type of the return value of a function, even +`convert`, unless the types of all its arguments are known. + ### Declare types of keyword arguments Keyword arguments can have declared types: From 430230b5d8a780e0fb27990a5513d247cb8edb75 Mon Sep 17 00:00:00 2001 From: StephenVavasis Date: Thu, 22 Jun 2017 13:51:19 -0400 Subject: [PATCH 2/5] Update performance-tips.md clarified my clarification --- doc/src/manual/performance-tips.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/manual/performance-tips.md b/doc/src/manual/performance-tips.md index 2c0ac0148aa35..ea3cb059279d7 100644 --- a/doc/src/manual/performance-tips.md +++ b/doc/src/manual/performance-tips.md @@ -479,7 +479,7 @@ value is not of the expected type, potentially catching certain bugs earlier. A slightly more generic way to annotate the type of `x` is `x = convert(Int32,a[1])::Int32`. The use of the `convert` function allows `a[1]` to be any object convertible to an `Int32` (such as `UInt8`). -Notice that the `convert` function itself needs a type annotation in order to achieve type stability. +Notice that the `convert` function itself needs a type annotation in this context in order to achieve type stability. This is because the compiler cannot deduce the type of the return value of a function, even `convert`, unless the types of all its arguments are known. From 26924918784776f58e41f114fcd363c18bb97159 Mon Sep 17 00:00:00 2001 From: StephenVavasis Date: Thu, 22 Jun 2017 20:37:26 -0400 Subject: [PATCH 3/5] Update performance-tips.md Rewrote new text following suggestion of @kshyatt --- doc/src/manual/performance-tips.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/src/manual/performance-tips.md b/doc/src/manual/performance-tips.md index ea3cb059279d7..382c271fd9cc1 100644 --- a/doc/src/manual/performance-tips.md +++ b/doc/src/manual/performance-tips.md @@ -477,8 +477,10 @@ Here, we happened to know that the first element of `a` would be an [`Int32`](@r an annotation like this has the added benefit that it will raise a run-time error if the value is not of the expected type, potentially catching certain bugs earlier. -A slightly more generic way to annotate the type of `x` is `x = convert(Int32,a[1])::Int32`. The -use of the `convert` function allows `a[1]` to be any object convertible to an `Int32` (such as `UInt8`). +In the case that the type of `a[1]` is not known precisely, `x` can be declared via +`x = convert(Int32,a[1])::Int32`. The +use of the `convert` function allows `a[1]` to be any object convertible to an `Int32` (such as `UInt8`), thus +increasing the genericity of the code by loosening the type requirement. Notice that the `convert` function itself needs a type annotation in this context in order to achieve type stability. This is because the compiler cannot deduce the type of the return value of a function, even `convert`, unless the types of all its arguments are known. From 10d26af21d3e864bc0b24541e33a4cd096440b66 Mon Sep 17 00:00:00 2001 From: StephenVavasis Date: Fri, 23 Jun 2017 13:03:08 -0400 Subject: [PATCH 4/5] Update performance-tips.md More small edits as per comments from @nalimilan and @fredrikekre --- doc/src/manual/performance-tips.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/src/manual/performance-tips.md b/doc/src/manual/performance-tips.md index 382c271fd9cc1..cee7134b74f96 100644 --- a/doc/src/manual/performance-tips.md +++ b/doc/src/manual/performance-tips.md @@ -478,12 +478,12 @@ an annotation like this has the added benefit that it will raise a run-time erro value is not of the expected type, potentially catching certain bugs earlier. In the case that the type of `a[1]` is not known precisely, `x` can be declared via -`x = convert(Int32,a[1])::Int32`. The -use of the `convert` function allows `a[1]` to be any object convertible to an `Int32` (such as `UInt8`), thus -increasing the genericity of the code by loosening the type requirement. -Notice that the `convert` function itself needs a type annotation in this context in order to achieve type stability. -This is because the compiler cannot deduce the type of the return value of a function, even -`convert`, unless the types of all its arguments are known. +`x = convert(Int32,a[1])::Int32`. The use of the [`convert`](@ref) function allows `a[1]` +to be any object convertible to an `Int32` (such as `UInt8`), thus increasing the genericity +of the code by loosening the type requirement. Notice that `convert` itself needs a type +annotation in this context in order to achieve type stability. This is because the compiler +cannot deduce the type of the return value of a function, even `convert`, unless the types of +all the function's arguments are known. ### Declare types of keyword arguments From a43ff12fbb946b76e1beadac4173d5a374f695f2 Mon Sep 17 00:00:00 2001 From: StephenVavasis Date: Sat, 24 Jun 2017 17:42:47 -0400 Subject: [PATCH 5/5] Update performance-tips.md Removed trailing spaces --- doc/src/manual/performance-tips.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/src/manual/performance-tips.md b/doc/src/manual/performance-tips.md index cee7134b74f96..7eec3d59137b8 100644 --- a/doc/src/manual/performance-tips.md +++ b/doc/src/manual/performance-tips.md @@ -480,9 +480,9 @@ value is not of the expected type, potentially catching certain bugs earlier. In the case that the type of `a[1]` is not known precisely, `x` can be declared via `x = convert(Int32,a[1])::Int32`. The use of the [`convert`](@ref) function allows `a[1]` to be any object convertible to an `Int32` (such as `UInt8`), thus increasing the genericity -of the code by loosening the type requirement. Notice that `convert` itself needs a type -annotation in this context in order to achieve type stability. This is because the compiler -cannot deduce the type of the return value of a function, even `convert`, unless the types of +of the code by loosening the type requirement. Notice that `convert` itself needs a type +annotation in this context in order to achieve type stability. This is because the compiler +cannot deduce the type of the return value of a function, even `convert`, unless the types of all the function's arguments are known. ### Declare types of keyword arguments