Code Formatters — unminify JavaScript, CSS and HTML
Paste minified code and read it as it was written: indentation, line breaks and structure restored.
Code is instructions written for a machine and read by people. This page is about the second half of that — why code is read far more often than it is written, and what follows from taking that seriously.
Tools in this section
Other sections
How to use Code
Whatever you are doing with code, the same few questions decide how it goes. Answer them before you start typing rather than discovering them afterwards. What should this do — stated precisely enough that you could test it.
How will you know it worked — a check that can fail, not a feeling. What already exists that does this — searching first beats building second. Who reads this next — including you, having forgotten everything.
Written once, read for years
Code is written in a session and read for as long as it exists. Every choice that makes writing slightly faster and reading slightly harder is a bad trade, because the reading happens many more times. Clever compression, unexplained abbreviations and structures that only make sense while holding the whole problem in your head all cost more than they save.
The useful test is to imagine returning to the code in six months with no memory of writing it. Anything that would need reconstruction should have been written down instead. Every line of code is a liability. The asset is what it does — and you can sometimes get the asset with fewer lines.
The part that is not typing
Most of the difficulty in code is not producing it. It is understanding an existing system well enough to change it safely, working out why something behaves differently than expected, and deciding what should happen in the cases nobody specified. Typing is the fast part.
This is why "how long will it take" is hard to answer honestly. The writing is estimable; the understanding is not, because you cannot know how long it takes to understand something until you have understood it.
Debugging as a procedure
Debugging goes badly when it becomes guessing. It goes well when it becomes a procedure that narrows down the possible causes. Reproduce the problem reliably — an intermittent bug you cannot trigger cannot be fixed with confidence.
Reduce it to the smallest case that still fails. State what you believe is happening, then find the observation that would prove you wrong. Check the assumption you are most sure about, because that is where the bug hides.
Fix it, then confirm the original reproduction now passes. The third step is the one people skip. A hypothesis you only try to confirm will feel supported by almost anything. A hypothesis you try to break either survives or dies quickly, and both outcomes are progress.
Deleting more than you add
Codebases grow by default. Things get added and rarely removed, because adding is visibly useful and removing feels like it risks something. Over time this produces systems where a large fraction of the code is not reached, not needed, or duplicated somewhere else with small differences nobody remembers the reason for.
Removing that code is not cleanup for its own sake. Every unused path is something a reader has to understand before deciding it is irrelevant, and something a change has to be checked against. Deleting it makes the remaining code cheaper to work with. The best-reviewed changes are frequently the ones where the total line count goes down.
Questions and answers
- Should code have comments?
- Comments should explain why, not what. What the code does should be visible from reading it; why it does that — the constraint, the decision, the thing that would otherwise look wrong — is not recoverable from the code itself.
- How do I know if code is good?
- Someone unfamiliar with it can read a section and correctly predict what it does. That test catches more real problems than any style rule.
- Is it worth rewriting working code?
- Only when the cost of working with it exceeds the cost of replacing it, and only when you understand what the existing version handles. Working code usually contains fixes for cases the rewrite has not met yet.