9 ms·
(defun udpate () (let ((pos (find-char-pos))) (move-char pos)) (print (stats)) (rotate enemies)) (defun udpate () (set 'pos (fin
by such_a_casual 9y ago
(defun udpate ()
(let ((pos (find-char-pos)))
(move-char pos))
(print (stats))
(rotate enemies))
(defun udpate ()
(set 'pos (find-char-pos))
(move-char pos)
(print (stats))
(rotate enemies))
I now have to keep this 'pos symbol in my head for the rest of the function (in another language, forever in this case), whereas in the first example I can just forget about the variable after the next line. It doesn't exist anymore. It makes code clearer and much easier to refactor since I can immediately see everywhere that the variable is used.
- nnq 9y agoI get it, despite having a small issue with "forever" being defined as "just 2 more loc", but I just: (1) feel more drawn to "Flat is better than nested." from "Zen of Python" to dislike the extra scoping level despite the conceptual clarity it provides (because I'm sure some "idiot" will abuse it and I'll end up reading a 10 nested let-s monstrosity pretty soon) (2) like to write small functions, so forever will always be "~10 loc max" for me ...so imho if you're used to "thinking in classic Lisps" you'll miss let, otherwise you won't. What I'd miss for example would be some Haskell-like where (https://wiki.haskell.org/Let_vs._Where#Advantages_of_where https://wiki.haskell.org/Let_vs._Where#Advantages_of_where) but I'd wake quickly out of it since it would make no sense to someone not already "stuck in Haskell-like thinking mode".
- jazzdev 9y ago(defun udpate () (ag-if (find-char-pos) (move-char it)) (print (stats)) (rotate enemies)) Doesn't Hy's anaphoric macros solve this? And one could even argue it's more readable.
- such_a_casual 9y agoI don't know what that is (tried googling it), but it doesn't look like it's doing the same thing as let.