HackerURLs

一次又一次被重新发现的经典。

同一个链接,相隔一年以上,一次又一次被人重新发现、再次冲上 Hacker News 首页。能经受住这种时间检验的,大多是值得一读再读的文章。每篇附中文标题,讨论最热的那些再加上中文导读和高赞评论翻译。

从名人堂开始
  • 4,700+篇经过时间检验的经典

Hall of fame

名人堂

在经典库里看全部精选

上首页次数最多、而且有中文导读的 30 篇。时间轴上每个黑点是一次上首页,空心点是一次没冲上去的投稿。

  1. 正在载入经典…

Archive

经典库

按第一次上首页的年份分布,点柱子筛选。

排序

    About

    这些经典是怎么挑出来的

    1. 01

      合并同一个链接

      读取 Hacker News 自 2006 年以来的全部链接投稿,把 http/https、www、跟踪参数等写法不同的同一篇文章合并成一条。

    2. 02

      只留经得起时间的

      同一链接至少两次拿到 50 分以上(约等于上首页),而且两次相隔一年以上;再由 AI 剔除状态页、产品首页和新闻事件。

    3. 03

      写导读、译评论

      上首页次数最多的 2,000 篇配上中文导读、"为什么经久不衰",并精选翻译 HN 高赞评论。导读由 AI 生成,可能有误。

    算法与计算机科学hillelwayne.com

    1/0 = 0:除零的来龙去脉

    1/0 = 0

    2次上首页
    6年跨度
    793累计得分
    809条评论

    2018 — 2024,它一次次回到首页

    黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。

    导读

    这篇文章讨论编程语言 Pony 将整数除零(1/0)定义为 0 这一设计选择,并围绕其理由与争议展开分析。文中涉及部分函数、错误处理,以及整数除零与浮点除零(后者仍得到 Infinity)的区别。

    为什么经久不衰:它触及一个看似简单却牵涉类型系统、错误处理与数学直觉的经典设计取舍,因此多年后仍值得拿出来讨论。

    关键词 Pony语言除零错误处理类型系统

    HN 评论精选

    除零几乎总是未处理的 bug,返回 0 会掩盖错误;应抛错,若确需 0 应显式处理。

    我对“1/0 = 0”的不满是:它本质上是在掩盖程序里几乎总是 bug 的情况。程序执行除以零,几乎肯定不是你想要的,而是你没能预见和处理的边界情况;既然没计划,返回的结果几乎肯定也不是你想给用户的。遇到这种未预料的边界情况,通常更好的做法是抛错:防止数据/状态进一步损坏,避免用户拿到一个她以为可信的坏结果,并清楚暴露问题。直接返回 0 恰恰相反。如果你是那 0.1% 预见到并确实想让程序把 1/0 当作 0 的人,那就显式检查这个情况并让它按你的意愿行为。Pony 作者可以任意设计语言,但在这个案例中,他们伤害用户远多于帮助用户。

    whack查看英文原文

    My problem with "1/0 = 0" is that it's essentially masking what's almost always a bug in your program. If you have a program that's performing divide-by-zeroes, that's almost surely something you did not intend for. It's a corner case that you failed to anticipate and plan for. And because you didn't plan for it, whatever result you get for 1/0 is almost surely a result that you wouldn't want to have returned to the user. When encountering such unanticipated corner cases, it's almost always better to throw an error. That prevents any further data/state corruption from happening. It prevents your user from getting back a bad result which she thinks she can trust and rely on. It highlights the problem very clearly, so that you know you have a problem, and that you have to fix it. Simply returning a 0 does the exact opposite. If you're one of the 0.1% who did anticipate all this, and correctly intended for your program to treat 1/0 as 0, then just check for this case explicitly and make it behave the way you wanted. The authors of pony are welcome to design their language any way they want. But in this case, they are hurting their users far more than they are helping.

    Pony 核心成员回应:这是有意但不满意的权衡,仅限整数除法,浮点仍得 Infinity,未来会引入可报错的部分函数。

    我是 Pony 核心团队成员。之后会写得更详细。先简单说几点:1)团队里没人对最终走到这一步感到满意;理解这个决定需要了解 Pony 如何处理部分函数(可能产生除零等错误的函数),以及由此带来的易用性问题。2)这只适用于整数除法,其中除零未定义;1.0/0.0 会使用可用的 Infinity 值。3)Pony 即将引入部分函数数学,包括把 1/0 视为部分函数(即会产生错误),以及处理 +、-、* 的整数上溢/下溢。4)即使没有这些操作,也很容易自己定义一个在除零时返回错误的除法。

    spooneybarger查看英文原文

    Hi, I'm on the Pony core team. I will be writing in more detail about this decision. A few short notes until then: 1) no one on the team has ever been happy with ending up here, understanding why the decision was made involved understand how partial functions (one that can produce errors like division by zero) are handled in Pony and interesting ergonomic issues that can result that is a large part of what my post will be about. 2) this applies only to integer division wherein division by zero is undefined. 1.0/0.0 uses the available Infinity value. 3) Partial function math is coming to Pony that includes 1/0 as partial (ie error producing) as well as handling integer overflow and underflow for operations: `+`, `-`, and `*`. 4) It's very straightforward even without that those operations to define your own division that will be partial (ie return an error) for division by zero. Edit to include link to the comment below because it contains a good bit of the decisions that have to make when dealing with integer math: https://news.ycombinator.com/item?id=17736637 Which is part of what I will touch on in my post about the decision process that Pony went through to reach to state we are currently at (which I want to highlight, is one we intend to improve- see #3 above).

    真正麻烦的是 0/0:沿不同路径逼近,x/y 的极限可以是 0、无穷甚至 17,所以不存在单一值。

    有人说“这很简单,1/0 就是 +Infinity”。所以真正有趣的是 0/0。x/y 在 x 和 y 都趋于零时的极限取决于你沿 xy 平面上哪条路径逼近奇点:沿一种逼近极限是 0,沿另一种发散到无穷,沿又一种极限是 17。我没开玩笑!去 GeoGebra 3D 输入 x/y 旋转图像,x=0、y=0 处的“值”是整个 z 轴。换个视角,用 WolframAlpha 画 z=x/y 并开启等高线模式,注意等高线从 z 轴辐射出去;每条线都是一种不同 z 值的逼近,沿每条线取极限会得到不同值。

    phyzome查看英文原文

    Some people say "oh, that's easy, 1/0 is +Infinity". So the real fun is at 0/0. The limit of x/y as x and y go to zero depends on which path across the xy plane you take towards the singularity. Along one approach, the limit is 0, along another approach the limit diverges to infinity, along yet another the limit is 17. I'm not kidding! Go to https://www.geogebra.org/3d and enter "x/y" and spin the graph around. The "value" at x=0 y=0 is the entirety of the z-axis. For another perspective, try http://www.wolframalpha.com/input/?i=z%3Dx%2Fy and turn on contour mode for the 3D plot. Notice how the contour lines radiate out from the z-axis; each of those is an "approach" to the singularity at a different z-value, and taking the limit along each line leads to a different value.

    把 1/0 定义为 0 会破坏除法与乘法的对称性,以及依赖 (x/y)*y=x 的代码。

    > 但 Pony 做了不健全的事吗?绝对没有。定义 1/0 = 0 完全没问题。什么都不会破坏。 它实际上破坏了除法与乘法之间的对称性,以及许多假设 (x / y) * y 等于 x 的代码。这里有一个简单且不实用的例子,但现实世界中并非不可能意外或有意出现这种简化代码,当 y = 0 时可能产生非常不精确的结果。

    luso_brazilian查看英文原文

    > But is Pony doing something unsound? Absolutely not. It is totally fine to define 1/0 = 0. Nothing breaks It actually does break something, the symmetry between division and multiplication and the many pieces of code that assume that (x / y) * y equals x. Here is a naive and non practical example, but it is not impossible to find a real world example where this simplified code manifests itself accidentally or by design function do_something_with_x(x, y) { let ratio = x / y; if (do_something_with_ratio(ratio)) { return x * y; } else return null; } Again, this is a naive example but one that could manifest itself with a very imprecise result when y = 0

    历次讨论

    同类还值得读

    1. 位运算技巧集

      Bit Twiddling Hacks

      斯坦福页面上的经典位运算技巧合集,收录了 popcount、前导/尾随零、位反转、交换、舍入等大量技巧,并附有解释和性能讨论。

      算法与计算机科学上首页 8 次 · 2011–2024graphics.stanford.edu编辑精选
    2. 如何不按平均评分排序

      How Not To Sort By Average Rating

      经典文章解释了为什么按平均评分排序不可靠:只有少量评价的条目(比如仅一条五星)会轻易排到最前,而评价数量的差异被忽略。

      算法与计算机科学上首页 7 次 · 2009–2024evanmiller.org编辑精选
    3. 数据结构可视化

      Data Structure Visualizations

      旧金山大学 David Galles 教授制作的数据结构与算法交互式可视化网站,涵盖 B 树、红黑树、排序、图算法等,可逐步操作观察其运行过程。

      算法与计算机科学上首页 6 次 · 2011–2021cs.usfca.edu编辑精选
    4. 1996 年以来的计算机科学最佳论文奖

      Best Paper Awards in Computer Science since 1996

      Jeff Huang 维护的一个汇总页面,收录了自 1996 年以来计算机科学各主要会议的“最佳论文奖”获奖名单,并按年份和会议整理,方便读者一站式浏览历届获奖论文。

      算法与计算机科学上首页 6 次 · 2010–2018jeffhuang.com编辑精选
    5. 算法(Jeff Erickson)

      Algorithms, by Jeff Erickson

      伊利诺伊大学 Jeff Erickson 教授的算法课教材,免费在线开放。

      算法与计算机科学上首页 5 次 · 2018–2022jeffe.cs.illinois.edu编辑精选

    打赏支持

    打赏二维码

    觉得有用,请作者喝杯咖啡。

    WeChat

    关注向阳乔木

    微信公众号「向阳乔木推荐看」

    微信公众号「向阳乔木推荐看」二维码

    微信扫一扫;在微信里打开本页时,长按二维码识别。