4 ms·
As much as I like lisp the beauty, strength and philosophy of Lisp, it seems like I can't make the switch in my real production project. Why? Because of the rea
by d0m 16y ago
As much as I like lisp the beauty, strength and philosophy of Lisp, it seems like I can't make the switch in my real production project. Why? Because of the readability: (Taken from the article)
(let [width (inc (apply max (map (comp count values) squares)))
line (join \+ (repeat 3 (join (repeat (* 3 width) \-))))]
So, I see that and I'm like, wtf, where do I start.
let width .. inc apply max of map comp coun, wtf. Let's start from the end.
map all squares with comp count values, take the max of those, increment it, put that in width. ok
then, line join repeat 3 join.. wtf. let's try it from the end;
minus three times the width repeat.. ok, repeat 3width '-', then, join this, repeat it 3 times, then join again with +, and put that in line.
I always struggle like that when reading lisp, people always give example like:
(map square '(1 2 3 4)) where you can read it all in one pass.. but real code is usually more complicated. So, if I had to rewrite that more clearly, I'd probably just separate it in more functions so I don't have to have more than, say 4 nested ().
And, yeah, the problem is not that much the "read from the end", but more about the actual work of each line of lisp being a puzzle to guess where to start reading it. Some are better to read up front, others are better to start from the last. Sometime you skip the first part, and read the last part, then come back at the beginning. That is what trouble me. I want to be able to read code as fast as possible - skim over it while understanding it.
Now, you might argue that you can write nested stuff in every languages. True enough BUT it seems like the philosophy in python is more about making things clearer and using more function if it makes everything simpler/easier to maintain and understand.. while in practically all lisps code I read, it feels like it is a write-only code without thought about you will read it after.
Is it because all the "Here's why lisp is better" are written by new-lisper who are too much excited as they can now use closures and nest everything rather than using simple, yet useful, normal functions?
When I read lisps forum, it's always about how that or that doesn't support tail recursive function or why macro rocks everything, but never talking about readability and good practices about not nesting everything up. Yeah, they say to use real editor, to never look at the (), to align thing smartly.. I don't know for you, but I feel like my brain works in a kind of stack. I can put some stuff in my short memory, but I can't put more than say 5-6 stuff at once. And when I see this:
(let [width (inc (apply max (map (comp count values) squares)))
It just seem too much to read it quickly; I need to stop and think. Yeah, some laugh at me saying "Yeah, you need to think*! You are not used to that! Well, no, when I'm reading a book, I like to think about the concept or the story, not trying to figure out how to read that complicated sentence.
When I read python code, I think about pattern, modularity, what's the goal of the actual file. When I'm reading lisp, I can't go quickly into it because of those 10 levels nested function.
/end of rant.
- deleted 16y ago[deleted]
- evanrmurphy 16y agoHmm... I just tried it, and backslashes don't seem to work as a way to escape Hacker News markup. Were you kidding? Update: Ah, it looks like you can get literal asterisks if you use your whitespace carefully: * asterisk * another one emphasis
- deleted 16y ago[deleted]
- m_myers 16y agoNope, not kidding, just ignorant. I'll delete my comment.
- swannodette 16y ago(inc (->> squares (map (comp count values)) (reduce max))) Similar to the Python | operator that came up yesterday.
- nickik 16y agolen(values[s]) for s in squares) (map (comp count values) squares) How is that better! If you know the standard function this is super easy (in both languages). Note clojure is just one pure function call nothing fancy. (inc (apply max 1+max The expressivness is tiny bit better in python because the max function looks at the type of the input. apply is a commen pattern that is easy to anderstand. The python way is a little bit easier to read but the clojure way makes the library simpler. line = '+'.join(['-'*(width*3)]*3) line (join \+ (repeat 3 (join (repeat (* 3 width) \-)))) The thing that makes python shorter here is that they alow math on non number. I don't think that a good idea in general but that up to the language designers taste. The diffrence between the code is basiclly that in clojure you have to use repeat two times instead of * and one more join. So only real diffrences are on the first line clojure uses apply and on the second repeat instead of join. I think is just a matter of training. Much harder then the language reading is to know what the standard functions really do.