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.

I am afraid to inform you that you have built a compiler (2022)

262 pointsby mutant_glofishalmost 2 years ago

20 comments

ashton314almost 2 years ago
It&#x27;s funny how projects grow like this organically.<p>Perhaps burned by experience, one time I implemented a mini-language for specifying some business logic that I knew—just <i>knew</i>—that our client would change his mind on a dozen times and not understand the half of the ramifications of his requests and would only arrive at the solution he <i>really</i> wanted by trial-and-error. Was the little language I made as complex as a &quot;real&quot; compiler? Goodness no. Was I happy to have a flexible language-based solution? True to my predictions, I <i>did</i> get many, many logic change request and handled them with ease. Yes, I was very happy after that.
评论 #37168939 未加载
评论 #37166503 未加载
评论 #37170182 未加载
评论 #37166691 未加载
评论 #37169182 未加载
random3almost 2 years ago
Given how easy it is to build a Turing machine, I&#x27;d argue that building something you don&#x27;t envision is the 99% of the time rule and it&#x27;s already captured by <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Greenspun%27s_tenth_rule" rel="nofollow noreferrer">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Greenspun%27s_tenth_rule</a> &quot;Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.&quot;<p>In fact I&#x27;d argue that it&#x27;s much harder to not accidentally build something that you don&#x27;t envision.
评论 #37170623 未加载
评论 #37171366 未加载
评论 #37169483 未加载
rozapalmost 2 years ago
A funny thing is that this can go N layers deep. At a previous job we had a DSL which was very well specified, pretty straight forward, and had been written by an exceptionally brilliant engineer (who was even still at the company!). We had two backend services that would operate on that AST in a query context and in a streaming transformation context, and they shared the parser, compiler, and typechecker. The problem was that the engineering team was so fragmented and lacking in stable technical leadership that a large part of the engineering team had no idea about how these things worked, so on every project they were constantly going &quot;Ooops, I created a feature which has its own intermediate representation with slightly different semantics so reuse is impossible&quot;. It was super hard to deal with and stuff was constantly being invented and then thrown out because it couldn&#x27;t be extended.<p>The only thing worse than creating a compiler is being unaware that one already exists and creating a new one on top of the existing one.
guideamigo_comalmost 2 years ago
At a billion-dollar fintech, some engineer thought gRPC is too complicated. So, he built someything from scratch.<p>A year later, there was a team of 5 engineers maintaining a half-baked implementation of gRPC. Good for him. Bad for the company.
评论 #37170088 未加载
评论 #37170790 未加载
评论 #37168712 未加载
评论 #37174546 未加载
评论 #37167325 未加载
评论 #37174549 未加载
dangalmost 2 years ago
Related:<p><i>Dear sir, you have built a compiler</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=29891428">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=29891428</a> - Jan 2022 (175 comments)
评论 #37167068 未加载
renoxalmost 2 years ago
What&#x27;s strange is that if you had started with a Lisp, it would have been much simpler!<p>And yet few people think about using a Lisp for their DSL.
评论 #37167019 未加载
tombertalmost 2 years ago
It is sort of incredible how often I&#x27;ve ended accidentally re-inventing interpreters or compilers without that being an explicit goal.<p>You start by just adding some kind of configuration for rules, maybe in JSON. Then you start wenting to make more complex rules so you allow some kids of recursive system in your JSON that can nest rules and combine them. Then you find yourself copypasting rules a lot and so you implement some kind of naming convention so you can reuse rules. Then you realize how disgusting your JSON is getting so you dust off a parsing library and make a basic DSL that compiles into that JSON, and then it dawns on you.
评论 #37171196 未加载
RandyRandersonalmost 2 years ago
Creating a configuration file? I am afraid to inform you that you have started writing a compiler. What&#x27;s the only way to avoid this? Your software not being successful.
dessimusalmost 2 years ago
Dammit! Every time I try putting together an Ikea bookshelf, this happens!
vishnuguptaalmost 2 years ago
There was a joke at Uber about beginning with a configuration management system and ending up with a version control system.<p>And somewhere else about accidentally building a real time chat service (or was it email? Don’t recall).
评论 #37167793 未加载
jcarranoalmost 2 years ago
The key is to know, acknowledge and accept where you are going, and to go boldly and deliberately- or not go at all. Say &quot;this problem looks like making a small program so I&#x27;m making a mini-language&quot;. However, if you find yourself saying &quot;&quot;this looks like a database...&quot; then stop there and please do not build a db.
bstpierrealmost 2 years ago
I accidentally built a kind-of compiler last year.<p>It started as a few sed commands to merge TeX+code -&gt; TeX for a book project. I ran these sed commands from a makefile. Life was easy.<p>But then there were complications, and I needed to make slightly more sophisticated substitutions. So the sed commands moved into an awk script, run by the makefile. This was better than maintaining a handful of little commands that were growing on a weekly basis. Life was good.<p>The transformations I needed kept growing a bunch of little variations, and the awk script became hard to maintain, so I rewrote it in go, with proper parsing and output. (And even unit tests, after the 2nd time I broke some output.) Designing it as almost-a-proper-compiler was 10x better than maintaining an ad hoc script. Life was great, even with the overhead of maintaining a separate processing tool.
评论 #37172010 未加载
Detrytusalmost 2 years ago
Totally offtopic but I can&#x27;t help but wonder why this guy has a site with .pl TLD. He seems to be based in the US, not Poland. Does he think &quot;pl&quot; stands for &quot;programming languages&quot;? :)
评论 #37169384 未加载
评论 #37168465 未加载
评论 #37169313 未加载
评论 #37169728 未加载
samsquirealmost 2 years ago
I am especially interested by the characterisation of handling interactions between different AST nodes.<p>I think interactions between features are very hard to think about.<p>I think constructed languages have the opportunity to think about potential interactions that would be useful and aim to support those ones.<p>But there&#x27;s lots of permutations to features.<p>Just look at async functions in Rust and coloured functions. It&#x27;s such as pain.<p>It also reminds me and brings up thoughts about &quot;the expression problem&quot; [0]<p>How do you think which combinations of features would be useful upfront? For example: there&#x27;s interactions between memory management, garbage collection, async, multithreading, coroutines, closures, the stack, FFI. It&#x27;s all very complicated.<p>[0]: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Expression_problem" rel="nofollow noreferrer">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Expression_problem</a>
makachalmost 2 years ago
How embarrassing. I&#x27;ve done this. Programming is easy, making things easy is difficult.
wrsalmost 2 years ago
Other needed topics in this series: “You have built a database”, “You have built an orchestrator”, “You have built an RPC layer”, “You have built a build system”…
评论 #37166436 未加载
评论 #37167272 未加载
评论 #37166416 未加载
评论 #37166552 未加载
评论 #37167071 未加载
alexchantavyalmost 2 years ago
I work on a Python project where I need to take class definitions and generate database query statements because all ORMs that currently exist don’t work for my needs. I&#x27;m currently doing this with string templates that I&#x27;ve defined by hand. Is there a smarter way?<p>I&#x27;ve looked into some compiler-like tools (can&#x27;t remember the specific ones, sorry), and from what I can tell their code generation phase looks very similar to mine in that they use string templates.
评论 #37166567 未加载
评论 #37167811 未加载
eternityforestalmost 2 years ago
... how does this even happen? What bizarre use case doesn&#x27;t allow for just using an off the shelf scripting language?<p>I&#x27;ve only done anything like this once and not regretted it, and it&#x27;s purely visual scripting, if this then that style. Anything that can&#x27;t be handled by an event that triggers a list of actions, then stops when one returns False, I will hardcore a hack just for that feature.<p>Most actions and triggers are responses to specific use cases.
WalterBrightalmost 2 years ago
It just crept up on me.
ameliusalmost 2 years ago
A compiler typically transforms programs that run in O(N) time into programs that run in O(N) time, for whatever suitable definition of N, so it&#x27;s not really something to be super thrilled about.