Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Block comments in Julia: #= vs """

Tags:

julia

I know that block comments in Julia is officially #= ... =#. I also know that multiline strings are """ ... """.

However, I have seen a lot of source codes use """ ... """ on the top of the file to write documentation, and Julia seems to interpret this as a comment (for instance: Flux.jl).

My question is: if I use """ ... """ for any type of lengthy, multiline comments (e.g. describing function parameters), would there be any type of downside over using #= ... =#? I would like to know any performance penalties, potential side effects during parsing, etc... Why would one use #= over """, other than personal preference?

like image 346
5Pack Avatar asked Jun 19 '26 23:06

5Pack


1 Answers

""" in front of the function are docstrings that are later seen by Julia's help system (e.g. when you type ?funnctionname or can be used for automated documentation generation that is usually integrated into CI processes with tools such as Travis).

To understand what is going on, try this simple Julia session:

julia> """
           myfoo(bar::AbstractVector)
       Returns the length of `bar`
       """
       myfoo(bar::AbstractVector) = length(bar)
myfoo

help?> myfoo
search: myfoo

  myfoo(bar::AbstractVector)

  Returns the length of bar

julia>
like image 125
Przemyslaw Szufel Avatar answered Jun 22 '26 06:06

Przemyslaw Szufel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!