3 ms·
The author mentioned this at the end, but banning while loops (and any other way for running a loop with a priori unknown number of iterations) actually decreas
by H8crilA 5y ago
The author mentioned this at the end, but banning while loops (and any other way for running a loop with a priori unknown number of iterations) actually decreases the expressiveness of a language - it becomes no longer Turing complete. A classic example is the Ackerman function - it cannot be computed in a primitive recursive language.
(The author is on point when they say almost all code used in practice is primitive recursive, though)
- tbenst 5y agoI think “while loops” are orthogonal to primitive recursive functions.. for example, here’s how to compute the Ackerman function using only recursion in several languages; https://stackoverflow.com/questions/16115815/ackermann-very-inefficient-with-haskell-ghc https://stackoverflow.com/questions/16115815/ackermann-very-...
- H8crilA 5y agoIt doesn't have to be a while loop. Recursion is another way to implement a loop with a priori unknown number of iterations. You can also use goto. And no, they aren't othogonal. A simple language with only integer variables, basic arithmetic, if() and for(i in range(x,y)) is actually not Turing complete.
- notatoad 5y agoi think the key point is that the linter doesn't ban anything. nobody is proposing removing while statements from the language. if you have a valid case for disobeying the linter, then you can disable the linter for that line: https://pylint.pycqa.org/en/latest/user_guide/message-control.html https://pylint.pycqa.org/en/latest/user_guide/message-contro... (if a project unconditionally bans PRs that don't pass the linter, that's a different issue, and not really the linter's fault)
- mst 5y agoI could certainly see a linter that says "are you sure?" before you initially add a while loop to make you ask yourself if that's really the best option being quite neat. The trick would be making it sufficiently useful and minimally annoying that people don't get angry and turn it off.
- notatoad 5y agoit's not really the linter's job to say "are you sure". the linter just applies the rules and generates messages, it's up to you to do with those messages what you will when using the python integration in vscode (which runs pylint), clicking on a linter error gives me a context menu where one of the options is essentially "are you sure?" and will automatically adds the appropriate comment to disable the linter for that line.
- mst 5y agoI was thinking along the lines of something similar except for running the linter as a pre-commit hook.