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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Loopless Code (2006)

136 点作者 xept超过 3 年前

17 条评论

userbinator超过 3 年前
The loops are still there, they&#x27;re just implicit. That&#x27;s how APL-family languages can be parallelised easily.<p>It&#x27;s notable that the first J interpreter, while written in C, has a similar style --- it defines a macro to run a loop &quot;implicitly&quot;, and then uses that throughout: <a href="https:&#x2F;&#x2F;code.jsoftware.com&#x2F;wiki&#x2F;Essays&#x2F;Incunabulum" rel="nofollow">https:&#x2F;&#x2F;code.jsoftware.com&#x2F;wiki&#x2F;Essays&#x2F;Incunabulum</a>
评论 #29350817 未加载
评论 #29353860 未加载
评论 #29356316 未加载
matthewaveryusa超过 3 年前
Sean Parent has a good talk about no loops in C++. His primary argument is that typically a loop is an algorithm you’re applying (map, filter, reduce…) and the raw loop masks the algorithm.<p><a href="https:&#x2F;&#x2F;m.youtube.com&#x2F;watch?v=qH6sSOr-yk8" rel="nofollow">https:&#x2F;&#x2F;m.youtube.com&#x2F;watch?v=qH6sSOr-yk8</a>
评论 #29351066 未加载
评论 #29352569 未加载
bennybob超过 3 年前
Map reduce and filter often are much more readable, but then sometimes a loop is clearer. I often see this when I use resharper&#x27;s (a c# tool) auto refactor a loop into a linq statement , it can become unreadable.
评论 #29351970 未加载
评论 #29351111 未加载
dahart超过 3 年前
&gt; If the rank of the verb&#x27;s operand is smaller than the rank of the verb, the verb is applied to the entire operand and it is up to the author of the verb to ensure that it produces a meaningful result in that case.<p>This instantly brings back all my frustration with getting broadcasting in numpy to work like I want &#x2F; expect. I love getting the right dot products to work between an array of matrices and an array of vectors, but I don’t do it often enough to remember how, I have to slowly re-derive the incantation every damn time.<p>&gt; J does contain while. and for. constructs, but they carry a performance penalty<p>Question - what is the state of the art of functional programming for performance? My experience in JavaScript, Python, and C++ is that using loop-hiding pure functional constructs is difficult to impossible to optimize, often much slower than explicit loops, and worse that it’s harder to refactor when you realize your nested loops are inside-out from what they need to be. I want to use functional more often, but I feel like I hit roadblocks in practice.
评论 #29352043 未加载
MaxBarraclough超过 3 年前
From the title I was sure this was going to be about the <i>branch forward only</i> pattern used in the Gripen, that John Carmack has briefly written about. In that pattern, there&#x27;s a top-level loop, but other than that, no looping constructs or other backward-branches are permitted anywhere in the codebase.<p>* <a href="http:&#x2F;&#x2F;lambda-the-ultimate.org&#x2F;node&#x2F;5362" rel="nofollow">http:&#x2F;&#x2F;lambda-the-ultimate.org&#x2F;node&#x2F;5362</a><p>* <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22192656" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22192656</a>
评论 #29351854 未加载
评论 #29351047 未加载
评论 #29352232 未加载
odipar超过 3 年前
No Stinking Loops! <a href="http:&#x2F;&#x2F;www.nsl.com" rel="nofollow">http:&#x2F;&#x2F;www.nsl.com</a>
johan_felisaz超过 3 年前
Genuine question, what would be the idiomatic way of doing an impure operation multiple times in J&#x2F;APL ? (e.g. if writing an interpreter loop)<p>I was wondering if it&#x27;s doable without the while. and other constructs (which honestly feel like plugged artificially in J, even syntax wise)
评论 #29351376 未加载
评论 #29351499 未加载
评论 #29353772 未加载
enriquto超过 3 年前
Why so much hate for loops? Loops are just a nice <i>notation</i> for some computational constructs. Sometimes they are the clearer way to write an algorithm. Very often an algorithm becomes clearer when written in explicit loop form than in &quot;vectorial&quot; notation.<p>Loops do not need to be artificially slow to discourage them. Any modern programming language should be able to recognize the construct and compile it in the most efficient way. Saying that you must avoid loops because they are slow is a failure in a particular programming language, not in the concept of loop. After all, all languages managed to implement loops efficiently many decades ago.
评论 #29351791 未加载
评论 #29352173 未加载
评论 #29352369 未加载
评论 #29352681 未加载
评论 #29353343 未加载
评论 #29353977 未加载
评论 #29355098 未加载
评论 #29352863 未加载
评论 #29352427 未加载
评论 #29353464 未加载
评论 #29352720 未加载
sys_64738超过 3 年前
When I saw the title the only method for repetitive code I could think of to replace loops was recursion.
评论 #29352357 未加载
brundolf超过 3 年前
I&#x27;ve found this tends to happen in my Rust code too, and even in my JavaScript lately (though sadly it has performance costs in JS). It&#x27;s true that 90% of loops in practice are just for processing collections, and that can be better served in most languages by using a harder-to-mess-up construct that&#x27;s designed for the purpose.<p>It really does almost feel like an extension of the goto trajectory, since loops themselves were one of the purpose-built constructs designed to cover specific, common uses of goto.<p>I wonder if we&#x27;ll see a &quot;control-flow considered harmful&quot; one day (this is a joke... mostly)
orcasushi超过 3 年前
I usually avoid loops. Guess I got sorta hooked by this new age functional school.<p>But recently realized even layman brains on drugs can understand some loop and goto statements:<p>&quot;Eat Sleep rave Repeat&quot;<p>Sometimes they are just the best to write logic.
awinter-py超过 3 年前
&#x27;and then he discovered loops&#x27; classic early apple interviewing story<p><a href="https:&#x2F;&#x2F;www.folklore.org&#x2F;StoryView.py?project=Macintosh&amp;story=Discovered_Loops.txt" rel="nofollow">https:&#x2F;&#x2F;www.folklore.org&#x2F;StoryView.py?project=Macintosh&amp;stor...</a>
fifilura超过 3 年前
Isn&#x27;t all this popularized in SQL? And (at least for me) written with a much clearer syntax.
评论 #29352260 未加载
dang超过 3 年前
A past related thread:<p><i>Loopless Programming</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=21278790" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=21278790</a> - Oct 2019 (122 comments)
ThePhysicist超过 3 年前
BPF didn&#x27;t have loops in the beginning either, but since Linux 5.3 it supports bounded loops as that seems to make programming a lot easier in many cases.
mlajtos超过 3 年前
I will always upvote APL&#x2F;J.
oh_my_goodness超过 3 年前
HN&#x27;s top-voted comment at this moment begins: &quot;Why so much hate for loops?&quot; The item cited as &#x27;hate for loops&#x27; is an introduction to &#x27;loopless&#x27; programming in J, a universally admired language developed by Iverson. Whether LINQ or SQL etc. are also examples of &#x27;hate for loops&#x27; or not ... I&#x27;m done.<p>For every web site there&#x27;s a moment when user comments need to be declared &#x27;not worth the pain of sifting through.&#x27; HN has crossed that threshold for me.<p>[Edit: My point is that we are crossing a sort of event horizon. Short-sighted micro-kvetching is becoming the largest single focus of user comments, upvotes, etc. on this site. Perennial examples: one-indexing vs zero-indexing; OO &#x27;vs&#x27; FP; whitespace. You can list more yourself.]
评论 #29352999 未加载
评论 #29353275 未加载
评论 #29356964 未加载