Live data from Hacker News

Ask HN: How do you learn new libraries without much documentation?

news.ycombinator.com

11–20 of 56 posts

Re: Ask HN: How do you learn new libraries without much documentation?

#11
1. learn a good editor.

2. write a script to concatenate all the code files in a folder, separated by filenames.

3. pipe that result to your editor.

4. use your editor's "find" functionality.

By reading the entire source code in a single file, you have global knowledge of the entire codebase. All the information is available to you. I suggest you try it before dismissing the idea, as I once did.

https://github.com/shawwn/scrap is what I use. `codefiles | grep js$ | xargs merge | ft js` will open all javascript codefiles in vim, in JS mode. `cppfiles | xargs merge | ft cpp` will open all C++ files in vim, in C++ mode.

Free yourself from the loop of asking other people for answers. Stop that. Read code.

If you limit yourself to "projects that have good documentation," you'll miss out on 90% of the interesting code in the world.

Re: Ask HN: How do you learn new libraries without much documentation?

#12

Look at the library's tests. It's quicker and better for learning functionality than "just read the source code". If it's proprietary and closed and obfuscated then you need to familiarise yourself with reverse engineering toolsets.

Seconding this! Tests are a wonderful way to quickly discovering the properties of the codebase that the authors considered important.

Re: Ask HN: How do you learn new libraries without much documentation?

#14

1. learn a good editor. 2. write a script to concatenate all the code files in a folder, separated by filenames. 3. pipe that result to your editor. 4. use your editor's "find" functionality. By reading the entire source code in a single file, you have global knowledge of the entire codebase. All the information is available to you. I suggest you try it before dismissing the idea, as I once did. https://github.com/sh…

This sounds like trying to create a poor man's IDE with go to definition / find usages functionality.

Is there an IntelliJ product for JS yet?

Re: Ask HN: How do you learn new libraries without much documentation?

#15
If you have the source code to this library, `find` and `grep` are your best friends. If nothing else, you should be able to find other usages of the code you're looking to use (or maybe even tests), which will let you know how that code is supposed to be used. The other things to look for are classes, functions, or modules that aren't used by other code in the library. Those tend to be the "top-level" code intended to be called by application code. Seeing how those are structured and what functionality they expose can be a great way to discover functionality that documentation leaves out.

Re: Ask HN: How do you learn new libraries without much documentation?

#16
post #14

1. learn a good editor. 2. write a script to concatenate all the code files in a folder, separated by filenames. 3. pipe that result to your editor. 4. use your editor's "find" functionality. By reading the entire source code in a single file, you have global knowledge of the entire codebase. All the information is available to you. I suggest you try it before dismissing the idea, as I once did. https://github.com/sh…

This sounds like trying to create a poor man's IDE with go to definition / find usages functionality. Is there an IntelliJ product for JS yet?

I haven't used it, but there is WebStorm [1]. Visual Studio Code also also has fairly good jump to definition/find usages, thanks to the fact that it has a typescript compiler built in, which allows it to perform analysis of JavaScript projects as well.

[1]: https://www.jetbrains.com/webstorm/

Re: Ask HN: How do you learn new libraries without much documentation?

#17
post #14

1. learn a good editor. 2. write a script to concatenate all the code files in a folder, separated by filenames. 3. pipe that result to your editor. 4. use your editor's "find" functionality. By reading the entire source code in a single file, you have global knowledge of the entire codebase. All the information is available to you. I suggest you try it before dismissing the idea, as I once did. https://github.com/sh…

This sounds like trying to create a poor man's IDE with go to definition / find usages functionality. Is there an IntelliJ product for JS yet?

I regularly read and understand 50,000+ line codebases with this technique. Again, I suggest trying it before dismissing the idea. A good IDE is nice, when they work, but this fallback has worked 100% of the time.

CLion is for C++. PyCharm is for Python. Webstorm is for JS. But Vim is for everything.

To put it differently: how often do you use ripgrep on a large codebase? If the answer is "often," then every time you switch to your terminal, you're losing context about the code. No wonder it's impossible to understand when you're having to read code fragments every few minutes. Read the whole code.

Re: Ask HN: How do you learn new libraries without much documentation?

#18
There is lots of good advice about how to figure out how it works in this thread.

One piece of advice I have is write formal documentation of some form as you figure it out. Share it as widely as possible. If nothing else, it will be very useful for you and your co-workers in the future. It sounds like there is some sort of community you can share it with. Ideally there would be some way to contribute it back the to source of the software for distribution with it, but that often isn't possible with proprietary software.

Regardless of who you share it with, it will help establish you as an expert within that group. In addition to helping people, it will likely be good for your career.

Re: Ask HN: How do you learn new libraries without much documentation?

#19
A good navigation tool can really help sort out a foreign code base. I suspect it could take you a few hours (with luck...) to install Sourcegraph but when you succeed it will be worth your time! (and the data should be local to the host where you install it).

Found a random article online that shows step by step with pictures [1] (I think is a bit more visual than the canonical docs).

Good luck!

1: https://www.techrepublic.com/article/how-to-install-sourcegr...

Re: Ask HN: How do you learn new libraries without much documentation?

#20

1. learn a good editor. 2. write a script to concatenate all the code files in a folder, separated by filenames. 3. pipe that result to your editor. 4. use your editor's "find" functionality. By reading the entire source code in a single file, you have global knowledge of the entire codebase. All the information is available to you. I suggest you try it before dismissing the idea, as I once did. https://github.com/sh…

I'd recommend just learning ag (or ripgrep), they make searching across projects dead easy and support limiting to specific filetypes.

Reading all the code might be a decent approach for small libraries but sometimes it's excessive.

Post reply on HN