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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

A word for “the number of things you need to know to understand the code”?

4 点作者 unknownsky将近 3 年前
For example, to understand<p>if (obj.index == 0 &amp;&amp; (f_mode &gt; 3 || state[1] != null))<p>you need to know * What does obj represent * Under what circumstance does obj have an index of 0 * Why we are interested in that circumstance for what we are trying to achieve * What does f_mode represent * Under what circumstances is f_mode greater than 3 * etc etc etc<p>You need to know at least 10 things to understand it. However, if we break it up and replace it with<p>if (Membership.IsExpired)<p>then we need to know 0 things to understand it.<p>Is there some sort of principle that represents the number of things you need to know? A sort of Things You Need To Know To Understand This Index? Something that is a countable unit, so that you could say that one block of code has an index of 17 (i.e. you need to know 17 things to understand it) while another block of code has an index of 2?<p>We could start from a baseline assumption that the reader knows the coding principles themselves. The reader needs to know how an if-statement works, for example, but that would not be included in the index. One might argue about whether more obscure coding tricks should be included in the index or not.

5 条评论

Someone将近 3 年前
In<p><pre><code> if (Membership.IsExpired) </code></pre> You still need to know what <i>Membership</i> represents, that it has a <i>IsExpired</i> field, that that is a Boolean, and what it means.<p>Most of it is in the business domain, though.<p>You may want to start at <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Software_metric" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Software_metric</a>, which has links to methods both for estimating complexity before a line of code is written and for estimating complexity of existing code. For the latter, examples are:<p><pre><code> https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Halstead_complexity_measures https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Cyclomatic_complexity </code></pre> AFAIK most of them estimate the complexity of multiple lines of code&#x2F;functions&#x2F;entire programs.<p>I don’t think there is agreement as to the usefulness of this, and if so, which method is the best, or whether it’s possible to measure software complexity at all (for the latter, I think everybody’s gut feeling says “yes”, but I don’t think every person would even place different program fragments in the same order of complexity (example: <i>foo.map.filter(…)</i> versus a <i>for</i> loop with a nested <i>if</i>. Which one is deemed simpler depends on one’s pre-existing knowledge)<p>I also think we can only estimate program complexity roughly, and wouldn’t go as far as calling anything a metric.
评论 #31481734 未加载
0x38B将近 3 年前
What about depth? What if we said your first sentence was 8 deep. One layer for each reference (obj.index, f_mode, state[1]), +1 layer for each statement: == 0, &gt; 3, != null, &amp;&amp;, and (…).<p>Giving literature and specific sentences reading levels is similar to what you’re asking.<p>One expression, such as ‘obj.index’, might itself be very deep: obj.index, object and its properties, function, perhaps what created it, and so on.<p>I don’t know that ‘depth’ is the word you were looking for, perhaps there’s a fancy scientific word to be found. If I wanted to get into it, I’d look into linguistics research on quantifying comprehension and related topics.
jka将近 3 年前
GNU&#x27;s complexity[1] tool calculates something like what you&#x27;re talking about for procedures in C programs, and calls the result a &quot;complexity score&quot;, although I don&#x27;t think it accounts for variable names, nor magic integers.<p>[1] - <a href="https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;complexity&#x2F;manual&#x2F;complexity.html#Example-Output" rel="nofollow">https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;complexity&#x2F;manual&#x2F;complexity.ht...</a>
marshmellman将近 3 年前
You might look to psychology’s concepts of “cognitive load” and “working memory”.
joezydeco将近 3 年前
I&#x27;ve always called this &quot;self-commenting code&quot;. No need to overthink it.