TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Syntax is the last thing you should design

74 pointsby pcmonkabout 8 years ago

8 comments

aaron-leboabout 8 years ago
The author is right that syntax isn&#x27;t the be all end all, but syntax often drives semantics and vice versa. More than one language has crashed on the rocks of unforgivable syntax, and even successful languages even have small syntax annoyances that will never go away.<p>My growing belief is that if you can&#x27;t express your language using a Pratt parser you need to rethink what you are doing. Once you grok them and get your first one up they&#x27;re more extensible than anything else - far simpler than a parser generator and very easy to write in any language.<p><a href="http:&#x2F;&#x2F;javascript.crockford.com&#x2F;tdop&#x2F;tdop.html" rel="nofollow">http:&#x2F;&#x2F;javascript.crockford.com&#x2F;tdop&#x2F;tdop.html</a><p><a href="http:&#x2F;&#x2F;journal.stuffwithstuff.com&#x2F;2011&#x2F;03&#x2F;19&#x2F;pratt-parsers-expression-parsing-made-easy&#x2F;" rel="nofollow">http:&#x2F;&#x2F;journal.stuffwithstuff.com&#x2F;2011&#x2F;03&#x2F;19&#x2F;pratt-parsers-e...</a><p><a href="http:&#x2F;&#x2F;www.oilshell.org&#x2F;blog&#x2F;2016&#x2F;11&#x2F;01.html" rel="nofollow">http:&#x2F;&#x2F;www.oilshell.org&#x2F;blog&#x2F;2016&#x2F;11&#x2F;01.html</a><p><a href="http:&#x2F;&#x2F;effbot.org&#x2F;zone&#x2F;tdop-index.htm" rel="nofollow">http:&#x2F;&#x2F;effbot.org&#x2F;zone&#x2F;tdop-index.htm</a><p>Several of them link each other. Thorsten Bell&#x27;s book where you write an interpreter in Go uses it, too, to parse his own language Monkey.
评论 #13794310 未加载
评论 #13796017 未加载
odirootabout 8 years ago
Funnily enough syntax is one of the most important factors for me. Call me superficial but that was my main reason for choosing Python.
评论 #13796326 未加载
tomatsuabout 8 years ago
That&#x27;s only true if you don&#x27;t simply go with C-like syntax.<p>For example, Dart prioritized familiarity. They wanted to make it easier for people who already know JavaScript, C#, Java, or ActionScript.<p>JavaScript was also made to look somewhat like Java and they even put &quot;Java&quot; right in the name to make it look more appealing to the masses.<p>Creating completely new syntax is a very risky move which will always hinder adoption.
评论 #13795730 未加载
danielhooperabout 8 years ago
Going to join the &quot;I strongly disagree&quot; camp with Swift as my example. The expressive syntax in combination with the strict type system quite often challenges me to design succinct app architecture.<p>I personally prefer to omit type information from naming, so for example I would declare a username text field of a view controller as so: `let username = UITextField`. Other devs might declare the text field as a `usernameTextField`, and somewhere else declare a variable called `username` to represent the string from the text field, but now you have a view controller concerned with both the textfield and the data from the textfield. By naming the textfield simply as &#x27;username&#x27;, I force myself to not have a &#x27;username&#x27; value anywhere else in this particular view controller, which results in forcing myself to entirely separate these concerns. I can elaborate on this if someone is interested in trying to get this working in practice.
yxhuvudabout 8 years ago
Thanks for the link to cheery&#x2F;chartparser. It is the first complete and readable implementation of the parser type with right recursion optimization and parse forest generation that I&#x27;ve been able to find, and I have been looking as I&#x27;ve been trying to implement this (and failed!).
kazinatorabout 8 years ago
Irony: g++ has an (evidently) hand-written parser that&#x27;s well over a megabyte of code in one file.
评论 #13795041 未加载
vidarhabout 8 years ago
I disagree with this intensely.<p>For starters, syntax drives how I interact with a language as much as - maybe more than - semantics. How expressions are laid out is intensely important to me, as it affects how I remember and visualise the code. I can visualise the layout of code I have not worked with in years when the syntax is clear, and the code is well formatted.<p>I can work around painful semantics and find ways to pretend they don&#x27;t exist by avoiding features or picking patterns that work better; but painful syntax usually stares me in the face ever moment I work with a language.<p>I have more than once rejected or picked languages based on syntax. E.g. I can&#x27;t look at a Python program without getting annoyed with the syntax, and I avoid using the language whenever possible over it, and I work with Ruby whenever I can for the same reason (though the language geek in me wants to cry whenever I think about the Ruby grammar)<p>I also reject the idea of avoiding hand written parsers to start with. I sympathise a bit with the idea. I can see quickly testing changes with a parser generator. And certainly, if you hand write a parser, you need to avoid the temptation of adding all kinds of awful exceptions.<p>E.g. I love Ruby as a user of the language, but the MRI parser is beyond awful, and I think the syntax could have had most of the nice aspects and avoided most of the awful syntactical warts with a bit more discipline (&quot;favorite&quot; wart at the moment: &#x27;% x &#x27; parses to the literal string &quot;x&quot; - &quot;%&quot; when not preceeded by an operand that makes it the infix operator &quot;%&quot; starts a quote-sequence where the following character indicates what the quote character should be - with the exception of a few special character, most characters will set the quote character to its identity. So in &#x27;% x &#x27;, the quote character is space).<p>Though MRI uses a Bison parser, but contains thousands of lines of handwritten exceptions, demonstrating both the bad parts of hand writing irregular exceptions into parsers, as well as how easily you can mess things up even if using a parser generator if you have one that isn&#x27;t strict enough.<p>But to me, if your hand written parser becomes big and&#x2F;or problematic to maintain, you&#x27;re designing a language that will be problematic to parse cleanly, and it&#x27;s probably worth revising your grammar (I wish this rule had been adhered to for Ruby).<p>Nice, regular, clean grammars tend to lend themselves very well to small, compact hand-written parsers. In practice I&#x27;ve never run into a situation where a grammar change required major rewrites of a parser in any project I&#x27;ve worked on for this reason, unless the rule deviated majorly from what I&#x27;d consider good practice in language design in ways that would cause problems for most parser generators too.<p>Modularising a hand written parser along the lines of the grammar rules is easy, and few changes cut so deeply across grammar rules to make this difficult.<p>But what a hand written parser tends to get you over a parser generator, is better ability to do clean error reporting, and better ease of introspecting how parser changes actually changes the processing in ways that are meaningful to mortals. To me at least, this is a lot more difficult to do with ever parser generator I&#x27;ve tried (and I keep hoping to be proven wrong; I&#x27;ve tried writing my own too, to try to prove myself wrong, and so far I&#x27;ve failed to come up with something I consider a usable replacement to handwritten parsers - you certainly <i>can</i> come up with something expressive enough, but it tends to end up being verbose enough to lose most of the benefit over clean code in the target language that saves you from having to deal with idiosyncracies of the generator).<p>To me the &quot;solutions&quot; offered demonstrate exactly <i>why</i> syntax matters to me:<p>I deeply admire Forth and Lisp and descendants on a technical level, but the syntax has always been a massive barrier to me for both language classes. I chose a s-expression inspired syntax to kick off my own compiler project by basically treating it as a serialization format for the parse tree, and first adding a parser on top later, but I did that first to be able to toy with semantics of something I didn&#x27;t intend to make into its own language, and then to act as the &quot;guts&quot; of my in-progress Ruby compiler, not because I&#x27;d be willing to work with it more than that.<p>If anything, I&#x27;ve found it incredibly painful to work with, and I&#x27;d never have &quot;held out&quot; for very long without bolting a more human-friendly parser on top very early on. The experience has made me more insistent - not less - on if not starting with the syntax, then at the very least co-evolving semantics and syntax from the outset.
评论 #13794981 未加载
评论 #13795383 未加载
评论 #13800735 未加载
评论 #13794790 未加载
评论 #13795239 未加载
logicalleeabout 8 years ago
It is possible to completely avoid syntax, period, by putting boxes of various colors on a whiteboard and labeling or connecting them with pictographic symbols representing what you want to do.<p>As soon as you do so you will realize that all modern programming languages are as dumb as a sack of rocks, and the functionality you are coding is trivial.<p>You can then design the syntax, which is what separates your language from every other dumb as a sack of rocks language.<p>Quick, name a language where I can do something simple like mention &quot;Whenever this function is called, make sure there is enough free memory (at least ---- MB) before actually calling it; if there isn&#x27;t, first swap out any objects from memory to disk, starting with the ones that had been used the longest time ago, and after the function has finished running, swap those back into memory.&quot;<p>That&#x27;s pretty straight-forward and well-specified. Name a language I can do that in?<p>Or how about this: &quot;analzye this library and include a logically simplified version that only needs to address these cases:&quot; (a list of conditions.). What language will even try to simplify included source code?<p>Or take debugging. Name a language I can add this line to: &quot;if variables A and B ever both change as a result of the same function call, print the following debugging message:&quot; trivial. Name a language that can do it.<p>Languages are dumb. They do almost nothing. I can&#x27;t <i>wait</i> for the future, it can&#x27;t get here fast enough.
评论 #13794263 未加载
评论 #13794392 未加载
评论 #13794060 未加载
评论 #13794326 未加载
评论 #13794302 未加载
评论 #13799593 未加载