remix logo

Hacker Remix

What docs-as-code means

100 points by remoquete 3 days ago | 111 comments

NiklasBegley 3 days ago

I think this is a really good point in the post:

> If you don’t review, check, and merge docs the same way your org reviews, checks, and merges code, you’re not doing docs-as-code — you’re doing docs-as-bore.

While some WYSIWYG cloud-based docs platforms make it easier to make changes, that's not necessarily what you want. Docs are a critical component of how your users perceive your product - you want to have checks that it meets certain quality and accuracy standards. Just like your code.

And if you're an engineering lead company, you probably want your docs updates to be coordinated with your product releases. Git is just the logical place to put your docs in that case.

I've even created a company specifically to help with this workflow: https://www.doctave.com

Also, lots of comments here seem to be thinking of docstrings and other in-code documentation. I think that's really a different category that has a different set of goals and issues. This post is specifically about customer-facing documentation.

xorcist 2 days ago

> you probably want your docs updates to be coordinated with your product releases

People keep saying that but I can't help to wonder if they're every on the receiving end of documentation.

Documentation isn't code. It may all be text, and share other similarities, but it's something fundamentally different. You can't substitute code for docs, or docs for code. The above reasoning is what ends up publishing /docs/5.3/chapter1/installing.html. Reading documentation for a specific version of the product is not desirable.

To understand the product, it's very relevant what happens in version 5.4, and I should not have to diff different releases of the docs to find out. The documentation should say clearly that this function will be deprecated, or look different in the next version. In short, documentation should neither be branched with code, nor released with it. It should live in parallel and describe not only how the product works, but more importantly why it works like it does.

robertlagrant 3 days ago

> And if you're an engineering lead company,

Nit: engineering-led

zelphirkalt 2 days ago

A small change in writing, a big change in meaning.

NiklasBegley 2 days ago

Oops. Good catch.

tikkabhuna 2 days ago

Your product looks really interesting. I'm a big advocate for docs-as-code at my company. We use Confluence generally, but our team uses GitLab and Gatsby for our documentation/blogs as we really value the Merge Request workflow.

Our biggest challenge is local development. A WYSIWYG is just so useful in that regard. Is that what Doctave Studio is trying to solve?

NiklasBegley 2 days ago

You're correct - Doctave Studio is for making local development easier. It packages the whole "authoring environment", so it's all you need to start writing.

It's technically not WYSIWYG, but you do get a side-by-side real-time preview of your rendered Markdown content and OpenAPI specs that update as you type.

You get autocomplete, broken links checking, etc. Everything you'd expect from an editor.

euroderf 3 days ago

Having worked both as a developer and as a technical communicator (for software), I'm thinking that low friction for developers is paramount, and that therefore the way to get developers to put some effort into it is to have documents both (a) written in Markdown (or adoc or rST or typst) and (b) co-located with code under version control. Change the code, change the docs, no screwing around, BUT a quick & simple brain dump can suffice because of [see next paragraph].

To whit: I have yet to hear of a documentation system that provides fully bidirectional updates between such documents-as-code and edits made further downstream along the documentation production pipeline. That is to say, when a TC person or a reviewer makes edits to content, these changes should propagate back to the docs-as-code material.

Then everyone benefits, including senior devs whose scarce time is optimised by having TC people expand and polish their hasty scribblings, and junior devs who have well-maintained documentation at-hand in-place.

My 0.02€, YMMV. Maybe too niche.

smokel 3 days ago

Documentation near code is a good idea, but unfortunately it covers only part of the problem.

There is a big portion of documentation that should be available to "other persons", such as architects or project managers, who may not want to visit the codebase.

Another challenge is that for these people, diagrams are typically more useful than text. This still requires some manual effort which is difficult to achieve with Markdown.

ElevenLathe 3 days ago

I recently started keeping docs in Markdown but with a CD job to render them and publish to Confluence. We only have internal users but many of them are non-technical. This seems to be a sweet spot -- easy for us to update, but also easy for users to find.

