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

document __init__ #9240

Merged
merged 1 commit into from
Dec 3, 2014
Merged

document __init__ #9240

merged 1 commit into from
Dec 3, 2014

Conversation

stevengj
Copy link
Member

@stevengj stevengj commented Dec 3, 2014

This fixes #8923. @vtjnash, @JeffBezanson, please look over the text to make sure that it is accurate.

cc: @timholy

@stevengj stevengj added the docs This change adds or pertains to documentation label Dec 3, 2014
@JeffBezanson
Copy link
Member

👍

stevengj added a commit that referenced this pull request Dec 3, 2014
@stevengj stevengj merged commit 3d6c915 into JuliaLang:master Dec 3, 2014
@timholy
Copy link
Member

timholy commented Dec 3, 2014

Very nice. In practice, I've found that perhaps the most important point is that any global Dicts or Sets need to be rehashed---when that doesn't happen, figuring out what's wrong can be surprisingly tricky. In my recent HDF5 work I forgot to check Sets, and spent about 2 hours on this one-line fix: JuliaIO/HDF5.jl@df75bf9. The absence of the correct hash meant that the correct function was being overwritten by a newly-generated one, which made it a rather non-obvious debugging experience.

rehash is not exported, for good reason. But convenience syntax (for julia 0.4) added in e7ce4cb.

@stevengj
Copy link
Member Author

stevengj commented Dec 3, 2014

Isn't this only the case if they are hashed by object_id? Why would a Dict{Int} need to be rehashed, for example?

@timholy
Copy link
Member

timholy commented Dec 3, 2014

Correct.

@jakebolewski
Copy link
Member

Should we also provide an ObjectIdSet? This distinction could be made more explicit.

@stevengj
Copy link
Member Author

stevengj commented Dec 3, 2014

I don't see how ObjectIDSet would help, because Set could still be unsafe (just like Dict can be unsafe even though there is ObjectIdDict). The problem is that the default hash(x,h) method calls object_id(x).

Unfortunately, this includes hashing of strings immutables.

Actually, the story is even more complicated than that, because the object_id appears to be only pointer-based for some types. But it looks like strings immutables are not okay because the hash includes the hash of the pointer to their type? But it seems like the address of the string immutable type does not change from run to run (at least with the same julia binary), so immutable string keys are okay? It's confusing.

however, you may need to change your module to explicitly separate any
initialization steps that must occur at *runtime* from steps that can
occur at *compile time*. For this purpose, Julia allows you to define
an ``__init__()` function in your module that executes any
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's a missing backtick here.

Copy link
Member

Choose a reason for hiding this comment

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

Seems like it does. Fixed in 9743a99

Copy link
Member

Choose a reason for hiding this comment

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

If you want, you can fix such issues yourself, even without mucking with the git command line, because github provides a Web UI to create pull requests if you click the pencil button above a file.

ivarne added a commit that referenced this pull request Dec 4, 2014
@stevengj
Copy link
Member Author

stevengj commented Dec 4, 2014

Thanks for the fixes.

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

Successfully merging this pull request may close these issues.

document module __init__
6 participants