3 ms·
I just entered this variant into the server's repl so everyone can see the range of choices: (defop topcolors req (minipage "Custom Colors" (tab
by pg 19y ago
I just entered this variant into the server's repl so everyone can see the range of choices:
(defop topcolors req
(minipage "Custom Colors"
(tab
(each c (dedup (map downcase (trues [uvar _ topcolor] (keys profs*))))
(tr (td c) (tdcolor (hex>color c) (hspace 30)))))))
Defopa means only admins can use something, but since this is defined with defop, everyone can see this page: http://news.ycombinator.com/topcolors http://news.ycombinator.com/topcolors.
- Tichy 19y agoThat calls for the feature to enable color picking by clicking on the colors ;-)
- kirubakaran 19y agoNow you don't think pg's time would be better spent writing essays, do you? :-) http://news.ycombinator.com/item?id=97830 http://news.ycombinator.com/item?id=97830
- Tichy 19y agoJust trying to go with the flow ;-)
- sridharvembu 19y ago(before I begin: I am familiar with macros & DSLs, code generation, building a custom language layer and then write your app in that custom language and so on, and I buy into almost all of it) I am sure the code above is poetry for those deep into it, but for a person who is a bit rusty (or god forbid, new to the code base), this is basically indecipherable. Look at how many tokens are there in a line like (each c (dedup (map downcase (trues [uvar _ topcolor] (keys profs*)))) How many people can answer the question of which ones are macros, functions, simple identifiers and so on? In that particular example I am stumped at [uvar _ topcolor] and can't get past it. Yes, I have read Paul's thesis on Lisp code density (quick summary: each line is dense, but there is a lot less overall code so it evens out or better), but my counter would be that there is a density beyond which most mortal brains can't penetrate. Without intending to cause offense, I am going to say that this is tending to write-only code. Sure, the equivalent Ruby or Python (leave alone blubs like Java or C#) would be pages long, but I suspect that lower density leads to better understandability.
- pg 19y agoLook at how many tokens are there in a line like There's not really a concept of lines in Lisp; you can break expressions wherever you like. E.g. you could also write: (defop topcolors req (minipage "Custom Colors" (tab (each c (dedup (map downcase (trues [uvar _ topcolor] (keys profs*)))) (tr (td c) (tdcolor (hex>color c) (hspace 30)))))))
- sridharvembu 19y agoActually, the equivalent Ruby/Python would use a simple SQL query. I have long noticed how SQL is the poor-man's functional "DSL" for such uses ...
- nostrademons 19y agoI don't think that's a problem with macros so much as obscure naming conventions and an obsession with brevity. In the original example, I had a pretty good idea what minipage, tab, each, dedup, map, keys, downcase, tr, td, and tdcolor mean. I can figure out c (color?) and req (request?) from context. I have no clue about defopa, uvar, trues, _, [], profs, topcolor, hex>color or hspace (or I have guesses, but wouldn't trust my guesses enough to pin down the semantics). From PG's post above, it seems like those are fairly evenly distributed across macros and functions. I don't need to know whether td is a macro or function to guess that it outputs a table data cell. I do need to know that it outputs a table data cell, and I only know that because I'm familiar with HTML.
- sridharvembu 19y agoAgreed on the obsession with brevity. Reminds me of mathematical proofs, where you work out everything offline, and then make the proof elegantly brief. There is a similar process going on here - writing macros really does boil down to that kind of offline work. Just as with such elegant proofs, though, you do need a pencil and paper to trace through the steps. And if the programmer were anything but of the highest caliber, it is fairly easy to get tripped up. The way blub languages handle (the absence of) macros for td, tr etc. is to invent templating languages (JSP etc) where you embed Java inside HTML. You basically have a DSL living in a separate syntactic space. That gets the job done, for the specific problem space at hand (web apps). I have come to like that syntactic space separation: HTML lives as HTML, SQL lives as SQL and so on. With macros, you are getting everything to live in the same syntactic space, so you get the proliferation of tokens, without that structural separation that aids in comprehension.