this post was submitted on 24 Jun 2024
60 points (94.1% liked)

Programming

17655 readers
258 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 2 years ago
MODERATORS
 

I've encountered this many times where I simply don't understand the context and use of an API based of the API documentation unless I can find an example that already utilizes it in a working project. The first thing that comes to mind is Py Torch. I've tried to figure out how some API features work, or what they are doing in model loader code related to checkpoint caching but failed to contextualize. What harebrain details are obviously missing from someone who asks such a silly question?

all 26 comments
sorted by: hot top controversial new old
[–] [email protected] 72 points 5 months ago (1 children)

Why is the documentation incomplete?

Asks every programmer since the dawn of time.

[–] [email protected] 25 points 5 months ago

Pretty busy at the moment, I'll get back to this later when I have sone free time.

[–] [email protected] 55 points 5 months ago (1 children)

API documentation isn't a tutorial, it's there to tell you what the arguments are, what it does and what to expect as the output and just generally, what's available.

I actually have the opposite problem as you: it infuriates me when a project's documentation is purely a bunch of examples and then you have to guess if you want to do anything out of the simple tutorial's paved path. Tell me everything that's available so I can piece together something for what I need, I don't want that info on chapter 12 of the example of building a web store. I've been coding for nearly two decades now, I'm not going to follow a shopping cart tutorial just in the off chance that's how you tell how the framework defines many to many relationships.

I believe an ideal world has both covered: you need full API documentation that's straight to the point, so experienced people know about all the options and functions available, but also a bunch of examples and a tutorial for those that are new and need to get started and generally learning how to use the library.

Your case is probably a bit atypical as PyTorch and AI stuff in general is inherently pretty complex. It likely assumes you know your calculus and linear algebra and stuff like that so that'd make the API docs extra dense.

[–] [email protected] 7 points 5 months ago

Agree. I find “get started” usually is the best way to give an example of “entry point” to API. After that API documentation should get anyone covered for most of the cases. If API is big then it probably has primary and secondary set of features. Secondary then can be covered as tutorials.

[–] hperrin 29 points 5 months ago (2 children)

It’s because the same people who wrote the code usually write the docs, and people who are really good at writing code usually aren’t good at writing docs. It’s two different skill sets that usually don’t coincide.

Case in point: my own documentation for https://nymph.io

I know it’s bad, but I don’t know how to make it good. The code, however, is pretty good. It runs my email service.

Open source projects also aren’t very good at attracting people who both want to volunteer their time writing technical documentation and can.

[–] Carighan 7 points 5 months ago

It’s because the same people who wrote the code usually write the docs, and people who are really good at writing code usually aren’t good at writing docs. It’s two different skill sets that usually don’t coincide.

This is why companies ought to employ technical writers if they have enough documentation. Of course, few ever do, but it'd by the Right Thing™️ to do.

[–] abhibeckert 2 points 5 months ago* (last edited 5 months ago) (1 children)

Here's a tip on good documentation: try to write the documentation first. Use it as your planning process, to spec out exactly what you're going to build. Show the code to people (on GitHub or on a mailing list or on lemmy or whatever), get feedback, change the documentation to clarify any misunderstandings and/or add any good ideas people suggest.

Only after the docs are in a good state, then start writing the code.

And any time you (or someone else) finds the documentation doesn't match the code you wrote... that should usually be treated as a bug in the code. Don't change the documentation, change the code to make them line up.

[–] [email protected] 3 points 5 months ago (2 children)

Don’t change the documentation, change the code to make them line up.

Unless the documentation is wrong

[–] [email protected] 2 points 5 months ago* (last edited 5 months ago)
[–] abhibeckert 1 points 5 months ago

Sure - but in the real world that mostly only happens when the documentation is an afterthought.

[–] [email protected] 20 points 5 months ago (2 children)

I do find that everything related to Python is especially badly documented and/or maintained. Maybe I'm just not looking the in right place though? I don't generally use Python as my primary language.

[–] calcopiritus 6 points 5 months ago* (last edited 5 months ago)

Untyped function definitions + *args + *kwargs + args that can be of many types + strings used as enums don't help. The language that imo needs the most documentation is at the same time the one that lacks it the most.

[–] [email protected] 2 points 5 months ago

I also don't generally use Python as my primary language, but NumPy has pretty good docs in my opinion!

[–] [email protected] 13 points 5 months ago (3 children)

When someone writes API docs, should they assume the reader knows nothing or can they assume the is already experienced?

It takes a lot of effort to write documentation towards newbies, at the cost of making it more difficult for already experienced to find the answer they need.

[–] calcopiritus 6 points 5 months ago

Docs should be written for someone experienced in programming but inexperienced with the API. If it is about a niche subject (for example VR).

Whenever an explanation contains something about that niche subject, you don't need to explain everything, but maybe provide a link towards another place (for example wikipedia) that explains it.

[–] [email protected] 5 points 5 months ago* (last edited 5 months ago)

Usually API docs are tucked away inside a "developer dashboard" or whatever they decided to call it. So I think you can assume at least moderate API and web development knowlege and programming skills.

[–] [email protected] 2 points 5 months ago (2 children)

Write multiple versions of docs for different audiences

[–] [email protected] 6 points 5 months ago

No way they will ever be in sync.

[–] [email protected] 2 points 5 months ago

Which doubles the maintenance work to keep docs in sync

[–] [email protected] 8 points 5 months ago* (last edited 5 months ago)

It's really hard writing software and knowing every bit of it then seeing it as a new user to write docs.

[–] [email protected] 7 points 5 months ago (1 children)

How do I get better at understanding API docs without a tutorial to walk me through the basics of how the library works in the first place? Once I have an idea of some of what the library does and how a few commonly-used functions work I can somewhat handle the rest, but getting to that point in the first place is pretty hard for me if no getting started or tutorial section exists. And so I'm very intimidated by a lot of libraries…

[–] [email protected] 4 points 5 months ago

If there's no getting started section I usually go on GitHub to see how other projects use the library or API.

Reading the API docs with no prior knowledge or context is hard unless they're very well written.

[–] Feathercrown 6 points 5 months ago* (last edited 5 months ago)

I find that this is best explained by the four types of documentation theory. Often when you're starting out, you need a tutorial or how-to guide (or even just an overview of what the purpose and design language of the API is), rather than a reference, which is what nearly all API documentation is.

[–] [email protected] 5 points 5 months ago

Because usually if you end up at the API reference in that situation it's a code / project smell that other stuff is going wrong.

If I want to use a library to do something, you should be able to search for what you want to do + language / framework, find the library's docs, follow the install instructions and then look through the highest level API / instructions and then just go from there.

If you find yourself confused at unhelpful API references that just means that they have badly written top level API docs, badly written intros, or quite probably just badly written APIs.

[–] qaz 4 points 5 months ago* (last edited 5 months ago)

I often use grep.app to look for example. It's fulltext search for code on GitHub, and just get information about the parameters and output by looking at the library's code.