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

Guidance on documenting functions #36

Open
shazow opened this issue Feb 7, 2016 · 7 comments
Open

Guidance on documenting functions #36

shazow opened this issue Feb 7, 2016 · 7 comments

Comments

@shazow
Copy link
Contributor

shazow commented Feb 7, 2016

What's the preferred style for documenting functions?

a() { # a does foo
    ...
}

# b does foo
b() {
    ...
}

c() {
    # c does foo
    ...
}
@elasticdog
Copy link

My preference is style B.

@progrium
Copy link
Owner

progrium commented Feb 9, 2016

B, however, I usually have a reflection based description system where I say:

declare desc="This is what my function does"

Just inside the function. I even do this when I don't have that system in place. But if you have a long description, it would make less sense there.

@shazow
Copy link
Contributor Author

shazow commented Feb 9, 2016

Do we want to include a full example? Ideally with usage and other kinds of verbose stuff people might have. I've been using this style here https://github.com/shazow/dotfiles/blob/master/helpers.bash

# b does foo by performing baaz
# Example:
#     $ b quux
#     someoutput
b() {
    ...
}

Ideally something that parsing/extracting won't be too hard.

@progrium
Copy link
Owner

👍

@silopolis
Copy link

AFAIC, 'B' too, and going a little further with bashdoc.sh script:

http://wiki.sourcemage.org/bashdoc
https://github.com/eatnumber1/envbot/tree/master/tools/bashdoc

Used to have a bookmark to this script website but can't find it.
This is the first refs DDG returned me and it's not bad to see it used in a
complete bash project.

My 2 cts

Jérémie Tarot
http://about.me/silopolis

@ingkebil
Copy link

Sorry for bumping an old thread!

B, however, I usually have a reflection based description system where I say:

declare desc="This is what my function does"

Just inside the function. I even do this when I don't have that system in place. But if you have a long description, it would make less sense there.

I'm not familiar with a 'reflection based description system'. I've googled around, but don't seem to find anything that would enable me to use the desc declared inside a function. How does one go about using this?

@progrium
Copy link
Owner

@ingkebil Using declare -f gets you the source of a function, which you can then process as text. Here is a module with this little bit of code that gets us this kind of reflection: https://github.com/gliderlabs/glidergun/blob/master/src/fn.bash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants