tl;dr: just cargo cult and do what everyone else does :)

The main difference is where they search:

- `include` searches relative to the path of the source file *in which it
is called*. That is why it is useful and widely used in packages.

- `require` looks in cwd, then package directories (plus "src/" subdir for
each), then LOAD_PATH. However, `require` doesn't know anything about which
package/file it is used from, so it could (I think) accidentally end up
grabbing a file of the same name as something you have in your own package,
but from somewhere else. So, useful for interactive work, but probably not
recommended for packages. (require also lets you use `require("foo")`
instead of `require("foo.jl")`).

Where do you see that `include` loads twice?

On Thu, May 7, 2015 at 4:52 PM, Jack Minardi <[email protected]> wrote:

> When should I use `include` and when should I use `require`?
>
> In all the packages I've read everyone seems to use `include`, but
> `require` seems to do everything that it does, plus be smarter about not
> loading twice. Is this correct?
>

Reply via email to