# Does Julia have function prototypes?

**URL:** <https://discourse.julialang.org/t/does-julia-have-function-prototypes/6387>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 11, 2017, 8:07am UTC](https://discourse.julialang.org/t/does-julia-have-function-prototypes/6387 "2017-10-11T08:07:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjb](https://avatars.discourse-cdn.com/v4/letter/c/a4c791/32.png) [@cjb](https://discourse.julialang.org/u/cjb)\
**Post date:** [October 11, 2017, 8:07am UTC](https://discourse.julialang.org/t/does-julia-have-function-prototypes/6387/1 "2017-10-11T08:07:41Z")

</div>

Hello. I am wondering if it’s possible to have function prototypes, similar to what one does in C or C++ in a header file.

I would like to have such prototypes because it makes it very easy to read a julia file and see the functions it provides, without having to grep through hundreds of lines of code to see which functions and types are defined there. So far, from what I’ve seen, there are no function prototypes. If this is the case, do you have any advice on how to achieve achieve something of this sort, that would help have a quick understanding of the functions provided by a module or julia file?

Thanks!

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [October 11, 2017, 8:41am UTC](https://discourse.julialang.org/t/does-julia-have-function-prototypes/6387/2 "2017-10-11T08:41:56Z")

</div>

Just look at module’s `export` statement.

Also, you can list all exported functions and types from a module using `names(ModuleName)` or all external + internal using `names(ModuleName, true)`:

```julia
julia> import IterTools
INFO: Precompiling module IterTools.

julia> names(IterTools)
18-element Array{Symbol,1}:
 Symbol("@itr")
 :IterTools    
 :chain        
 :count        
 :distinct     
 :groupby      
 :imap         
 :iterate      
 :ncycle       
 :nth          
 :partition    
 :peek         
 :peekiter     
 :product      
 :repeatedly   
 :subsets      
 :takenth      
 :takestrict

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 11, 2017, 8:46am UTC](https://discourse.julialang.org/t/does-julia-have-function-prototypes/6387/3 "2017-10-11T08:46:52Z")

</div>

You could look at [GitHub - yuyichao/FunctionWrappers.jl](https://github.com/yuyichao/FunctionWrappers.jl). That package is mostly to handle the case where you want to avoid the dynamic dispatch when you have e.g. a vector of heterogeneous function with the same prototype but you could perhaps use it here.

There are some optimizations (like inlining) that will not work when it is wrapped though so it is not an ideal solution.

---

<div class="post-metadata">

**Author:** ![cjb](https://avatars.discourse-cdn.com/v4/letter/c/a4c791/32.png) [@cjb](https://discourse.julialang.org/u/cjb)\
**Post date:** [October 12, 2017, 8:41pm UTC](https://discourse.julialang.org/t/does-julia-have-function-prototypes/6387/4 "2017-10-12T20:41:59Z")

</div>

Thanks for the answers. It seems that for my case the best will be to have proper docstrings and generate the documentation per file or module, so it’s easy to know where each function is and depart from there.

Looking at the exports can help, but I was looking for something that could be seen directly in the source file, similar to how one looks at the .h file to see what a class is implementing, without having to grep into the respective .cpp file in C++; i find that very handy.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 13, 2017, 6:13am UTC](https://discourse.julialang.org/t/does-julia-have-function-prototypes/6387/5 "2017-10-13T06:13:34Z")

</div>

What information would you expect from a “function prototype” in Julia? Since methods can have different number of arguments, behavior, and returned types, pretty much the only information that is common to methods of a function is the function name.

---

<div class="post-metadata">

**Author:** ![cjb](https://avatars.discourse-cdn.com/v4/letter/c/a4c791/32.png) [@cjb](https://discourse.julialang.org/u/cjb)\
**Post date:** [October 14, 2017, 7:07am UTC](https://discourse.julialang.org/t/does-julia-have-function-prototypes/6387/6 "2017-10-14T07:07:34Z")

</div>

I agree Tamas that it’s tricky because of the variable number of arguments and templated functions. My motivation was mostly to have a quick summary of what a .jl file contains, even if a bit incomplete.

What I’m trying now is to use Documenter.jl to build the relevant docs so it’s easier to navigate. Thanks!

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 14, 2017, 9:08am UTC](https://discourse.julialang.org/t/does-julia-have-function-prototypes/6387/7 "2017-10-14T09:08:48Z")

</div>

The problem is exacerbated by the fact that the methods may be scattered over _multiple_ `.jl` files. While I like to put everything in a single file below 500 LOC, some Julia programmers like to keep things more separated. For some well-organized packages, you may find a file that defines the types and possibly the generic function stubs with syntax like

```julia
"""
here foo is documented nicely, methods will be all over the place
"""
function foo end

```

Then you can work your way through the other files which have the methods.

I usually call the `@edit` macro to take me to the relevant method. When [the debugger](https://github.com/Keno/ASTInterpreter2.jl) stabilizes, it will become even easier to explore code in a package.

Quick text searches also help — I find [ag](https://geoff.greer.fm/ag/) very useful for that.