It also opens up the possibility of generating the docs themselves from any data that are available at build time. For example, we have a page with a pretty complex Graphviz visualization that gets built from some of the data files we ship with the product. When the data changes, so do these diagrams. They literally can't get out of sync without us noticing (the build breaks). I see more opportunities for this kind of thing all the time now that I'm looking.

hinkley 3 days ago

I don’t know if it’s built in or a plugin but there is a way to embed a markdown document in version control into a confluence page. I don’t recall if it was any markdown page or had to be in bitbucket.

I used a simple intro and then embedded the docs from version control for a couple chunks of our architecture. Helped a lot.

consteval 2 days ago

> who may not want to visit the codebase

Personally, I think they should get over it. Git is not a "software dev" program. Version control is crucial to pretty much everyone who touches the product. I think therefore everyone should know how to navigate their codebase and use Git, at least a little.

Also, you can use git submodules for your documentation so it's kind of separate from code. The only problem is submodules kind of suck ass, so I don't know if devs would be keen for that.

mfuzzey 3 days ago

Agreed with your point of accessibility to people who don't live in the code.

But that doesn't preculude documentation near code nor Markdown. It just means that you need a CI job to publish the doc stored in the git repo as (for example) HTML or PDF.

For diagrams stuff like PlantUML are great, edit as text, publish as images.

jeffreygoesto 2 days ago

Can confirm. We are using Sphinx(-Needs actually) and I can send deeplinks to develop, release or feature branch rendered docs to everyone, including non technical staff. You just have to know the "latest of develop" or release links always work, the branch ones are for quick and ephemeral communication only. We include PlantUML and drawio as source along with the code and PR reviews check that code and doc update in sync.

spockz 3 days ago

We now use MermaidJS to render diagrams from text source in our documentation and that works pretty well!

Nathanba 3 days ago

the second you put docs into version control next to code it's no longer low friction enough. Suddenly you have peer review for docs change is far too much work.

misja111 2 days ago

In all my 26 years of working as a software dev, in the ~20 companies that I've worked or consulted for in various countries, never once did I see code documentation work out well.

It wasn't that the will was not there: in almost every single of the companies the devs and management agreed that good documentation was important. And every now and then some heroic effort would be made to finally clean up Confluence or whatever system was used at the time. And for a little while that would work, then slowly documentation would become neglected here and there, and in the end it would become so bad that nobody would use it anymore. Except perhaps to showcase your commitment to best dev practices to your manager when it was time for your performance review.

It doesn't matter if documentation has to be added in the code, or to some external system or both. Sooner or later it will be neglected, become out of sync and eventually become worse than no documentation at all.

With the exception of external libraries or API's, software simply changes too fast. You'd need an army of technical writers to keep all documentation in sync. And unlike what the author writes, I have actually been working for a couple of companies that gave up and simply used the code as documentation, and surprisingly this worked out pretty well.

remoquete 2 days ago

Sad to read your n=20 was like that. There are also cases where documentation led companies to growth—one example is Stripe.

Poking the finger at documentation is easy because it's visible and readily available. Would you say the bit rot phenomenon you described never happened to code, or processes, or UIs? Docs reflect organizations.

apwell23 2 days ago

> There are also cases where documentation led companies to growth—one example is Stripe.

how do you know this ?

remoquete 2 days ago

misja111 1 day ago

I wasn't talking about external api's or libraries, I actually mentioned that

>> With the exception of external libraries or API's, ..

Those I agree are different, the documentation is part of the product that you offer or sell to external customers.

apwell23 2 days ago

> developer tool documentation

i dont think thats what is being talked about here. Why would they write shitty tool documentation if practically their product.

OP is talking about this

> never once did I see code documentation work out well.

They are not synonymous.

My company's external api has amazing documentation but we have shitty internal code documentation.

remoquete 1 day ago

My post wasn't concerned with internal code documentation. Seems like we're having parallel conversations.

apwell23 1 day ago

gotcha.

> There are also cases where documentation led companies to growth—one example is Stripe.

when you said 'there are also' i thought you were talking about the same thing as the comment you were responding to. Not sure how existence of something totally unrelated to original comment is relevant.

sshine 3 days ago

