Live data from Hacker News

Ask HN: What are the “best” codebases that you've encountered?

news.ycombinator.com

251–260 of 278 posts

Re: Ask HN: What are the “best” codebases that you've encountered?

#251
post #240

Earlier quoted context omitted.

> If it was named TIMESTAMP_ROUND, I wouldn't need to know "Round off to MAX_TIMESTAMP_PRECISION decimal places." TSROUND is already as obvious as TIMESTAMP_ROUND. TS is a very common abbreviation of timestamp. And you would still need to know the decimal places. The real issue is that it's based on TS_PREC_INV and not MAX_TIMESTAMP_PRECISION as per the comment (though MAX_TIMESTAMP_PRECISION might still agree with t…

> TS is a very common abbreviation of timestamp. Common != universal. It's known up until someone doesn't know it. We have pretty powerful autocompletes, let use them instead, or just lose 3 seconds writing the 10 letters, it won't be so bad. > And you would still need to know the decimal places. Sure, by reading the code and understanding what it does and how it does it. You change a constant that will affect that c…

>Common != universal. It's known up until someone doesn't know it.

Someone might also not know what a timestamp is, or a UNIX timestamp at least, so there's that.

>We have pretty powerful autocompletes, let use them instead, or just lose 3 seconds writing the 10 letters, it won't be so bad.

The problem with the above idea is that it implies "spelling it out fully == better". Which is not necessarily the case, long variable names can make code hard to follow and verbose. Ask the Java community...

Re: Ask HN: What are the “best” codebases that you've encountered?

#252

Earlier quoted context omitted.

Running non-trivial code in your head is far too tedious for daily use. I'd much rather add debug checks for invariants when I want to confirm that the code works the way I expect it to.

The human brain has, what, about 7 registers in medium term memory?

5±3, if I remember right, but of indeterminate size. You can expand it to a couple dozen by moving up and down abstraction levels.

An exercise: I have 36 letters for you to memorize, in order and without mistakes: "The quick brown fox jumped over the lazy dog"

The sentence as a whole only uses 1 of those memory slots. As necessary, you can jump down one abstraction level to get 9 words, or again on a word-by-word basis to get the full 36 letters.

Code is the same. For example, use multiple slots to understand loop conditions, then file it away in a single slot as the whole conceptual loop. Use multiple slots to understand the loop body, in the context of one element; file it away as well. Combine them into a one-slot conceptual understanding of the whole loop. So on and so forth.

As you work with the conceptual models, you'll also end up with them in long-term memory and not have to do this reconstruction each time.

This pattern can continue indefinitely, with conceptual models of whole packages and systems. Most will do it unconsciously at that level as they become familiar with a codebase, but it works at every level, and is the basis of "running code in your head".

Re: Ask HN: What are the “best” codebases that you've encountered?

#254
post #241
post #108

Earlier quoted context omitted.

> If it was named TIMESTAMP_ROUND, I wouldn't need to know "Round off to MAX_TIMESTAMP_PRECISION decimal places." With only the name, how would you know how many decimal places? The comment isn't wrong/out of date here btw.

> With only the name, how would you know how many decimal places I'm not saying the name is wrong because of the comment, I'm saying it's wrong because of the usage of the acronym. > The comment isn't wrong/out of date here btw. Isn't wrong? How? It's true in the sense that they expect TS_PREC_INV to be related to MAX_TIMESTAMP_PRECISION (which would be a perfect example to my mind of a needed comment, if actually it…

> I'm not saying the name is wrong because of the comment, I'm saying it's wrong because of the usage of the acronym.

I get that. But you also said the comment would be unnecessary with a name change. The comment does communicate more information than your proposed name, IMO, hence is not replaceable by the name. (IMO).

> You wouldn't get a different rounding if you were to modify MAX_TIMESTAMP_PRECISION, which is what you would expect based on that comment.

Good point. The comment isn't wrong with the definition of MAX_TIMESTAMP_PRECISION as it is in the code. If you override it though, the code doesn't do what the comment says.

It's an interesting case: if you trust the comment indicates the desired behavior, then you can see the code may have room to be improved. If you distrust that the comment is correct or has value, then you might just remove the comment, and the code doesn't get better.

Re: Ask HN: What are the “best” codebases that you've encountered?

#255
post #25

The compiler for the B language, by Arthur Withney http://kparc.com/b/

I'd add to this family the J system, ver. 7 - https://github.com/jsoftware/jsource .

A good example of creating a DSL and then efficiently using that. "Never had a memory leak from day 1 (Roger Hui)" (written in C).

Re: Ask HN: What are the “best” codebases that you've encountered?

#256

Earlier quoted context omitted.

macOS has had automatic retain counting for the last decade. You have to remember your weak/strong for cycles but that's all. It's preferable over garbage collection because there are no unexpected pauses/memory scans and it's deterministic.

RE pauses, that’s only due to the system-injected calls to autoReleaseReturnValue and retainReturnValue which work in tandem to do assembly call stack analysis and set an extra register to keep return values out of the release pool. This allows pool runs to happen frequently enough with few objects in them and have smooth latency.

The autorelease optimization actually regularly breaks, because not even the compiler engineers remember it exists, and it relies on libraries tall-calling -autorelease which they also forget to do.

Even without it, there isn't a pausing problem because you can clear the pool at the end of the runloop tick, when the app is idle anyway.

Re: Ask HN: What are the “best” codebases that you've encountered?

#257
post #197

Earlier quoted context omitted.

The build system and assembly system (x86asm) are very underrated. Open source went from autotools, which are awful, to cmake, which also seems to be awful. ffmpeg's configure/make system has the same interface as autotools but is actually good. libavformat is rather difficult to use and difficult to fix bugs in - you'll never find the bugs. Same with the ffmpeg frontend, which makes it easy to ask for something it's…

libavformat is rather difficult to use and difficult to fix bugs in - you'll never find the bugs. Some examples? encoding never worked as well, which is why nobody uses ffmpeg2/4/etc and x264 is a separate project. Most users use x264 _via_ ffmpeg since they may need to filter the video and/or filter/process/mux audio and other streams.

> Some examples?

Just try copying video between different containers (mkv, ts, avi for one) without reencoding.

> Most users use x264 _via_ ffmpeg since they may need to filter the video and/or filter/process/mux audio and other streams.

They don't have to do that; you can handle each track separately and mux them back afterward.

I'm talking about ffmpeg's builtin MPEG2/4/MP3 encoders, which nobody used when they were competitive because it leaves all the options at "go fast" instead of providing tunings.

They're also unmaintained and the code is hard to figure out - that's why x264 was a separate project instead of just another part of libavcodec.

Re: Ask HN: What are the “best” codebases that you've encountered?

#258
post #28

I really liked the Go standard library (or at least from around 1.4-ish, it might have gotten more complicated now). I liked that it was actually possible to read it and understand what was going on. In a similar vein, P. J. Plauger's version of the The Standard C Library is nice because even if it might not be especially optimized(?), you can actually read the code and understand the concepts that the standard libra…

I supposed it's this one, but it's public domain and over the years has been forked many many times (far more than I ever expected).

http://git.annexia.org/?p=jonesforth.git;a=summary

Re: Ask HN: What are the “best” codebases that you've encountered?

#260

Earlier quoted context omitted.

RE pauses, that’s only due to the system-injected calls to autoReleaseReturnValue and retainReturnValue which work in tandem to do assembly call stack analysis and set an extra register to keep return values out of the release pool. This allows pool runs to happen frequently enough with few objects in them and have smooth latency.

The autorelease optimization actually regularly breaks, because not even the compiler engineers remember it exists, and it relies on libraries tall-calling -autorelease which they also forget to do. Even without it, there isn't a pausing problem because you can clear the pool at the end of the runloop tick, when the app is idle anyway.

But if you didn’t had the trick, CPU intensive runloop ticks could create lots of small objects that were put in the pool because they had a 0 refcount as a function returned the value. That’s why we had the ability to write our own pools.
Post reply on HN