27 ms·
Do you have a problem? Write a compiler
- smacktoward 7y agoNow you have two problems! :-D
- quickthrower2 7y agoOnly if you use regex in the lexer.
- guramarx11 7y agoI guess now you have 3 problems
- kccqzy 7y ago> Implementing small (domain specific) languages is fun. This, from the conclusion, is something I totally agree. However fun isn't all there is to production systems. Writing so many little languages just make the program overall more complicated with increased cognitive burdens. Writing new languages must generally be carefully weighed against the alternative of picking one single language with good abstraction power for almost everything.
- deleted 7y ago[deleted]
- maaaats 7y agoSome languages have constructs that make it possible to make pseudo-DSLs in them. For instance function with receivers in Kotlin. That's a nice tradeoff I think.
- chrisseaton 7y agoOften called internal DSLs.
- bigwavedave 7y agoI once took over a project from an engineer who'd been let go, and after I saw the mess of a DSL he'd made and used in 100% of his contributions to the project I understood why. We called it our infernal DSL.
- goatinaboat 7y agoFortunately, in the near future, all programming will be done in YAML. Apart from OPA obviously. /s
- TeMPOraL 7y agoC++ or JavaScript is a "language", but so is the API to that library you're currently using in your project. Different ends of the language spectrum. The article is about Clojure, a Lisp, and Lisps are good at giving you access to the entire spectrum. When you hear a Lisper talking about "writing a language", half of the time it's just couple dozen lines of code defining a macro that makes some code much more readable and expressive. Then there are times when "a language" is an extensible pattern-matching engine or otherwise half of Prolog, but those cases are usually handled by someone who has a real need for it and later publishes it as a library - and you're only happy you can now use half of Prolog without actually adding a Prolog to your codebase, with all the devops headaches this would create.
- kccqzy 7y agoThat's what I meant by "language with good abstraction power." Lisps with macros, or Haskell with its incredibly flexible do-notation are examples of languages that allow you to reuse the host language parser and compiler. It takes a lot of fun out of actually developing a language, but nevertheless more practical.
- dehrmann 7y agoAlternatively, use blockchain.
- oneepic 7y agoThis, or perhaps MechanicalTurk.
- nullc 7y ago> Alternatively, use blockchain. Hows that work? Step 1. Raise 4 billion dollars in an unlawful ICO. Step 2. Pay 24 million (0.6%) in a settlement with the SEC that admits your actions were unlawful but absolves you of any further issues. Step 3. Use the remaining 3.998 billion to pay someone to write a compiler for you instead of writing it yourself?
- deleted 7y ago[deleted]
- rob74 7y agoWant to hammer a nail into a wall? Build a robot to do it! If you have lots of spare time, of course...
- taneq 7y agoI've actually come to the conclusion over the years that automation is a form of optimisation, and that all of the rules of optimisation apply in full force. Do you need to process a list of 10,000 things, once a day, forever? Then you do need to automate. Do you need to process a list of 100 things, once? Just roll up your sleeves and start typing (or get someone else to do it). The chances that you could come up with something remotely reusable in less than the two minutes it'd take to do manually are slim to none, yet I have often seen people spend a couple of hours coding up a script to do a 15 minute non-recurring job.
- ahmedalsudani 7y agoMacros, regex, awk are the tools to quickly automate text processing. It literally takes less than two minutes in most cases once you’re proficient.
- taneq 7y agoOh sure, if it's absolutely trivial then bash it (hah) through some shell scripts or even just do it on the command line. I'm talking more about things that are slightly more complicated and will need a bit more effort than find & replace.
- fastball 7y agoHonestly the amount of time I've saved just by throwing stuff into a text editor with multi-cursor support is kinda unbelievable.
- sinstein 7y agoStep 1 - Let me try using command line magic to transform this data Step 2 - ?? Step 3 - Create a scratch file in IDEA and some cursor + regex magic and I am done!
- mehrdadn 7y agoI'm reminded of: https://steve-yegge.blogspot.com/2007/06/rich-programmer-food.html https://steve-yegge.blogspot.com/2007/06/rich-programmer-foo...
- john-radio 7y agoHoly fuck this is hilarious.
- jimbokun 7y agoMade me exhale out my nose: "Whenever I gave even a moment's thought to whether I needed to learn compilers, I'd think: I would need to know how compilers work in one of two scenarios. The first scenario is that I go work at Microsoft and somehow wind up in the Visual C++ group. Then I'd need to know how compilers work. The second scenario is that the urge suddenly comes upon me to grow a long beard and stop showering and make a pilgrimage to MIT where I beg Richard Stallman to let me live in a cot in some hallway and work on GCC with him like some sort of Jesuit vagabond." "Both scenarios seemed pretty unlikely to me at the time, although if push came to shove, a cot and beard didn't seem all that bad compared to working at Microsoft."
- otabdeveloper4 7y ago> Write a compiler Then you have two problems?
- gpvos 7y agoYes, that quote is also the first thing I thought of.
- chrisaycock 7y agoYears ago I was at a trading firm where I needed to write a test suite for our order entry system (the software that sends orders to a stock exchange). Tests could become quite large because I had to track the sequence of acknowledgments and executions from the test exchange. The tests would have been a real pain to write in C++, so I created my own language! It was inspired by both Expect and Cucumber. https://en.wikipedia.org/wiki/Expect https://en.wikipedia.org/wiki/Expect https://cucumber.io/docs https://cucumber.io/docs That allowed me to write a simple script of expected behavior, like: test "Cross own order" -> new buy IBM 100 $141.01 1 <- ack 1 -> new sell IBM 200 $141.00 2 <- ack 2 <- trade 1 100 $141.01 <- trade 2 100 $141.01 My interpreter would run the above script against the exchange's UAT environment. The tests could get pretty sophisticated. I could investigate swanky exchange-specific order types by verifying queue position, liquidity flags, etc. By writing these test scripts, I could verify (1) that my order entry code was correct and (2) that I actually understood what the exchanges were doing with my orders. These test scripts had another added benefit in that traders now had executable documentation. So whenever a hypothetical scenario came up, I could write a script to verify that our assumptions were correct and then email the script's code as a precise set of steps that the exchange was taking. I ended up writing the whole language in Boost.Spirit, which admittedly was a beast. But I still believe that creating a testing language was the right thing to do.
- random314 7y agoI am curious. Was there any particular feature that your language had, which was lacking in C++, that helped in simplifying the test script?
- PaulRobinson 7y agoNot OP, but looking at his example, conciseness. DSLs are feared by many, but actually when you're doing the same thing over and over again and it's hugely verbose, they're great!
- ratww 7y agoAlso not OP but: Having a limited language that looks more like data than code provides great opportunities to analyze it in ways that you can't analyze Turing-complete languages (halting problem and all). An example: A friend works for a game translation studio and one of their games has a tool that read the game scripts and is able to detect missing/unused external resources, overlapping dialogue, unmatched mouth animation/voiceovers, etc... without even running the game.
- rosybox 7y ago> JavaScript numbers are a mess. Next a bit of arithmetics. They aren't a mess. Every programming platform has limits on number sizes. In JavaScript numbers are floating point values, but you can get a guarantee of integer precision within the scope of Number.MAX_SAFE_INTEGER and Number.isSafeInteger. Is that a mess? I'm not one to defend JavaScript, it has lots of problems, but in this case the behavior works as defined in the specification and is predictable.
- axaxs 7y agoDo you not find the fact the JavaScript has no concept of integers and treats everything as floating point, as a valid point to it being a mess with numbers? Sure, you can make it work. But I think it's a fair criticism when compared to just about any other language.
- jgtrosh 7y agoConversely, do you find that this criticism applies to Lua?
- deleted 7y ago[deleted]
- OskarS 7y agoAs a person who spends his days writing Lua, it absolutely applies.
- axaxs 7y agoAbsolutely. I don't particularly like either language much as a self admitted language snob, but I have to realize their successes and try to remain rather objective in my statements. Subjectively, I think that python does numbers best for a scripting language.
- samatman 7y agoI would say ever so slightly less. Lua has the identical problem to JS, in that you get 53 bits of precision (now 64 with Lua >= 5.3). However, Lua has operator overloading, so it's practical to import an infinite-precision integer library, define the operators, and then use ordinary arithmetic from there, with correct results. I would prefer a proper built-in numeric tower, but I'm in the minority there; Lua is a minimalist language and generally doesn't add things to the core which can be written as extensions.
- endymi0n 7y ago"Imagine you are writing a cool new rogue-like game. So cool many have no idea what's going on." ...and then you nerd snipe yourself by writing a compiler in order to ensure the fair randomness none of your end users perceived to be off in the first place. The game still isn‘t fun.
- klyrs 7y ago> The game still isn‘t fun. Joke is on you; writing it was the fun part. Roguelikes are meant to be hard. Fun really isn't the point
- uka 7y agoI had a problem I wrote a compiler Now I have 2 problems at line 33 and 67.
- TeMPOraL 7y agoTo people saying that writing a compiler is almost always an overkill - that's because you and author mean different things by the word "compiler". Or, in other words, that's because your intuition is based on the inflexible languages you're working with. It's not an accident that the talk/article is about Clojure[0]. A Lisp. In Lisp, "writing a compiler" is a fancier way of saying "writing a possibly code-walking macro", which is still just a fancy way of saying "writing a function that transforms a tree into another tree, and having it run compile-time on parsed program source as the input". 99% of the usual compiler work - tokenizing, building an AST, generating machine/bytecode, optimizing - is handled for you by the host Lisp compiler. All the mechanics are there, and all you have to do is to add the brains you need. -- [0] - Clojure itself actually makes this slightly more difficult than it looks, because of the decisions it made that makes the syntax slightly less obviously homoiconic.
- invalidOrTaken 7y ago+1 to this. I did this literally last week for a toy project and it was hilarious to be reminded of how easy it was. I know I'm just rehashing the above comment, but: if your target language is complicated, and your host language is complicated, sure, it can be a pain. If they're both lisps, you can almost do it in your sleep.
- LandR 7y agoThere is a joke in Lisp / Lisp dialects that they don't write their code in Lisp, they write the language they want to write their code in in Lisp. Then solve the problem in that language. It's often not true, but writing DSLs in a Lisp is technically much simpler than other languages I reckon, if your problem domain actually requires such a thing.
- stevekemp 7y agoLisp is not alone in that regard, to be honest I suspect it is even more true in FORTH. In FORTH you define words, which you then write your program in. These words very quickly become problem/domain-specific.
- deleted 7y ago[deleted]
- WalterBright 7y agoI had a problem with Telecom C back in 1982, so I decided to write a C compiler. Still working on it.
- galfarragem 7y agoWhile reading this blog post I feel that my programming knowledge is an order of magnitude below. It's a bit depressing.
- Dude2029 7y agoFun to implement, sucky to maintain! Like event-sourcing.
- pyrale 7y agoWhy would event sourcing be sucky to maintain? My last job was to build a system to replace something that used to require lots of maintenance. Event sourcing made most of this maintenance trivial, and the remaining cases were made easier to explain and handle. Event sourcing things doesn't mean you need to use a complex frp framework, a simple pg table and a state machine in your language of choice is usually enough.
- Dude2029 7y agoIn this case the maintainer is the builder, that is always comfortable.
- pyrale 7y agoI have recently moved to another team, so we shall see. However, we also administered two crud dbs, one we inherited and another recent one. The three dbs were doing pretty much the same thing. Understanding and maintaining what happened in the crud db we built was significantly harder than understanding and maintaining the event-sourced one.
- jhayward 7y ago> Fun to implement, sucky to maintain! Like event-sourcing. This comment begs for a blog post or some links that illuminate what you mean.
- janczer 7y agoHere the link to video: https://youtu.be/kOXfdZRD0wM https://youtu.be/kOXfdZRD0wM
- codr7 7y agoWriting compilers for languages that look like Lisp in Lisp is so effortless that most don't bother to go further. I feel that's often a missed opportunity. Hook in a parser [0] and the sky is the limit. [0] https://github.com/codr7/lila https://github.com/codr7/lila
- GaurVimen 7y agoI had a problem I wrote a compiler Now I have 2 problems
- VBprogrammer 7y agoI was half expecting the punch line to be "now you have 2 problems!".
- WesternStar 7y agoI feel like this and the motivation for golang are vaguely similar. Hear me out. The intention of golang in its language is to make complex things hard to do and make it easy to understand the language in any piece of code because there isn't much syntax. But sometimes you want to code more expressively and having some nice syntax would be nice. Its not a big deal if its local and limited to what this exact problem is. That's tough to get from a general purpose language.
- jimbokun 7y agoI thought the intention of golang was to avoid C++'s super slow compile times.
- Beltiras 7y agoNow you have 2 problems.
- asdf333 7y agoDo you have a problem? write a compiler....and now you have two problems!
- imihai1988 7y ago"When inlining is a valid rewrite?" "When constant folding is a valid rewrite?" Are these valid questions ? structurally speaking ... they seem somehow off, a lot off. I'm asking because I'm way more bothered by them than I should be.
- mbrodersen 7y agoThe article really should have been called: "Do you have a problem? Write a DSL". I use DSL's (Domain Specific Languages) or "Little Langues" all the time to be much more productive in C++/Java/C#/...