4 ms·
Indentation and convention both help (as does experience). Python: def spam(self, eggs): for egg in eggs: if egg.color == "white":
by Tiomaidh 15y ago
Indentation and convention both help (as does experience).
Python:
def spam(self, eggs):
for egg in eggs:
if egg.color == "white":
egg.crack
Which goes to:
xxx xxxx(xxxx, xxxx):
xxx xxx xx xxxx:
xx xxx.xxxxx == "xxxxx":
xxx.xxxxx
CL:
(defun spam (eggs)
(dolist (egg eggs)
(when (equal (color-of egg) 'white)
(crack egg))))
(Ignore the fact that this example was clearly written with object-oriented Python in mind :P .)
Which goes to:
(xxxxx xxxx (xxxx)
(xxxxxx (xxx xxxx)
(xxxx (xxxxx (xxxxx-xx xxx) 'xxxxx)
(xxxxx xxx))))
I don't think there's a huge difference.
- jrockway 15y agoActually, you've misindented the CL and that's causing confusion. You should indent when statements like: (when (equal foo bar) (do-something) So that it doesn't look like: (when (equal (some-long thing) (that is being compared)) (do-something)
- jshen 15y agoThe only significant different I see is that == isn't xx. If you turn == into xx then it's no different. If it were clojure it would look better than the python version since you'd use [] instead of () in a couple of places.
- CJefferson 15y agoI think you are over-cutting the python. First of all, with the python the first things on the lines are: def for if egg My eyes are naturally drawn along that list. While I could do the same thing for CL, I find the opening brackets slow me down. The colons at the end of each of those lines tell me that each of the def, for, and if are one-statement lines. With the CL, I have to backet-count along the line to figure out if everything is on one line. I can see instantly that ' if egg.color == white: ' is a complete statement, as it is a common pattern. With (when (equal (color-of egg) 'white), I need to bracket count to see where I have got to by the end of the line.
- deleted 15y ago[deleted]