

Write code. Not too much. Mostly functions....
source link: https://www.brandonsmith.ninja/blog/write-code-not-too-much-mostly-functions
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Write code. Not too much. Mostly functions. December 15, 2020
There's a well-known quote by author Michael Pollan: "Eat food. Not too much. Mostly plants." I like it because it doesn't attempt to be dogmatic: it encapsulates some basic guiding principles that get you 90% of the way there 90% of the time. Wikipedia describes the book the quote is from (emphasis mine):
He explains...the notion that nutritionism and, therefore, the whole Western framework through which we intellectualize the value of food is more a religious and faddish devotion to the mythology of simple solutions than a convincing and reliable conclusion of incontrovertible scientific research.
That...sounds familiar.
Write code #
Code, like food, has value. I think those of us who write it can (hopefully) agree on that. Some, though, are so afraid of writing/eating too much that they avoid writing/eating what they should.
In the context of programming, I think this translates to an unhealthy fear (again, for some) of duplication. A little bit of duplication - writing something in a way that doesn't completely maximize conciseness - isn't the end of the world. Sometimes it's the best path forward. Sometimes it's okay to copy-and-modify here and there, especially when you're still figuring out what your application will end up being.
Not too much #
Of course too much code, like too much food, can also be a bad thing. This is a well-trodden topic so I don't feel the need to go too far into it here.
Just be aware of your project's "appetite": write what needs to be written, and then try not to over-indulge.
Mostly functions #
By "functions" here I mean "pure functions". You could make a case that pure functions aren't the "plants" of code, though I feel that they are. In my experience most codebases have a pure functional subset, and I believe writing that subset in a pure-functional style is nearly always a win for the long-term health of the project.
Of course the qualifier is "mostly": this isn't a dogma. Writing a 100% functional system ("going vegan", if you will) often requires you to jump through a bunch of extra hoops to get all the functionality you need. Looking at it solely from the perspective of health, those extra complications may not be worth it.
And then different projects have different needs: just as an athlete may need a larger percentage of protein, or individuals may have certain nutrient deficiencies, a project may only have a very small functional subset, or may not be able to afford to return new values each time due to data size or performance-sensitivity. There's nothing wrong with that.
"Real code" #
Pollan later qualifies his snappy statement a bit further:
He contends that most of what Americans now buy in supermarkets, fast food stores, and restaurants is not in fact food, and that a practical tip is to eat only those things that people of his grandmother's generation would have recognized as food.
At the risk of stretching the analogy, maybe the equivalent is "code only those things that people at a junior level would recognize for what they do". Code in simple, straightforward terms. Don't get too clever, "manufacturing artificial ingredients". Use the primitives that are there, when possible. Write what is simple, and natural, and human.
Recommend
-
121
I've given this blog post as a talk which you can watch here: A while back, Guillermo Rauch (creator of Socket.io and founder of
-
40
I like to blog little veins of thought as I see them. We recentlylinked to an article by Facundo Corradini calling out a tweet of ours where we used an...
-
35
Too much rare! Add to FavoritesShareToo much rare!
-
18
Blazor EditForms, an essential tool or too much magic?July 23, 2020 · 6 minute read · Tags: blazorBlazor ships with something called an EditForm.B...
-
15
Taking too much slack out of the rubber band Of late, I keep hearing more and more about elastic this and elastic that. People use it in order to "right-size" their services, and only run the number of instances, pods, or whateve...
-
16
Too much interference? Get in the car Friday, January 12, 2007 Well, I have been pretty frustrated for the past week or so, as I have realized that there is just too much RF and electrical interference in my house. It is mak...
-
9
The Pmarca Guide to StartupsThe Pmarca Guide to Startups Part 6: How much funding is too little? Too much? Jul 3, 2007 In this post, I answer these questions: How much fun...
-
7
Running (Mostly) Minimal .NET 6 APIs in Azure Functions Posted on September 3, 2021
-
22
Software Will Mostly Write Itself in the FutureOnly about one-half of one percent of the world can code and there is more code to be written than there are developers to do it. Demand is high for tools that take the drudgery out of coding –...
-
3
Those last few steps are the toughest — The pathway to 90% clean electricity is mostly clear. The last 10%, not so much Six different approaches—with pros and cons—for gett...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK