views:

175

answers:

6

I need to document the software I'm currently working on. The software consists of several programming languages and scripts which got me thinking. If a new developers comes along and needs to fix something, they might know Java but maybe not bash scripting. It would be nice if there was a program which would help to understand what

for f in "$@" ; do

means. I was thinking of something that creates a static HTML page with the code plus syntax highlighting and if you hover over something (like the "for"), it would display a pop-up with an explanation:

for starts a loop which iterates over all values that follow in. In the loop, you can access each value via the variable $f. The loop body is between do and done

Does something like that already exist?

[EDIT] This is just an example. You'll get another help for f, in, "$@", ; and do, i.e. each and every element of the line should be explained. Unknown elements (like command names) should link to Google. So you can understand what it does even if you're missing some detail.

[EDIT2] I'm aware that you can't write a program which understands what another program does. What I'm looking for is a simple tool which will do "extended syntax highlighting" in the sense that it will color an expression and give a short explanation what it means (plus maybe a link to some in-depth reference).

This is meant for someone who knows how to program but maybe hasn't seen some obscure construct before. Say

echo "Error" 1>&2

Every bash programmer knows what this means but a Java developer might be puzzled by the 1>&2 despite the fact that they can guess that echo == System.out.println. A simple "Redirects stdout to stderr" will clear things up and give that instant "AHA!" which allows them to stay in their current train of thought.

A: 

If you think about it, it's not that useful to have a tool that explains the syntax. Developers could just google for keywords instead of browsing a website in a similar fashion to http://www.codeweblog.com/source/ .

I believe that good comments will be by far more useful, plus there are tools to extract the documentation by using the comments (for example, HappyDoc does that for Python).

altvali
The good comments will explain the high level details. But for me, it's obvious what `"$@"` means, while another developer will just stare at it in frustration. I understand that this tool won't allow to create automatic documentation; it's just a "smart lens" that can answer detail questions.
Aaron Digulla
Then why not add an inline comment about "$@"? You can add tags for comments too, like #TODO: ... or #FIXME: ... or #SEEME: ... or, in this case, #NOTICE: "$@" does this little thing ...On a sidenote, what would the benefit be for someone who doesn't know bash but knows Java to know what "$@" does, besides knowing the high level details? Surely you're not expecting him to debug or fix without learning bash?
altvali
Because I don't know what the next developer might know and I surely don't want to explain every character in every line of my code!
Aaron Digulla
A: 

It is a very tricky thing. First of all by definition it can be proven that program that will "understand" any program down't exist. However, you can still use existing documentation. Maybe using tools like Doxygen can help you. You would need to document your code through comments and the documentation will be generated from them.

Gabriel Ščerbák
You can find tool which supports even more languages here:http://sourceforge.net/projects/naturaldocs/
Gabriel Ščerbák
I just want new developer spare the effort to look up every detail of an unknown programming language in a book or Google. I'm not looking for a tool which can "understand" but one which "helps to understand"
Aaron Digulla
@Gabriel: This generates nice looking documentation from source code comments. I'm aiming for something that works on a lower level.
Aaron Digulla
hmm, so you want something like Javadoc view in Eclipse, although with information even to the language level...? doesn't seem so useful... new developer has to be familiar with the language, because he will surely have problems with libraries and frameworks and looking up things on different levels of abstraction won't help.IMHO first get familiar with basic concepts and then add more, don't try to get all at once.
Gabriel Ščerbák
+1  A: 

IMO it would be simpler and more effective to just collect links to good language-specific references and tutorials on a Wiki page.

For all mainstream languages, such sources exist and are maintained regularly. If you try to create your own reference, you need to maintain it too. Fair enough, bash syntax is not going to change very often, but other languages do develop faster, so it is going to be a burden.

Péter Török
It would be better to collect those links in a tool which can connect them to the relevant parts of the language-specific reference. How often have you tried to read some perl just to wonder where in the docs to even start looking for something?
Aaron Digulla
I understand the version problem. I figured that you'll have to run the tool on the machine with the scripts and it will call `bash --version` and add that to the HTML page (so it knows which syntax is correct). Yes, it's an effort but not an insurmountable one.
Aaron Digulla
@Aaron Digulla Ah, now I get your idea. And it sounds intriguing indeed. I would still say that a tool which links to explanation of syntax for a particular construct is only a superficial help. In order to use a language element properly, one must understand its semantics, side effects... often there is a hell of a lot of underlying complexity. So knowing the syntax (and only the syntax) might give a false sense of control to junior developers.
Péter Török
If they don't understand the concept, they at least know what to google for. Try to google for ">>".
Aaron Digulla
@Aaron Digulla I agree with that. Used wisely, it would certainly be a useful tool. In fact, this sounds like an exciting idea for an open source project if no such tool exists yet :-)
Péter Török
Agreed. Since I haven't seen anything so far and no one on SF seems to know something like this, either, I might just do that. When I do, I'll post an answer here.
Aaron Digulla
A: 

A language cannot be explained only through its syntax. The runtime environment plays a great part, together with the underlying philosophy of the language and libraies.

Moreover, syntax is not that complex for most common languages (given that code has been written with maintainability in mind).

Going on with bash example, you cannot deeply understand bash if you know nothing about processes & job control, environment variables, a big list of unix commands (tr, sort, cut, paste, sed, awk, find, ...) and many other features that don't appear in syntax.

mouviciel
Aaron Digulla
My point is that the reader may not understand the very concept of "running a command in the background" and will in the end look up the whole language. What is best? spending time to implement popups on every syntax element, spending time to teach bash to someone who already know java or spending time to hire someone who already know bash and java? I wouldn't choose the first solution.
mouviciel
If they don't understand this concept, you at least know what to google for. Try to google for ">>".
Aaron Digulla
+2  A: 

A tool like this could be built using ANTLR, i.e. parse the code into an abstract syntax tree using an ANTLR grammar for that language, and write an HTML generator which produced the annotated code.

It sounds like a useful tool to have for language learning, or exploring source code of projects you're not maintaining -- but is it appropriate for documentation?

Why is it important to help the programmers of other languages understand the code at this level of implementation detail? Anyone maintaining the implementation at this level will obviously have to know the language and will probably have an IDE to do most of this.

That said, I'd definitely consider a tool like this as a learning aid.

mattbh
I won't use this tool to document my work. I'll use it as a maintenance tool through which the next developer can run any script to understand all those little tricks he doesn't understand :-)
Aaron Digulla
mattbh
A: 

If the tool produced

for starts a loop which iterates over all values that follow in. In the loop, you can access each value via the variable $f. The loop body is between do and done

it would be pretty worthless. This is exactly the kind of comment that trainee (human) programmers are told nver to write.

anon
-1 Sorry, you didn't understand the question at all.
Aaron Digulla
@Aaron That is often the fault of the questioner.
anon
@Aaron: He did understand the question, you didn't ask a proper question tho :p.
Younes