4 ms·
Some (including me) would argue that writing any loop yourself is considered harmful and you should be better of using higher order functions. In Haskell there
by fho 5y ago
Some (including me) would argue that writing any loop yourself is considered harmful and you should be better of using higher order functions.
In Haskell there is a higher order function for basically every usecase and (most of the time) the compiler is smart enough to merge chained higher order functions into a single loop.
Python is at least trying with its `itertools` package, but it's still a far cry from the generalization "modern" languages allow.
(Background: I was fortunate enough to program in Haskell for 2 years. It was great, but I can see that it's basically useless for a lot of common usecases :-( )
- Joker_vD 5y agoOkay, so how should the following loop be rewritten: while self.keep_going: s = input('> ').lstrip() if s == '': continue cmd = self.parse_cmd(s) # The "quit" commands sets self.keep_going to False, oh the horrors # of the global mutable state cmd() ? Should it be: for cmd in self.stream_of_commands(): cmd() But stream_of_commands() will still have a loop inside it, wouldn't it? Because that's how you write generators?
- clownpenis_fart 5y agoah yes, surely it is possible to restrict yourself to a subset of the language that is guaranteed to terminate and is therefore not turing complete and still be able to implement anything you want