Learning from Giants #34
NASA's ten rules for developing safety critical code, The invaluable role of copying in design, and the popular React Query's underlying architecture.
👋 Hi, this is Mathias with your weekly drop of the 1% best, most actionable, and timeless resources to grow as an engineering or product leader. Handpicked from the best authors and companies.
Did a friend send this to you? Subscribe to get these weekly drops directly in your inbox. Read the archive for even more great content. Also: I share these articles daily on LinkedIn.
NASA's ten rules for developing safety critical code
"Among the many coding guidelines that have been written, there are remarkably few patterns to discern, except that each new document tends to be longer than the one before it."
When it comes to writing mission-critical software, NASA immediately comes to mind. To achieve near-perfect reliability, they have researched and designed a limited set of strict general rules they would always follow.
"The rules I will propose are somewhat strict—some might even say draconian. The tradeoff, though, should be clear. When it really counts, especially in the development of safety-critical code, working within stricter limits can be worth the extra effort."
📗 In the 2006 article The Power of 10: Rules for Developing Safety-Critical Code, Gerard Holzmann describes rules they have set up in JPL software teams to optimize the code reliability and their ability to validate it. Even if you're not writing space-grade software, there is much to learn from the rationale behind each rule.
"Rule 1: Restrict all code to very simple control flow constructs—do not use goto statements, setjmp or longjmp constructs, or direct or indirect recursion." The less magic, the safer.
"Rule 4: No function should be longer than what can be printed on a single sheet of paper." Functions must be understandable as a unit: optimize for code reviews.
"Rule 7: Each calling function must check the return value of nonvoid functions." If there's a return value, especially error types, it must explicitly be handled.
Copying is the way design works
"I've only been able to have a career in design because I copied."
Copying is a catch-all word with a vague, primarily negative meaning. Yet it is a strong driver of progress and innovation.
Take the example of Apple and Microsoft:
"We both had this rich neighbor named Xerox ... I broke into his house to steal the TV set and found out that [Jobs] had already stolen it." Bill Gates, reflecting on their shared inspiration for Xerox Labs inventions.
"Great artists steal." Said Steve Jobs, quoting Pablo Picasso.
An invaluable piece of history now, but also the symptoms of something bigger: software and design are spaces where copying has become unavoidable.
"Richard Stallman went even further — he made copying a right. [...] Stallman wrote a manifesto, defining the idea of free software. The manifesto kicked off the free software movement."
How would you start a new system without UNIX? Without a FOSS programming language? Or the dozens of libraries?
"Permissive licensing and distributed source control form the engine of modern software development."
📗 Matthew Strom's essay Copying is the way design works approaches copying from the author's historical, cultural, and personal angles. It's fascinating how something that institutions and (western) culture label as wrong can be such a driving force of innovation and careers.
"Whether you believe that it's worthwhile or worthless to copy, whether you think that copies are a valuable part of the design community or a scourge, you are using software, hardware, websites and apps that all owe their existence to copying."
Inside React Query
Beauty in software architecture is when it looks evident and simple, almost obvious, and when every abstraction has a purpose.
In that regard, react-query is beautiful. It's de-coupled from the underlying framework and has a simple architecture and encapsulated components.
"I've been asked a lot lately how React Query works internally. How does it know when to re-render? How does it de-duplicate things? How come it's framework-agnostic?"
The answer: a QueryCache that stores queries by key, a central Query object that hides the framework's querying complexity, and QueryObservers that push query data to the UI framework.
"Query is where most of the logic is happening. [...] It has an internal state machine to make sure we don't wind up in impossible states. [...] Most importantly, the query knows who's interested in the query data, and it can inform those Observers about all changes."
The rest is quality-of-life helpers and optional features.
📗 Dominik Dorfmeister's Inside React Query is a short yet fascinating dive into the internals of one of the most popular data-fetching libraries. It's also a good reminder that beautiful architecture can also happen to be in front-end code!