Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update performance-tips.md #22479

Merged
merged 5 commits into from
Jun 25, 2017
Merged

Update performance-tips.md #22479

merged 5 commits into from
Jun 25, 2017

Conversation

StephenVavasis
Copy link
Contributor

I added a paragraph concerning something that surprised me about convert.

New paragraph about the use of `convert` and type stability.
clarified my clarification
@kshyatt kshyatt added domain:docs This change adds or pertains to documentation performance Must go faster labels Jun 22, 2017
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps rephrase this to "A slightly more generic way to annotate the type of x is shown by the example of...". It took me a second to realize you are referring to the ::Int32 bit and the fact that convert is involved is somewhat incidental (if I've understood correctly).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph is supposed to make two points: First, to increase genericity, a convert function can be used rather than a direct annotation. In other words, the use of convert allows more possible types for a[1]. The second point (which is the point that surprised me) is that if convert is used in this manner, it needs a type annotation else it is type-unstable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second part comes through pretty well but your response to me here, if worked into what you already have, would make it a lot clearer I think. Thanks for adding this!

Rewrote new text following suggestion of @kshyatt
Copy link
Contributor

@kshyatt kshyatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for bearing with me @StephenVavasis

@@ -477,6 +477,14 @@ 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.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps worth adding a reference to convert? E.g. [`convert`](@ref)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also wrap lines at 92 chars.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps "...the types of all the arguments...", since "its" could refer to the compiler in this sentence?

@@ -477,6 +477,14 @@ 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.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double space before "The" ?

`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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps "Notice that convert itself..." ?

More small edits as per comments from @nalimilan and @fredrikekre
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing space which causes CI to fail, same on the next 2 lines.

Removed trailing spaces
Copy link
Member

@nalimilan nalimilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@tkelman tkelman merged commit cb50e0b into JuliaLang:master Jun 25, 2017
DrTodd13 pushed a commit to IntelLabs/julia that referenced this pull request Jun 26, 2017
* Update performance-tips.md

New paragraph about the use of `convert` and type stability.

* Update performance-tips.md

clarified my clarification

* Update performance-tips.md

Rewrote new text following suggestion of @kshyatt

* Update performance-tips.md

More small edits as per comments from @nalimilan and @fredrikekre

* Update performance-tips.md

Removed trailing spaces
@nalimilan
Copy link
Member

@tkelman Would have been nice to remove mentions of our usernames from the commit message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:docs This change adds or pertains to documentation performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants