TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Simplicity Before Generality, Use Before Reuse

58 点作者 j4mie超过 7 年前

8 条评论

nnq超过 7 年前
&gt; People do not on the whole pay for — or need — generality: they tend to have a specific situation, and it is a solution to that specific situation that has value<p>Yeah, but otoh, most progress in science and tech has been made by <i>sort-of-tricking</i> people into <i>paying for stuff that solve a slightly more interesting&#x2F;general problem than the original boring problem they wanted solved.</i><p>So at least when it doesn&#x27;t drown everyone in paralyzing complexity, we need to remember to keep that &quot;hacky rascality&quot; alive and <i>slightly</i> &quot;screw&quot; our clients at the expense of developing some general and reusable solutions (hopefully as open-source libraries :P) that will probably matter more than whatever &quot;important&quot; problems they want solving ;)
评论 #15906796 未加载
dgreensp超过 7 年前
This article really hits home in terms of how people sometimes think about React components, and how I’d like them to think about them.<p>I sometimes hear, from other engineers working on a complex React app, that the point of React’s components is that every component is written to be “reusable.” Every component. This is used as a justification for “going general” immediately when writing a component. In reality, there is real work to make a one-off component into a reusable component, and that work can only be done in the context of having (or at least realistically imagining, not dreaming up as an exercise) multiple use sites.<p>What React components actually provide are the same things that modules and functions provide: encapsulation; limited dependencies; a calling convention. When you write a function, you try to keep the arguments to a minimum; you might say it makes the function more “reusable,” but there is still a big difference between a library function that is <i>designed</i> to be used from anywhere, and a private helper function that is not. React components are “reusable” the way functions and modules are reusable. A better word might be “usable.” :) You can reason about the use, even if there is only one use.<p>Making something “reusable” means making it general, and we’ve all had the experience that the article points to of taking some code that was intended to be general, but in fact is used in only one place, and remaking it so that it’s actually possible to use in a second place.<p>That said, I have many times in programming succeeded in boiling something down to its essence in advance, and writing the general thing first, followed by the specific thing. I suspect this is actually more about simplicity than generality, however. I’m thinking of cases of “bottom-up” development where you write the primitives and then the higher-level parts in terms of the primitives. Actually, maybe it is about generality too, and when you are testing out your primitives in different combinations, you are doing the work required for good generality (seeing lots of different cases and basing your decisions on that).
Derbasti超过 7 年前
This is especially true for libraries. A minimal, simple library is much better than a sprawling, &quot;convenient&quot;, but more complex library.
评论 #15909106 未加载
whack超过 7 年前
Sorry for ranting. I&#x27;ve been reading articles like this one for many years now, and I&#x27;ve certainly learnt a lot through them. Lately though, it feels as though we as a profession are just going around in circles, not making any real progress.<p>More and more, these articles remind me of schoolyard wisdom, the kind people love to throw around because they sound wise. <i>&quot;Winners never quit.&quot;</i> &quot;<i>Quitters never win&quot;</i>. &quot;<i>Quit while you&#x27;re ahead&quot;</i>. Taken individually, they all sound perfectly reasonable and wise. Put them together, and clearly there&#x27;s something wrong.<p>This article strikes me in the same vein. &quot;<i>YAGNI. Keep your code as simple as possible. Focus on your code as it is right now, and not what&#x27;s going to happen in the future&quot;</i>. &quot;<i>The only constant is change. Business requirements are always in flux. The mark of good code is the ability to change its behavior without overhauling everything&quot;</i>. Taken individually, they both sound perfectly reasonable, but put them together, and something is clearly wrong.<p>Maybe it&#x27;s time we accepted that there is no one right way. No one all-important metric or rule that trumps everything else. That simplicity is important, that conciseness is important, that DRY is important, that being able to adapt to future changes is important. That good code finds a balance between all of the above, without sacrificing one on the altar of another. That instead of writing articles trying to elevate one over another by attacking strawmen, we should instead present realistic code examples, thorough which we can have a grounded discussion on how best to find the balance between all the different qualities that comprise good code.<p>It&#x27;s not going to be as easy or fun as simply declaring <i>&quot;X considered harmful&quot;</i>, but it&#x27;s going to help elevate the quality of our discussion, and help our profession progress to the next level.
评论 #15909092 未加载
评论 #15908714 未加载
tome超过 7 年前
I&#x27;d like to take this opportunity to flesh out some ideas I&#x27;ve had regarding the difference between the concepts &quot;generic&quot; and &quot;general&quot;. &quot;Oh, I think we need the ability to do this kind of thing someday&quot; falls under &quot;general&quot;, giving more and more functionality to a component. &quot;Oh, there are several things about this piece that we don&#x27;t actually need to know&quot; falls under &quot;generic&quot;, allowing the code to generally be simpler. In Haskell<p><pre><code> traverse :: (Traversable t, Applicative f) =&gt; (a -&gt; f b) -&gt; t a -&gt; f (t b) </code></pre> is more <i>generic</i> than<p><pre><code> traverse :: Int -&gt; IO Float -&gt; [Int] -&gt; IO [Float] </code></pre> and therefore strictly better (unless there are reasons the latter could be optimized but not the former).
评论 #15916442 未加载
bootsz超过 7 年前
This really hits home:<p>&gt; <i>How much of what software engineers now do is still devoted to the accidental, as opposed to the essential?</i><p>Far, far too much
curyous超过 7 年前
So true. Premature generality is a big problem.
评论 #15909456 未加载
bullen超过 7 年前
Great article! We need more &quot;practical rational knowledge&quot; infused arguments in a sea of over-engineered &quot;download and configure&quot; nightmares!