5 ms·
> [P]eople are taught to think in strings[, b]ut what people actually need are grammars. I don’t actually disagree with you for the most part, but I feel that
by mananaysiempre 3y ago
> [P]eople are taught to think in strings[, b]ut what people actually need are grammars.
I don’t actually disagree with you for the most part, but I feel that an important caveat has gone unacknowledged.
Grammar formalisms have the same weakness compared to dealing with raw strings as sound static type systems do compared with dynamic typing: there are small, mostly isolated islands of feasibility in a sea of intractable (often undecidable) generality, and if your problem doesn’t fit inside those borders things start to get nasty (cf how even GCC’s handwritten rec-descent parser didn’t get its lexer hack interactions correct in all cases[1]).
I still agree that we spend criminally little time on syntax. Starting with the simplest cases: with how much time is spent in school on “order of operations” you’d think we could take a moment to draw[2] a damn syntax tree! But nooo. There are in fact working mathematicians who don’t know what that is. (On the other hand, there are mathematicians who can explain that, in a sense, the core of Gödel’s incompleteness is not being able to reason about arithmetic—it’s being able to reason about CONS[3], which arithmetic happens to be able to very awkwardly do.)
[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67784 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67784
[2] https://mlochbaum.github.io/BQN/tutorial/expression.html https://mlochbaum.github.io/BQN/tutorial/expression.html
[3] https://dx.doi.org/10.1215/00294527-2008-028 https://dx.doi.org/10.1215/00294527-2008-028
- compressedgas 3y agoSo you have heard about StringBorg: https://edolstra.github.io/pubs/injections-gpce07-final.pdf https://edolstra.github.io/pubs/injections-gpce07-final.pdf It knows when to do escaping and how. It also can detect, though dynamically, when fragments have been combined into an illegal sequence which would be rejected by the full grammar. It can not however guarantee that the result will parse only that it can not detect that it would fail.
- mananaysiempre 3y agoWas that a question? In that case, now I have :) The authors include both of the Eelcos I’ve ever heard of no less! The ugly quasiquoting seems unfortunate (I’ve a half-serious suspicion the reason Template Haskell never got popular is that it looks so bad), and the GLR sledgehammer precludes ever having a lightweight implementation, but otherwise it seems like a interesting entry in the extensible languages story.
- jameshart 3y agoI feel like nobody ever ends up having this discussion about JSON. Generating JSON data using string interpolation or templating is clearly wildly insane, right? You don’t do it. Maybe for some config file generation scenarios you might just run a template JSON file through a token substitution or env var interpolation or something. But you’d feel bad about it, because it’s so easy to NOT do it that way. And even then you’re not interpolating in JSON fragments like ‘“age”: 25’ - you’d have the decency to only interpolate in values like ‘25’. In the node ecosystem it’s so easy to switch from a .json file to a .js file, too, if you want to build the json dynamically. For some reason people feel more willing to attempt it with YAML. And then regret it when they realize how significant indenting has screwed them. And then with HTML people just give up and go ‘yup, it’s all text, even the angle brackets’
- pphysch 3y agoI've used AWK to output (flat!) JSON in ETL pipelines, because it's blazingly fast and "zero" deps. But I'd never try to implement my own parser or output deeply nested JSON.
- jameshart 3y agoA useful tool for transforming JSON to and from a format that is more amenable to simple text tooling is gron: https://github.com/tomnomnom/gron https://github.com/tomnomnom/gron Takes all the tree and hierarchy management away, makes it so ordering doesn’t matter. If I’m generating JSON from batch scripts it’s my preferred tool (easier than fighting jq for many tasks)
- jlokier 3y ago> Generating JSON data using string interpolation or templating is clearly wildly insane, right? You don’t do it. I'm sorry to report that I've seen a lot of JSON generated by string concatenation and templating, in different projects. Often using 'printf' or 'echo' in various languages. Sometimes using whatever's used for HTML string templating if the JSON is embedded in HTML or served as a resource similar to HTML. Yes, its horrible and breaks if fed variable values that have characters like quotation marks in. People do it anyway. Even in languages that have perfectly good data structures and JSON libraries. I've seen a fair amount of parsing values out of JSON using regexes too, assuming specific formatting of the supplied JSON.
- wombatpm 3y agoIf Twitter and TikTok is any indication, schools do not spend enough time on order of operations 5 - 2(3 - 1) - 5 = ?
- gsk22 3y agoIf Facebook is any indication, schools have been failing to teach order of operations for decades. My older relatives are the ones I see repost these inane order-of-operation tests, getting the answer consistently wrong.
- bobthepanda 3y agoAre schools failing to teach it, or do some lessons fail to stick through the decades depending on how much math you’re doing? Schools have no control on what your older relatives have been up to.
- DaiPlusPlus 3y agoToday’s Facebook grumpy posters would be the same kids doing “New Math” in the 1960s: https://en.wikipedia.org/wiki/New_Math https://en.wikipedia.org/wiki/New_Math - just something to consider
- HideousKojima 3y agoMy school taught PEMDAS but failed to teach that multiplication and division are equal in priority, nor did they teach that when there is ambiguity working left to right takes priority.