4 ms·
So don't do that. As programmers, we can indeed write infinite loops. Why is it "a bad idea" if the loop happens at compile time rather than runtime? Why shoul
by kentonv 10y ago
So don't do that.
As programmers, we can indeed write infinite loops. Why is it "a bad idea" if the loop happens at compile time rather than runtime? Why should we reduce the expressiveness of our language to avoid this possibility?
- tejasmanohar 10y agoRule of Least Power
- kentonv 10y agoThe Rule of Least Power leads people to lock themselves into low-power languages, only to find that they need more power, which leads to extending the language incrementally to support incrementally more power, which inevitably leads to a mess. Most heavily-used file formats (even "config" formats) eventually evolve into turing-complete languages, but inevitably they are bad languages, because they were not designed with this end-state in mind.
- derefr 10y agoWe (perhaps stupidly) make the assumption that compilers halt all the time, such as in shared CI environments.
- eridius 10y agoShared CI environments should always impose some sort of resource limit. Even without turing-complete type systems, you can still make compilation take effectively forever. It's been a while since I tested, but by my recollection, creating a fixed-length array of sufficiently large size in Rust would make compilation hang indefinitely (well, for much longer than I was ever willing to let it run). Of course this particular behavior may have been fixed (or maybe not; I'm not in a position to test right now), but I'm sure there's other ways to produce artificially long compilation times as well.
- dvt 10y agoBecause it's not necessary. If a Turing-complete programming language can't be expressive enough without a Turing-complete metalanguage, then it's probably not designed very well. What next? Will we start seeing meta-metalanguages because, hey, it makes compilation less error-prone (but adds something we'll call pre-compilation)?
- clock_tower 10y agoI think C/C++ #ifdefs could qualify as a meta-meta-language. I've certainly found that there are situations where static analysis can't comprehend C++ without pre-compilation...
- dvt 10y agoYes, I think you're right, actually. I doubt the C/C++ pre-processor is Turing-complete, though.
- pcwalton 10y ago> If a Turing-complete programming language can't be expressive enough without a Turing-complete metalanguage, then it's probably not designed very well. What is your proposed alternative to the Paterson conditions (described in the top comment)?
- cronjobber 10y ago> So don't do that Sure boss, I'll fix it. Would have fixed it already, if only nontermination wasn't the most unhelpful kind of compiler error message, ever...
- naasking 10y ago> Why is it "a bad idea" if the loop happens at compile time rather than runtime? Because you need at least one reliable tool to tell you when there's a problem, and if that tool isn't a compiler, what are you left with? When do you realize that a long compilation is actually in an infinite loop and not simply a long compilation? How do you debug the cause of an infinite compilation? These questions may have answers, but current compilers aren't designed to address them.