2 ms·
I've yet to find Lisp any more or less readable then anything else I write day-to-day (Python, Ruby, JavaScript, CSS, HTML). In all these languages I find mysel
by swannodette 16y ago
I've yet to find Lisp any more or less readable then anything else I write day-to-day (Python, Ruby, JavaScript, CSS, HTML). In all these languages I find myself constantly fighting to find a readable and reasonable formatting. I certainly won't argue that I find myself doing this less in Lisp, but the readability argument is just something that continues to be bandied about by people who haven't spent much time programming in Lisp.
Here's a DSL I'm working on for CouchDB:
(defmapping post
:pre-commit timestamp
:fields {:author-id :string
:title :string
:created :date-time
:modified :date-time
:body :string
:tags [:string]
:meta {:copyright :string
:href :string}})
I wish my work in other languages had this kind of structural clarity all the time!
In constrast my favorite Python lib for CouchDB work looks like this:
creators = ListField(DictField(Mapping.build(
name = DictField(Mapping.build(
name_authority = TextField(),
name_authority_id = IntegerField(),
display_string = TextField()
)),
user_id = IntegerField(),
roles = ListField(TextField()),
attrs = ListField(TextField()),
xts = ListField(TextField()),
)))
Just look at all those parens!
- DannoHung 16y agoThat honestly looks more like a failure on the part of the Python library maintainer to create a pleasant way to create record prototypes. I mean, all you're doing in your list example is creating dictionary and list examples of the mapping you want. There is literally nothing stopping you from doing that in Python.
- swannodette 16y agocreators = [{"name" :{"name_authority" :TextField, "name_authority_id" :IntegerField, "display_string" :TextField}, "user_id" :IntegerField, "roles" :[TextField], "attrs" :[TextField], "xts" :[TextField]}] Yes you could do something like this. But the lack of keywords does reintroduces some noise via the quotes around strings. Moving the colons around like this to give visual alignment would probably be frowned upon. So my sense is that this would be considered "un-Pythonic" but I could be wrong.
- cma 16y agoUse single quotes; less noise.
- DisposaBoy 16y agowho writes code like that? creators = [ { "name": { "name_authority": TextField, "name_authority_id": IntegerField, "display_string": TextField }, "user_id" :IntegerField, "roles": [TextField], "attrs": [TextField], "xts": [TextField] } ] anyway
- swannodette 16y agoI certainly don't write Python code that looks like what I wrote. My point was that the various idiomatic versions, including yours, certainly isn't any more readable than the Clojure version.
- DisposaBoy 16y agoI don't speak for everyone but the reason I see lisp code as unreadable is that most of what I've seen is written like your example. That is, there is some indentation which helps, but it's as-if the coder is afraid to utilise vertical space so they put all the closing brackets on the same line, most of the opening ones in the middle of some lines. With that kind of formatting (for me at-least), it's not immediately clear which.