# Best way to specify a filename inside a function

**URL:** <https://discourse.julialang.org/t/best-way-to-specify-a-filename-inside-a-function/80263>\
**Category:** New to Julia\
**Created:** [April 29, 2022, 5:05pm UTC](https://discourse.julialang.org/t/best-way-to-specify-a-filename-inside-a-function/80263 "2022-04-29T17:05:02Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![chadagreene](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chadagreene/32/34924_2.png) [@chadagreene](https://discourse.julialang.org/u/chadagreene)\
**Post date:** [May 5, 2022, 5:40pm UTC](https://discourse.julialang.org/t/best-way-to-specify-a-filename-inside-a-function/80263/21 "2022-05-05T17:40:07Z")

</div>

Ha! Fortunately, the people who use my code are generally very capable scientists. They can handle the task of entering a filename on a specific line of a function. The trouble is I don’t yet trust my own abilities to implement Preferences.jl correctly. I’m sure I’ll get there eventually, but I’m not quite there yet.

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [May 5, 2022, 6:03pm UTC](https://discourse.julialang.org/t/best-way-to-specify-a-filename-inside-a-function/80263/22 "2022-05-05T18:03:33Z")

</div>

If editing source code is OK, maybe you can just ask users to input the filename? You can do this with a function such as

```julia
function fninput()
    print("Please enter filename: ")
    filename = readline(stdin)
end

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 5, 2022, 8:36pm UTC](https://discourse.julialang.org/t/best-way-to-specify-a-filename-inside-a-function/80263/23 "2022-05-05T20:36:55Z")

</div>

> [@chadagreene](#):
>
> I’m trying to understand why such a complicated solution is necessary for such an incredibly simple task.

It’s not necessary. You can just stick the setting in a file somewhere, anywhere, your choice.

The complexity arises if you want that setting to be associated **uniquely with a package** , because the **package system is complicated**. (_All_ good packaging systems, in every language, are complicated!)

A key complication is that Julia can have _multiple versions_ of the same package installed _simultaneously_, and the user can rapidly switch versions by changing [project environments](https://pkgdocs.julialang.org/v1/environments/), and can run in different environments simultaneously on the same machine. So there is _no single place that a package is installed_. Moreover, a package might be “hidden” because it was only installed as a dependency of another package, so that the user doesn’t necessarily need to know that it is exists or where it is. And such a hidden package should be automatically deleted when it is no longer needed. And some packages might be in a read-only location (e.g. installed by a sysadmin).

So, to associate a preference _with a package_, the preference really needs to be _per project environment_ as well, so that diffferent versions of the same package (or the same version in different environments) can have different preference settings. (After all, the meaning of the preference settings might change incompatibly between one version of your package and another.)

> [@chadagreene](#):
>
> I tell users to type `open myfunction` into the command window, and I say “edit Line XX of the function to indicate the correct file path to the data file.”

You can still do this in Julia. You can discard the whole package system and all its benefits and just give users a script (or a module as raw source code in a directory) and tell them to edit a file.

But then, of course, you lose all of the benefits of a modern package system: automatic dependency management, version management, environments (which are crucial to avoid “dependency hell” when you’re using different software with incompatible version requirements in different projects), automated precompilation, and more. Nearly every modern language seems to have a complex and full-featured package manager (Rust Cargo, RubyGems, JavaScript npm, Python pip and conda, …), usually after years of painful development with more primitive solutions. Really, we’ve tried going without, and in the long term it sucks!

@sswatson had some good advice in another thread:

> [@Package management via conda?](https://discourse.julialang.org/t/package-management-via-conda/60806/19):
>
> My advice is to **use tools the way they are used by other people**. If you want to learn Rust, use Cargo. If you want to learn Haskell, use Cabal. Trying to fit a tool into an idiosyncratic workflow is a recipe for a lot of work and frustration for very little gain. This is a lesson I have learned the hard way.

[Previous page](https://discourse.julialang.org/t/best-way-to-specify-a-filename-inside-a-function/80263.md?page=1)
