News for hackers. Stuff that matters.
Re:Four kinds of documentation by protomikron on Friday October 18, 2019 @07:43AM (#21290458)
My pet peeve is auto-generated documentation from configuration files or source code. It is absolutely useless and I would rather prefer no documentation than auto-generated.

Some time ago Swagger (nowadays OpenAPI) got really popular and many projects "had an API" and pointed users to their green autogenerated API documentation clusterfuck. When time went on this green page would become an indicator for me, that the project does not work and I should be very sceptical - I am sure there are projects that do it better, but for me no-content auto-generated documentation is a real code smell.

Re:Four kinds of documentation by dtech on Friday October 18, 2019 @09:08AM (#21291035)
I do not share your experience, because in my experience the auto-generated docs will be kept in sync with the code/API while a separate specification will become outdated over time.

This does of course require human-readable description in all the endpoints. But that's the same as only an autogenerated function signature in code documentation vs an added human-readable description.

Re:Four kinds of documentation by tootie on Friday October 18, 2019 @10:49AM (#21291844)
I've said before that the killer feature that launched Java wasn't garbage collection or checked exceptions, but javadoc. Autogenerating HTML documentation based on strictly-typed interfaces was absolute genius and I really haven't seen it topped by any modern language.
Re:Four kinds of documentation by usrusr on Friday October 18, 2019 @12:05PM (#21292522)
The problem with this family of tooling is that they are essentially fill-the-blanks forms and that all the surrounding ceremony is generated indiscriminately of wether the blanks were actually filled or not. Or worse: (pre-)filled with redundant placeholders like "@return returns the $Typename".

The frustration pointed out by OP is that when you see a page of "blank" generated documentation you never know if there is valuable information waiting for you maybe just one or two clicks away or if it's placeholders all the way down. Consuming a sparsely filled doc almost feels like being trapped in an illustration of the halting problem.

A javadoc/-like implementation that somehow put the actually authored subset into the spotlight while not completely skipping the inferred bits could be very valuable.

(also: a javadoc/-like compiler that detects as much delegation as possible and aggressively pulls in stronger documentation when it is available further up or down the call nesting)

Re:Four kinds of documentation by coldtea on Friday October 18, 2019 @01:41PM (#21293432)
>The problem with this family of tooling is that they are essentially fill-the-blanks forms and that all the surrounding ceremony is generated indiscriminately of wether the blanks were actually filled or not.

Still better than 90% of projects/libs at the time, who didn't have any reference documentation at all.

Just seeing the signatures and packages in an organized manner with cross links (e.g. to parent class, implementing classes) etc, was a vast improvement...

Re:Four kinds of documentation by dtech on Friday October 18, 2019 @12:25PM (#21292704)
Exatly. A "/ @return String */" is absolute garbage Javadoc, but that does not mean that the concept is bad or cannot be put to good use.
Re:Four kinds of documentation by usrusr on Friday October 18, 2019 @08:05PM (#21295976)
Sure. Even the most sparsely populated javadoc suddenly turns from a nightmare into a valuable improvement when you stop trying to pull information with a browser and just enjoy what the IDE presents when implementing an API client, if it is presenting something. More authored content is still better than less, but the amount of empties remaining stops being a hindrance when consumed through an opportunistic push mechanism.
Re:Four kinds of documentation by lalaithion on Friday October 18, 2019 @12:12PM (#21292592)
This is also a great feature of Haskell, especially Hoogle, which is what I miss the most when working in Java. If I want to find a function which, say, removes items from a Map based on a function over values, in Java I have to look and see if it's in the Map class. Nope. Is it in Guava Maps? Ah, there it is, "filterValues".

In Hoogle, I can type `Map k v -> (v -> Bool) -> Map k v` into the search bar, and it finds the function, even though I got the order of the arguments wrong.

https://hoogle.haskell.org/?hoogle=Map%20k%20v%20-%3E%20(v%2...

Re:Four kinds of documentation by rovolo on Friday October 18, 2019 @12:54PM (#21292950)
I'm impressed. Being able to search for functionality by the function signature seems incredibly useful. In the "Verb-Noun vs Noun-Verb" thread from a couple days ago [0], people were saying that OO languages make autocomplete much easier because you start with the parameter you're operating on. But, autocomplete (at least in IntelliJ) only lets you search by method name. There have been lots of times where I want to search by return type or param type instead.

When you're looking for functions, do you generally use Hoogle, or do you have a local autocomplete-like feature hooked in to your editor? I really want to be able to use this while writing code.

[0] https://news.ycombinator.com/item?id=21271212

Re:Four kinds of documentation by marcosdumay on Friday October 18, 2019 @04:35PM (#21294867)
If you try, you'll discover it is much less useful in Java. That's probably the reason it's not available there.

Pure languages get a lot of hate, but this is the kind of thing you get when you enable better static analysis of your code.

Re:Four kinds of documentation by ergothus on Friday October 18, 2019 @05:59PM (#21295397)
Interesting, because when I switched to Java I absolutely hated (and still do!) the autogenerated documentation. Included was every variation of the constructor. Missing was HOW I would actually call it, and where I would get the params to it.

It's been the better part of a decade, so I can't actually quote correct APIs, but I recall trying to connect to an LDAP server - I just needed to call one of four constructor methods, which seemed to imply I needed an LDAPContext object. Looking at that object told me the 10 bajillion values it had, but no idea how to set them.

Once I saw an _Example_, which IIRC was basically calling a method to clone the default context object and setting the one or two params (such as server url), I could then pass that to one of the constructors I saw the docs for.

The generated documentation was 100% _correct_, but not _useful_.

Other languages I had been in had very example-focused documentation, and were far more accessible and usable as a result, even with occasional challenges where the docs might slip behind - that almost always tended to be corner cases, while the Java approach made the most common need into a corner case.

Re:Four kinds of documentation by GordonS on Friday October 18, 2019 @06:17PM (#21295512)
At the end of the day, it's up to the developer to provide useful documentation.

Especially in the enterprise world, I often come across completely useless code docs, created purely to satisfy SonarCloud or an otherwise stupidly dogmatic gated checkin of the "all public methods must have code docs!" variety. I'm sure many of us have come across it - code docs for a constructor that say "Constructs a Widget", or for an `AddWidget` method that says "Adds a Widget"; utterly pointless. I think of this as "dogma driven documentation".

Re:Four kinds of documentation by lelandbatey on Friday October 18, 2019 @01:10PM (#21293133)
I'll definitely assert that Rust has nailed the automatic generation of documentation from comments in source code. It's a somewhat unusual language so getting used to how the docs are laid out toook a bit of time, but once I was using the language, the docs are the best I've ever used. Some examples:

https://docs.serde.rs/serde_json/

https://doc.rust-lang.org/std/vec/struct.Vec.html

Re:Four kinds of documentation by ojosilva on Friday October 18, 2019 @10:59AM (#21291932)
Typedoc [1] is an excellent documentation generator for Typescript.

And every other modern language, be it statically typed or dynamic (with the help of annotations), has had some sort of auto-documentation generator either bundled or at package manager's reach, and probably any can top javadoc in many ways.

[1] https://typedoc.org/

Re:Four kinds of documentation by pandalicious on Friday October 18, 2019 @12:41PM (#21292829)
The .NET standard library docs are a thing of beauty because they intermingle autogenerated javadoc-style documentation with generally well-written freeform "remarks" sections that include more general explanations, context, and code samples.
Re:Four kinds of documentation by codys on Friday October 18, 2019 @01:47PM (#21293496)
I've struggled through doxygen generated docs for C++ before, and I think one of the things that helps make javadoc more readable is due to the "stricter" (in a sense) structuring of the java language vs C++: namespaces & objects everywhere make grouping more likely to occur in consistent ways in the code base, which then gets translated to more readable auto-generated documentation.

This is something I think rustdoc (for rust) also has succeeded at, partially for similar reasons.

Re:Four kinds of documentation by protomikron on Friday October 18, 2019 @09:40AM (#21291249)
> I do not share your experience, because in my experience the auto-generated docs will be kept in sync with the code/API while a separate specification will become outdated over time.

Does it? You can just alter the code and forget to alter the documentation above the functions/methods, so I don't think there is much of a difference. And wrong documentation is worse then no documentation.

You have to write your documentation, keep it up to date and take it seriously. I would argue, if you have auto-documentation you are more likely to miss that, because you have some kind of documentation somehow - irregardless if it's actually useful.

Re:Four kinds of documentation by steveklabnik on Friday October 18, 2019 @10:35AM (#21291718)
With Rust, we help mitigate this by running code examples in API documentation as tests. That doesn't stop people from opting out, and it doesn't solve every problem, but it's still quite useful!
Re:Four kinds of documentation by mdtusz on Friday October 18, 2019 @11:07AM (#21291997)
I'm sure you know because you're Steve Klabnik, but for other readers: you can enforce documentation for public items in a crate by adding `#![deny(missing_docs)]` to the `lib.rs` file.

Then it just takes some self-control and gold code reviews to make sure you're writing good documentation rather than just short stubs to silence the error.

Re:Four kinds of documentation by steveklabnik on Friday October 18, 2019 @11:23AM (#21292132)
You’d think, but I have certainly committed (in both the colloquial and git sense) a dummy /// TODO comment to silence this warning... oops
Re:Four kinds of documentation by joshmarlow on Friday October 18, 2019 @04:56PM (#21295012)
I'm going to hijack this thread to recommend Rust Skeptic - https://github.com/budziq/rust-skeptic

It checks for rust snippets in markdown files and attempts to build them when you run `cargo test`. It helps keep docs and code in sync.

Re:Four kinds of documentation by 725686 on Friday October 18, 2019 @11:00AM (#21291941)
"Does it? You can just alter the code and forget to alter the documentation above the functions/methods"

Yes you can forget, but the barrier is much, much, much lower than having to modify a document god knows where.

Re:Four kinds of documentation by minxomat on Friday October 18, 2019 @10:06AM (#21291449)
For abstract descriptions of what the code does, sure. But for small things like documenting the purpose of arguments, an IDE should warn about changes that are not reflected in the doc comment (type or a new arg altogether). IntelliJ IDEs are pretty good at that.

Rust for example also warns about code included in the doc comments example section which is invalid.

Re:Four kinds of documentation by ses1984 on Friday October 18, 2019 @09:44AM (#21291283)
I've used swagger with java and golang and both of them generate docs directly from the code, no comments needed.
Re:Four kinds of documentation by protomikron on Friday October 18, 2019 @09:46AM (#21291296)
But what's the point then? If there's a tool, that can make "documentation" out of source code, I can just look at the source code?
Re:Four kinds of documentation by kazagistar on Friday October 18, 2019 @10:06AM (#21291440)
Mostly it collates all your endpoints more easily, generates clients for different languages, genearates an online documentation and test page that makes your service self describing, and can be published out to third parties that dont have access to your code.
Re:Four kinds of documentation by curryst on Friday October 18, 2019 @02:18PM (#21293783)
The tool parses out the bits that you're interested in. If you want to know what year the proverbial apple fell on Isaac Newton's head, you can get a biography and start reading, or you can Google and let the machine filter out the irrelevant bits.

If I'm looking at documentation, I want the inputs and outputs and a brief description of what it does. I care very little about the implementation, or I would write my own.

Re:Four kinds of documentation by teknopaul on Friday October 18, 2019 @10:44AM (#21291789)
Presumption that all code is open source. The war is won :-)
Re:Four kinds of documentation by chipotle_coyote on Friday October 18, 2019 @11:44AM (#21292336)
The article talks about four kinds of necessary documentation for large projects: explanation, reference, how-to guides, and tutorials. Auto-generated docs, even when they're very good, only provide one of those -- the reference.

Even if you have great inline documentation that can be turned into a great external reference document, you need separate documentation.

Re:Four kinds of documentation by xtiansimon on Friday October 18, 2019 @09:28AM (#21291167)
I've been trying to get my head around a particular Swagger project. Here is a funny email exchange from my request for documentation:

... Hi, I reaching out to to ask if I could get my hands on some documentation because the API is somewhat a black box to me.

... The api documentation for [product] can be found here: https://api.[product].com/

... Sorry. That's not what I mean by "documentation". It's certainly non-linear. I don't know how to "read" this site to gain an understanding. It's kinda sparse:

   GET /v2/adjustments > Implementation Notes: Fetches a list of adjustments.

   GET /v2/reportCategories > Implementation Notes: Fetches a list of report categories.
... Hm, I think swagger documentation is pretty standard among APIs I've worked with before. I'm pretty sure it's all they have.

... "Swagger Documentation" is a special class of documentation for sure; Nobody likes writing documentation.

Talk about insider (them)/outsider (me).

Re:Four kinds of documentation by SamuelAdams on Friday October 18, 2019 @04:13PM (#21294718)
Isn't that the point of an API though? To be a black box? The example you provide is fairly simple: you hit these endpoints and get this kind of data.

If you need to add data to one endpoint and see how that travels to other endpoints, that makes sense as to why you want documentation. In that case, a product / API tutorial or recipe (like the author suggests) might be useful.

Re:Four kinds of documentation by remotedeveloper on Friday October 18, 2019 @07:49AM (#21290487)
I work with a very large, complicated piece of software which has quite a comprehensive API but it's basically CRUD on top of a database. There is zero documentation about what happens when you update an object - only OpenAPI. To find that out, you would have to dig in to the database triggers. Half of working with it is trial-and-error and the other half is hope-and-pray.
Re:Four kinds of documentation by JoeAltmaier on Friday October 18, 2019 @08:01AM (#21290578)
Same here. Why is documentation standard so low? Tell me how that buffer management works (do I provide it? delete it? when? how?); how threading is supported (reentrant? send/receive at the same time/different threads? interprocess?); dependencies (necessary initialization? teardown? states in between?); efficiency (can I hold a lock around the call? does it block?).

Instead, we often get nothing but a method name and argument types. Ridiculous.

Re:Four kinds of documentation by TuringNYC on Friday October 18, 2019 @09:28AM (#21291166)
>> Same here. Why is documentation standard so low?

Because those who control resources make a conscious decision to prioritize new features and/or bug fixes rather than documenting what exists already.

Re:Four kinds of documentation by xtiansimon on Friday October 18, 2019 @09:41AM (#21291255)
I really like writing the first draft of documentation. I get to run through the endpoints and even fine tune some of the details to fit to the big idea I'm creating about what the software does and how to use it best.

The problem comes months later when I'm in the weeds and a colleague asks a question. I try to fob them off to the documentation, but some details are out of date. I pray it's just one detail, and that I don't have to stop what I'm doing to rewrite the documentation now.

Re:Four kinds of documentation by chucksmash on Friday October 18, 2019 @01:36PM (#21293382)
That's part of it. Plenty of working developers will also omit tests and documentation even without the feature-factory time pressure though. A lot of times, the need for technical documentation isn't even a blip on the TODO radar. If I had a dime for every README where the last change was "Initial commit" and the file only contained

# <PROJECT NAME> Service

This is the new service for <TASK>.

....I could buy a good README.

Re:Four kinds of documentation by michannne on Friday October 18, 2019 @08:49AM (#21290920)
Because docs take time to write, and good docs require a passionate dev who cares to write them
Re:Four kinds of documentation by dragonwriter on Friday October 18, 2019 @09:08AM (#21291040)
Good docs take a dedicated tech writer who cares to write them. A passionate dev may or may not be a decent tech writer.
Re:Four kinds of documentation by crdoconnor on Friday October 18, 2019 @10:03AM (#21291419)
Also because it's hard work that reduces the employer's dependency on that developer.
Re:Four kinds of documentation by the_af on Friday October 18, 2019 @09:13AM (#21291069)
...plus they tend to get outdated and out of sync with the code pretty fast!
Re:Four kinds of documentation by dragonwriter on Friday October 18, 2019 @04:03PM (#21294636)
Not if the first step of updating the code is updating the documentation to reflect the intended state after the code update, preferably with embedded doctests that form part of the definition of done for the code changes.

Sure, if documentation is treated as an afterthought it tends to reflect that attitude.

Re:Four kinds of documentation by dllthomas on Friday October 18, 2019 @04:52PM (#21294979)
In my experience, once you've got a bit of documentation, finding everything relevant to an intended change can be non-trivial and error-prone even if it's done first.

For documentation to remain relevant there needs to be some kind of process actually checking every part of it against reality.

Re:Four kinds of documentation by the_af on Friday October 18, 2019 @04:59PM (#21295028)
Plus you cannot really automate checks for documentation up-to-dateness.

I mean, with actual code you get some help from the tools. No silver bullet, but at least you have type checks, compiler errors, something. But with docs there's no way to automate checks to see if the doc is still relevant and accurate. And what terrible tools are there tend to lead to "boilerplate docs", like those javadocs mentioned in a comment elsewhere.

Re:Four kinds of documentation by dllthomas on Friday October 18, 2019 @05:55PM (#21295379)
I mean, where it's applicable doctest is amazing. But that's not everywhere.

I've been wanting some kind of system to add references to tests to documentation, in the spirit of citation. Maybe I will build it at some point.

Re:Four kinds of documentation by the_af on Friday October 18, 2019 @04:16PM (#21294742)
> documentation is treated as an afterthought

Bingo.

Do note that people here on HN live in a bubble where, for example, writing tests (any tests, not even good tests) is a given. But out there in the world there's plenty of software coding, a lot of it in major companies, where developers think testing is some cute but useless thing they teach you in college and which can be safely skipped, and managers are completely oblivious about this. Same with writing useful documentation.

Re:Four kinds of documentation by afarrell on Friday October 18, 2019 @08:45AM (#21290887)
> Why is documentation standard so low?

Even in companies where good documentation would raise revenue in a way that the sales team notices[1], someone still needs to write it and someone still needs to make the business case for writing it.

Engineers could, but many don't. If you're passionate about good documentation, but don't think you can deliver, it would be foolish to unless someone else is doing the writing.

I'm a bit of an extreme case, but Many engineers feel so incredibly uncomfortable with writing prose that they avoid it. Why? The standard of writing education for STEM-minded people is low. Why? Writing education in high school is focused on literary analysis essays rather than on learning to describe facts and systems with vibrant clarity.

[1] https://getputpost.co/overhauling-api-docs-with-gocardless-9... ---

Anecdote: At age 14, my school had poster which listed the professions one could use mathematics in. Someone pitched us on how much need there was for people who could program. Shop classes and science classes had assignments which were miniature versions of problems we could see in the real world. Nobody did this for literary analysis. I didn't know how to ask "why are we doing this?" other than as a snotty teenager saying "Hey english teacher! Justify why your life's work has meaning." In reality, I wanted to say "I'm having trouble getting oriented around this subject. I'm having trouble understanding what it means to make progress or make something good. Can you help me?"

I searched for writing advice devoured works like Politics and the English Language and Strunk and White. But they just helped me get better at editing, not at putting thoughts onto a blank page.

Anecdote: At age 17, I told my English Literature teacher that I wanted to write really good physics tutorials. She looked confused at me and said "Why? Thats so boring." At age 17, I didn't have the self-confidence to persist to find a different teacher who would be interested in that.

Anecdote: At age 20, in an engineering university, I knew that I struggled with getting the first draft of an essay done. I went to the writing center at my school. But I never built a good workflow with them for how to get the first-draft-writing process. I didn't know how to learn to write without an anxiety so strong that I felt compelled to dig my nails into my skin. I didn't know how to ask professors or TAs for help. I accepted that writing was just staring at the paper until my eyes bled. I wasn't going to learn to write. I endured my required writing classes. hoped that once I graduated, I might be able to work in a way to

Anecdote: At age 29, I had to quit a visa-sponsoring software engineering job and very quickly find a new one, because of my failures with writing first drafts interacted with a business process for immigration-law compliance.

---

I've now found two coaches and plan to spend this Saturday working on a first draft of a blog post and trying some of their strategies. Wish me luck.

Re:Four kinds of documentation by touisteur on Friday October 18, 2019 @12:27PM (#21292719)
One book that (unexpectedly) gave me good tips on 'how to write' was Zen and the art of motorcycle maintenance. At some point the main character, who's a teacher in rhetoric, finds out that no one of his students know how to write. They all learned through analysis how great author have written this or that way, but they don't know where to start. They don't know the great authors probably didn't consciously decide to say 'here I'll put a metaphor, now a simile, and here you go, ellipsis'... They probably started with something simple, badly expressed, and refined, polished, restarted, embellished, simplified... The bigger hurdle of his students seems to be 'the first draft', the initial idea, the first words. Not even a 'blank page' problem. He gives them exercises in pure description, simpler and simpler and most of his students can't even start the first words. The funny 'solution' is just to start and write... Something... (and I'm not doing the book justice here sorry... I really like it, not as a philosophy reference (I've read many negative critics on this), but how it mixes the pain of being a father or a kid, the pain of mental illness, the pain of feeling cleverer than your peers, and the pain of being a teacher, a writer and a friend. All wrapped in a beautiful and sad storyline, lots of beautiful American scenery, and some advice on motorcycle maintenance...).
Re:Four kinds of documentation by UserIsUnused on Friday October 18, 2019 @10:51AM (#21291861)
>Anecdote: At age 17, I told my English Literature teacher that I wanted to write really good physics tutorials. She looked confused at me and said "Why? Thats so boring."

I laughed and then I got sad

Re:Four kinds of documentation by zomglings on Friday October 18, 2019 @10:58AM (#21291923)
Good luck and, for what it's worth, that was a very well-written comment.
Re:Four kinds of documentation by afarrell on Friday October 18, 2019 @01:13PM (#21293157)
Writing comments doesn't feel like "writing" to me; It feels like talking.

I've actually written some pretty long comments on reddit. Yesterday, I talked with one of my coaches and put some thought into why:

1) I don't have any memories of feeling anxiousness from commenting on reddit. This is unsurprising since it has never been assigned to me by a teacher/parent. If I ever feel like "Its unclear why I would respond to this or what I would say to this", I just choose not to comment.

2) I have memories of writing a comment and other people upvoting it or telling me that it was helpful. I don't have this for essays. I driven by making people happy, so that is a meaningful reward.

3) Because of those positive memories, as I am writing, I can imagine that a sentence I am about to write is going to be helpful. That imagining is a bit of positive re-enforcement that I can chase, inherent to the task. It is like when I was a kid and I would do math homework and I would solve a problem and see that I'd solved it. It is one of the tricks of TDD.

So, my plan this Saturday is to seek out the things that could possibly be intrinsically rewarding about writing:

A) Look for interesting phrases that I can craft to clearly explain something.

B) When I start on a section, write a question that someone could ask on a reddit thread, which this section answers.

C) When I write a section, imagine myself saying this as an explanation in response to that question and imagine someone else expressing gratitude for that explanation.

D) To avoid procrastination, mentally rehearse the act of starting and getting into the task. Simulate the trigger-response-reward in my mind so I can build the neural pathway. The reward I imagine should not be tied to completion, but come from the "I've just gotten started" state.

Re:Four kinds of documentation by robotbikes on Friday October 18, 2019 @09:36AM (#21291230)
I think free writing such as journaling can help one get better at writing first drafts. Its important to practice the skill of getting something written.
Re:Four kinds of documentation by afarrell on Friday October 18, 2019 @01:05PM (#21293080)
Yes, since my commute changed, I've been regularly freewriting on the train and it has been helpful.
Re:Four kinds of documentation by dredmorbius on Friday October 18, 2019 @03:41PM (#21294483)
Another (possible) factor driving this is service- and support-based business models.

Good documentation, enabling user self-support, eats both cost and revenue.

(To what extent this is a conscious strategey and not simply decades-of-experience-born cynicism, I'm not entirely sure.)

Re:Four kinds of documentation by rkangel on Friday October 18, 2019 @11:02AM (#21291951)
Documentation pulled out of code is only as good as the doc comments that have been written. It does have the advantage of making it far easier to write and maintain. If you're editing a function, if the documentation is just above then you're more likely to update it.

This from the Rust standard library is a good example - https://doc.rust-lang.org/std/result/index.html . I think that's great documentation, and it's entirely generated from the source code.

Most rust libraries won't have this level of explanatory detail, the core team have put a lot of effort into making it as easy as possible to learn, and documentation effort is part of that (the Rust book is another important part).

Something else that Rust does well is that 'examples' is a standard part of project layout. For libraries that haven't done their top level documentation well, the examples folder will usually give a good demonstration of how to use the code, and they usually exist because that's the easiest thing for the library author, and the usually compile because they're automatically built by `cargo build`.

Re:Four kinds of documentation by jerf on Friday October 18, 2019 @12:00PM (#21292477)
I have some Swagger-based documentation for a few APIs I've written, and I find it very frustrating because you can see in the renderers for Swagger that nobody actually documents with it. Nominally, several of the fields are specified as Markdown, allowing for useful formatting in your documentation, but what fields are actually rendered as Markdown in a given renderer is semi-random. The top-level description usually is, but a lot of the other fields come out random. In the worst cases, not only is the "Markdown" content rendered as plain text, it also is simply slapped between <p></p>, so the newlines are eliminated.
Re:Four kinds of documentation by blattimwind on Friday October 18, 2019 @11:49AM (#21292393)
> My pet peeve is auto-generated documentation from configuration files or source code. It is absolutely useless and I would rather prefer no documentation than auto-generated.

For most applications this approach is generally useless and should not be used. Comments should be in the code itself, and you expect people who want to work on the application to read at least some of the code. I.e. no reference / API documentation for applications, instead high level overview (where is what, application architecture etc.) and guides (how to set up your dev environment, how to contribute, how to prepare releases etc.).

For libraries it often makes sense to generate a reference documentation from the code itself. The drawback is that the strictly formulaic nature of comments parsed by the documentation generator has to be always kept in mind when writing the code itself. I.e. the comments need to make sense and be comprehensive when you remove them from the code surrounding them.

Some modules in the Python standard library are a good example of this. Quite a large amount of prose, separate from the code, and then a reference section generated from code. However, many modules have pretty bad documentation, where even the reference is missing crucial information (quite often very basic things like what a function returns).

Re:Four kinds of documentation by artursapek on Friday October 18, 2019 @12:18PM (#21292647)
> Comments should be in the code itself

Rust handles this nicely; its generated docs are based off source code comments. Same with Golang.

Re:Four kinds of documentation by Waterluvian on Friday October 18, 2019 @09:05AM (#21291019)
When I was super green I argued about this with the principal engineer for quite a while about swagger.

Docs generated from code do not define the contract, they describe the code-defined contract, bugs, accidental mutations, and all. How is that not a fatal flaw?

Re:Four kinds of documentation by PeterisP on Friday October 18, 2019 @11:22AM (#21292123)
It depends on how you're party to that contract - whether you're involved in making it, or you're a consumer in a take-it-or-leave-it situation.

If I'm a consumer of some third-party API, there's no practical difference between intended behavior, accidental mutation and a bug which the supplier won't fix any time soon - all of these things are equally part of the contract of how The Thing v1.2.3 works, and that's what I want described in the documentation. Any part of the documentation that says what The Thing should do (but doesn't actually do) is worse than useless, it's actively misleading; it describes some wishful thinking with no connection to reality.

If the contract documentation describes an interface between two parts of the system that I control, and I have the ability to fix discrepancies between contract and code by altering the code, then sure, that's a different situation; but if I don't have the ability to make these changes because it's an API to code made, maintained and controlled by someone else, then accurately describing current reality is the most important thing.

Re:Four kinds of documentation by bluGill on Friday October 18, 2019 @11:45AM (#21292351)
You are mostly correct. However the contract can say "X in the API will change without notice so don't use it", which is valuable to know. Often there are things that must be exposed in the API for "reasons" but the user shouldn't use themselves.

Likewise if v1.2.3 has a bug I want to know to not rely on that because I'll probably update to 1.2.4 which fixes it.

Re:Four kinds of documentation by soulnothing on Friday October 18, 2019 @09:37AM (#21291236)
I'm for swagger but only if the router uses it.

I keep hearing swagger / contract first. But then they still manually specify `/api/v1/user/login`.

Vertx web api contract router. Which takes in a swagger file, and routes based on the `swagger` operation id. Is the closet I've seen. https://vertx.io/docs/vertx-web-api-contract/kotlin

I've also written a library to route into ktor in a type safe way.

But if you're doing swagger. To me it should be written, then consumed by the back-end service. Then generate front-end clients. Anything less will result in bugs.

I've seen companies pile on so many services. To double check code generated swagger. Hit a bug, then have to maintain the swagger spec outside and not enforce it.

Re:Four kinds of documentation by eropple on Friday October 18, 2019 @11:29AM (#21292187)
> To me it should be written, then consumed by the back-end service.

This is an option, but I find that it works better to have OAS documents generated from what the server is actually doing. Specifying routes based on what the server actually does is, IMO, a more rigorous way to create an OAS spec than to hand-write the spec and then generate a server from it.

I've written a couple of libraries that do exactly this:

https://github.com/eropple/nestjs-openapi3 - OpenAPI3 library for NestJS that standardizes input validation

https://github.com/modern-project/modern-ruby - a Ruby web framework built around OAS3 concepts + rigorous validation

Re:Four kinds of documentation by pibi on Friday October 18, 2019 @11:13AM (#21292060)
That's my mantra since 5 years now. Swaggerize-express or swole for the routing, but also swaggering-mongoose or objection's schema loaded from the yaml file for the database model. As a plus, validation is available out of the box.

less code, standard approach, less bugs.

Re:Four kinds of documentation by dtech on Friday October 18, 2019 @09:09AM (#21291044)
A separate specification works much better as long as that specification is also enforced during the build.

A separate openapi spec that is not enforced can quickly become outdated, then an auto-generated from code is better.

Re:Four kinds of documentation by undreren on Friday October 18, 2019 @09:29AM (#21291175)
You can add two new columns to your Kanban board called "Documentation" and "Documentation Review".

Then tasks cannot move to your "Done" column unless documentation is written and passes review. If you enforce column limits documentation it will also block other tasks if not completed.

Re:Four kinds of documentation by Waterluvian on Friday October 18, 2019 @10:31AM (#21291672)
In addition to this (and going a bit off topic). I've been adding checklists to Github PR templates (it's really easy[1]) for things like, "Did you re-read the relevant API docs? Do they need to be changed?" and it helps me a ton.

[1] https://help.github.com/en/articles/creating-a-pull-request-...

Re:Four kinds of documentation by undreren on Friday October 18, 2019 @10:47AM (#21291826)
Checklists work so well. A kanban board has all the same qualities if used correctly :)
Re:Four kinds of documentation by dtech on Friday October 18, 2019 @12:23PM (#21292688)
I have about as much confidence that is gonna work as I'd have in a (non-automated) "Test" and "Test review" column
Re:Four kinds of documentation by undreren on Friday October 18, 2019 @03:51PM (#21294538)
Cool.
Re:Four kinds of documentation by lkschubert8 on Friday October 18, 2019 @10:12AM (#21291508)
I would argue that's even better than documentation that defines how the code should behave.
Re:Four kinds of documentation by Consultant32452 on Friday October 18, 2019 @07:56AM (#21290533)
I use javadocs all the time. Those are generated off comments in code. Is that the kind of thing you mean?
Re:Four kinds of documentation by protomikron on Friday October 18, 2019 @08:06AM (#21290608)
Yes.

Now if you use human language to document your functions (methods) that is not a problem, but too often I see something like:

    public class BookStore {
        ...
        
        /**
        * @param book The book.
        * @return The price.
        */
        public static float getPrice(Book book) {
            return book.price()
        }
    }
No shit sherlock! I admit that this is a contrived example, but you get my point.
Re:Four kinds of documentation by noxToken on Friday October 18, 2019 @09:32AM (#21291191)
> No shit sherlock! I admit that this is a contrived example, but you get my point.

Not a contrived example. There are an absurd amount of libraries that do this and call it documentation. There will be a nice, tidy example of how to use the library with a toy example. That's fine. The intro probably doesn't need to go that deep. Then I move to the technical documentation or API, and that's what they have to offer.

Re:Four kinds of documentation by Consultant32452 on Friday October 18, 2019 @09:05AM (#21291018)
I've written MANY javadocs like this, and I agree they are useless. They are derived from draconian build processes that fail builds when there's not a javadoc present. So for trivial methods like setters and getters this is the kind of comment/javadoc you get from me.

Of course, the other side of this coin is that without these draconian build processes I probably wouldn't write the useful kinds of javadocs I write for significant methods.

Re:Four kinds of documentation by acidburnNSA on Friday October 18, 2019 @08:41AM (#21290863)
Yeah, I was coming to say it can be done right, and that's your point too. If you spend the time to put what a thing does, why it does it, and how it does it, with meaningful hyperlinks to related things, then the auto-collected docs can be really slick.

Maybe "auto-collected" is a better term for this than "auto-generated". I agree that auto-generated docs almost by definition don't add much. But if you go in and write narrative and have it get nicely collected into a slick hyperlinked webpage by things like doxygen and Sphinx, then that's great.

Re:Four kinds of documentation by harimau777 on Friday October 18, 2019 @08:57AM (#21290951)
It seems to me that the issue with auto-collected code is that, if done well, it captures the behavior of the code itself. However, it doesn't capture the specification of how the system should work (as opposed to just how it does work) or the higher level design and strategy of the system.
Re:Four kinds of documentation by acidburnNSA on Friday October 18, 2019 @09:05AM (#21291022)
I agree with that too. There needs to be a lot of pure narrative in addition to the auto-collected API Docs. My big project has User Guide (with intro, vision, tutorials and how-tos), Developer guide (with architecture description, requirements specs, implementation overview) and then auto-collected API docs with all the details of how it's currently implemented. In the "notes" admonitions throughout the API docs, there's a some historical information and description of why it is the way it is and how it should ideally be (as appropriate). This feel like it works pretty well. Then again, I wrote a lot of it so I'm biased.

There should be a roadmap somewhere as well, possibly in a Wiki or the developer docs.

Re:Four kinds of documentation by the_af on Friday October 18, 2019 @09:15AM (#21291075)
It's not a contrived example. I see it all the time in Java codebases, and it drives me mad. I always flag it in code reviews and demand an explanation: "what purpose does this comment serve? What would be unclear if we removed it?".
Re:Four kinds of documentation by Karliss on Friday October 18, 2019 @08:50AM (#21290925)
There is also "@param p price". How about not giving argument single letter name so that you don't have to explain it in comment.
Re:Four kinds of documentation by marcosdumay on Friday October 18, 2019 @04:46PM (#21294937)
That comment says the code author actively stopped to think about the function and didn't find anything worth noticing about it.

It is a completely different situation from the lack of such a comment, that implies that the author didn't stop to consider the function, and you can find any kind of strange things when calling it.

Re:Four kinds of documentation by tomcam on Friday October 18, 2019 @03:13PM (#21294238)
My favorite by far is

    y++; // Bump y
Instead of

    y++; // Do we need error checking for top of y axis?
Re:Four kinds of documentation by random3 on Friday October 18, 2019 @01:19PM (#21293209)
My pet-peeve is technical documentation that is not versioned with the code. I think you're confusing garbage-in / garbage-out or interface rendering with auto-"generated" documentation.

Just like you can write bad code, you can write bad docs, not update them etc.

The point of code generated documentation is not to render the interfaces but rather to keep code and docs in sync in the same place. It's more likely you'll se an out of sync / undocumented piece during a code review, in context, etc. then to assume it was updated somewhere else.

Re:Four kinds of documentation by simonsarris on Friday October 18, 2019 @02:18PM (#21293781)
We have a similar four-part documentation strategy: Tutorial, Technical introduction pages, Auto-generated API, and Samples

Many people hate auto-generated API documentation because library authors do not write enough of it.

For example here are my project's auto-generated documentation from source code, for two classes:

https://gojs.net/latest/api/symbols/Diagram.html

https://gojs.net/latest/api/symbols/GraphObject.html

That's 1238 words and 1408 words before you even get to the constructor.

There should be a lot of information that comes out of the auto-generated API: What it is, what to know, different kinds of classes interact, and where to go next.

Then of course a primary tutorial: https://gojs.net/latest/learn/index.html

And then conceptual Intro pages: https://gojs.net/latest/intro/index.html (62 of them, covering everything from high level concepts to printing)

Then, since so many people learn by example, hundreds of samples, organized with pictures and tags for each, with an explanation and commented code: https://gojs.net/latest/samples/index.html

Re:Four kinds of documentation by mfer on Friday October 18, 2019 @09:35AM (#21291217)
If you want your project to get real uptake and usage it's important to have fantastic documentation. Autogenerated documentation does no provide this. It is good as supplemental rather than primary documentation.
Re:Four kinds of documentation by franciscop on Friday October 18, 2019 @12:04PM (#21292513)
I have experimented with some tools to generate 3rd party docs for quick reference (didn't get far though). Not for my projects, but to analyze 3rd party project APIs.

Why do you think it's useless? What part is useless? I am considering taking on this project at some point in the future.

Edit: also I am referring to a library's API while I think you refer to a RESTful API. Would your comment also apply to libraries's API?

Re:Four kinds of documentation by workthrowaway12 on Friday October 18, 2019 @07:59AM (#21290563)
might be a swagger/openapi issue. golang for example does generated doc quite well imo. i wish other languages had the same.
Re:Four kinds of documentation by GordonS on Friday October 18, 2019 @06:10PM (#21295467)
I find auto-generated documentation useful for libraries, and for powering intellisence kind of docs for libraries - it's pretty useless for anything other than libraries/APIs.

Unfortunately, in my experience a lot of devs turn on auto docs in their project's settings and call it a day, especially if it's not a library/API!

Re:Four kinds of documentation by weaksauce on Friday October 18, 2019 @12:22PM (#21292681)
I feel similar though it’s better than nothing to me. It’s feels like describing what a forest looks and operates by listing every tree in the forest. I want the higher level overview of component parts.