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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Fixing switch - what I want out of switch statements

4 点作者 samuellevy将近 13 年前

3 条评论

ggchappell将近 13 年前
SL: What you want out of switch statements is an easy way to implement a state machine -- or state-machine-like construct.<p>While this is a worthy goal, I don't think your proposed syntax is very readable. It might be better to think a bit more abstractly, and instead of asking, "How can we improve switch?" ask, "What features does a language need in order to facilitate implementation of &#60;whatever&#62;?"
评论 #4220578 未加载
Ralith将近 13 年前
Your trivial example is already spaghetti code; I'm loathe to imagine what real-world use would look like. It's also an internally inconsistent concept: consider "case 3" and "case s &#62; 4". Are you comparing values to the switch statement, or testing conditions like an if statement? What do you do when those two come into conflict?
bendauphinee将近 13 年前
Interesting idea. I can think of a few places in my code this would be useful.