TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Fixing switch - what I want out of switch statements

4 pointsby samuellevyalmost 13 years ago

3 comments

ggchappellalmost 13 years ago
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 未加载
Ralithalmost 13 years ago
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?
bendauphineealmost 13 years ago
Interesting idea. I can think of a few places in my code this would be useful.