3 ms·
There was a step-change improvement for me when I tried expressing some JS patterns via `underscore.js` instead of procedurally: eg: http://underscorejs.org/#ea
by ramses0 2y ago
There was a step-change improvement for me when I tried expressing some JS patterns via `underscore.js` instead of procedurally: eg: http://underscorejs.org/#each http://underscorejs.org/#each
Thinking of something as `each | map | filter | sum` is waaay less buggy than writing bespoke procedural code to do the same thing. No doubt there is a "cost" to it as well, but the _abstraction_ is valuable.
Now, if there were a "compiler" which could optimize that whole pipeline down and squeeze out the inefficiencies between steps because it could "see" the whole program at the same time. (oh, I don't know, something like `SELECT * FROM foo WHERE a > 100 AND b < 9000 LEFT JOIN bar ON ...etc...`)
...perhaps you could get both an expressivity gain (by using higher level concepts than "for" and "while"), a reduction in bugs (because you're not re-implementing basic work-a-day procedures), and an improvement in efficiency (because the "compiler" can let you express things "verbosely", while it sorts out the details of efficiency gains that would be tenuous to express and keep up to date by hand).
- faizshah 2y agoI 100% agree, I think the functional features that have been added across all the popular languages (map, reduce, fold etc.) has been a positive. Nothing demonstrates it better (imo) than purrr in R: https://github.com/rstudio/cheatsheets/blob/main/purrr.pdf https://github.com/rstudio/cheatsheets/blob/main/purrr.pdf I also think there is some merit to “high syntactical density” clearly if you can see the entire code in one place instead of having to navigate through many files or sections that’s beneficial. (Heavily discussed in the last big HN thread: https://news.ycombinator.com/item?id=38981639 https://news.ycombinator.com/item?id=38981639) I also think JQ has proven the merit of tacit functional languages in that you can concisely write arbitrary transforms/queries on json that can be more expressive than SQL (many SQL engines have added JSONPath anyway). And I also think postfix is great for processing pipelines. But I am not totally convinced in the approach of APL/J/Q/KDB for the combination of terse style + prefix + tacit because it makes the code so difficult to read. I think if you took an approach similar to JQ where instead of relying on symbols operators were just human readable words it would be easier to get us half way there to trying out the verb, adverbs etc. approach of the APL family. The problem with making it human readable text is that you lose the conciseness which is part of the draw of the APL family as they want to have a high syntax density and analogous code to mathematical expressions.
- snthpy 2y agoThat's kind of what we're aiming for with PRQL (prql-lang.org). While currently it only supports SQL backends, I want to generalize that to things like underscore.js.
- ramses0 2y agoIf I may be so bold as a pitch for adoption: For Python, support `prql-to-sqlite3` (in memory?) "out of the box" For JavaScript, support "array-of-dicts/objects" with no ceremony. Basically, in python I could justify the depends if I can say: sql = prql.parse( """select * ...""" ) results = db.execute(sql) In JS, similarly: all_my_records = [ { ... }, ... ] function oh_god_why_nevermind(...) { ... } subset = prql.execute( `select * from all_my_records ...` ) (butchering all syntax, of course) ...basically "nobody wants to learn sql nowadays", and in javascript "my kingdom for a left-join!" Pitch it as "graphql for data" (/zing!)
- snthpy 2y agoThank you for the suggestion. I actually very much agree with you. I've recently been updating my stack in other areas and have been utilising "Getting Started" or "Quick Start" sections a lot and thought that we're actually not making that easy enough or easy at all. I'll look into incorporating your suggestion soon. If you're up to it, you can open an issue in our repo and then I can ping you when that's done.