The problem with "documentation" in commercial code is that nobody reads it.

Any "documentation" that isn't embedded in code will never be opened again.

Any "documentation" in the form of doc-strings and comments will, over time, lie.

This is because competent programmers cannot agree on whether to even comment.

When any large percentage of competent programmers do not comment, it is better to not rely on comments.

Here's another pitch:

  Code-as-Docs

simonw 3 days ago

If people aren't reading your documentation it means they don't trust your documentation.

The solution is to build that trust, by building a culture of active documentation maintenance.

My favorite trick for that is to keep the docs in the same repo as the code and actively enforce relevant documentation updates as part of the code review process.

Once developers learn that new code cannot land on main without accompany documentation updates they learn to trust that documentation pretty fast.

sshine 3 days ago

> My favorite trick is to [...] actively enforce [...]

If active enforcement were an option, and it led to success, I don't imagine there would be a problem.

My favorite trick is to tell people really nicely they should write comments (preferrably doc comments on internally exported interfaces).

Yet, they don't. And so we're back to the dilemma:

If a significant percentage of competent programmers choose to not comment their code, or update the comments that are in the code, the comments will lie over time. And so it is probably better to not include them.

We haven't even reached the point in the conversation where we ask "But why is it you, dear competent programmers with decades of experience, think we should continue to minimize the amount of comments with good conscience?" or ask "Why is it, dear project managers, that we tolerate a total lack of communication through any other means than executable code?" And the answer is probably: Because a lot of autists produce a lot of valuable code, and they don't like to talk if they can avoid it, and we value their work and relay what they made to the wordy-word people.

> If people aren't reading your documentation it means they don't trust your documentation.

I don't trust your documentation unless there's alignment among developers. Alignment is a luxury you don't get in legacy shops.

jampekka 2 days ago

Many of us "autists" may be of the opinion that the code IS the documentation and describing that in ambiguous natural language for some unspecified audience is just not very useful (and can be actively harmful). Use the source luke.

The documentation discussion tends to take for granted that documentation is automatically valuable, and more documentation there is, the better. I find well named and structured code and actually executable standalone examples are far more valuable for understanding a codebase than some by-rote restating of what the code already says.

simonw 2 days ago

If people don't add documentation to their PR, I add that documentation to the PR for them (under my own name as a separate commit), then land the code.

Do that often enough and people get the idea that documentation isn't optional.

j-krieger 3 days ago

This is pretty much why Rust has doctests. You include a small test in your docstring.

sshine 3 days ago

Executable tests in Rustdoc are amazing. For those not involved, they are run when you write `cargo test` and they are included as markdown code blocks in your crate’s documentation.

They’re not an excellent place for extensive testing. But they are super useful for making sure your documentation examples are updated and functional.

#![deny(missing_docs)] is also a great way to ensure you don’t forget to document things.

jampekka 2 days ago

Doctests are indeed a great format for documentation. They are automatically checked for currentness/correctness, aren't ambiguous like natural language and are close to the implementation.

But I have the feeling that doctests aren't seen as documentation the way that is often desired in the documentation discussions.

enraged_camel 3 days ago

Elixir as well.

btbuildem 3 days ago

I read the article as referring to documentation for end users -- not internal documentation / comments written by developers who thought they knew what the code they wrote was doing.

YawningAngel 3 days ago

Lots of people, myself included, read documentation.

ks2048 3 days ago

Ditto. The problem is self-reinforcing: people don’t read docs because the docs are bad… we don’t spend time on docs because no one reads them…

sshine 3 days ago

Not only is it self-reinforcing:

It is inevitable because some competent programmers deliberately don’t comment their code, read comments, or delete other people’s comments when they are stale.

sshine 3 days ago

I personally read and write a lot. I track things in git messages by cross-referencing issues, and I comment my code.

But my point is: when you have a cultural divide among competent programmers on whether to comment, not commenting game-theoretically wins, because the outcome where you have comments that get updated some percent of the time is worse than not having those comments.

Instead, embed what you want to say in a comment in the code itself, or in a test.

Documents your libraries and APIs if they are used by people outside your team.