Hacker News new | ask | show | jobs
by moe 4860 days ago
Yes, it's arbitrary and there are of course exceptions and perhaps domains where it may not apply at all. It's just a recurring observation that I've made (mostly but not only) in dynamic languages.

Pretty much all good code that I've read or written was compartmentalized into units of roughly 500 LOC. A big program may be composed of many such units, but it was almost always a bad sign when a divisible part would exceed the "magic" number.

What comprises a divisible part of course also varies by language; at the least it'd be the LOC-per-file, but usually it'd be a self-contained and separately tested module.

In a moment someone will probably come up with a great piece of software where this doesn't hold true, I'd actually be curious to see it.

2 comments

And a program is usually made of many units so is much larger then 500 LOC
So, you actually mean functions instead of programs?
No.

I mean an isolated unit that could be ripped out at any time and would be immediately useful on its own.

Anyway, abecedarius (below) has phrased it better than I could.

Those 'isolated units' are commonly called libraries then.
No. They are called "module".
Yes, I agree with that name, libraries usually start as modules and some extra work is required to convert a module to a library.

Also, a library can be thought of as a collection of modules.