Skip to content

Commit

Permalink
Imported normalize (but not exported it to match package conventions …
Browse files Browse the repository at this point in the history
…in Julia)
  • Loading branch information
Marcus P S committed Sep 16, 2016
1 parent 1be50ce commit dbcc6b0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/basics.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Compat

if VERSION > v"0.5.0-"
import Base: normalize, normalize!
end

export ket,
bra,
ketbra,
Expand Down

4 comments on commit dbcc6b0

@tkelman
Copy link

Choose a reason for hiding this comment

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

importing will still extend the method from base and change the behavior of other code

@marcusps
Copy link
Collaborator

Choose a reason for hiding this comment

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

Even if I don't export those methods?

@tkelman
Copy link

@tkelman tkelman commented on dbcc6b0 Sep 16, 2016

Choose a reason for hiding this comment

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

Correct. If you import it from Base and define a new method, it's extending the Base version of normalize - http://docs.julialang.org/en/release-0.4/manual/modules/?highlight=import.

The best practice of avoiding "type piracy" is either define method names that aren't in Base on types that are in Base, or extend method names that are in Base on type signatures where at least one of the inputs is of a type defined in your package.

@tkelman
Copy link

Choose a reason for hiding this comment

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

It's an easy mistake to make, and a somewhat confusing topic. Some related discussion on a similar case here rened/FunctionalData.jl#3

Please sign in to comment.