7 ms·
So you want to design a programming language (2017)
- teddyh 5y agoSee also Growing a Language by Guy L. Steele Jr. in 1998: https://www.youtube.com/watch?v=lw6TaiXzHAE https://www.youtube.com/watch?v=lw6TaiXzHAE http://www.cs.virginia.edu/~evans/cs655/readings/steele.pdf http://www.cs.virginia.edu/~evans/cs655/readings/steele.pdf
- open-source-ux 5y agoOne of the sections in the article is headed "study existing languages", but why not also study languages that shaped programming language history? No mention of the Pascal-family of languages (Pascal, Modula-2, Oberon), no mention of Ada. Even Algol 68 is full of ideas that would reward study. Also, the language descriptions are too brief to be helpful (Java and C# for being enterprisey, C++ and Rust for pointers and other system constructs)
- jonsen 5y agoThe wiki page is rather informative in the sense of choosing which historical languages may be worth a closer look: https://en.m.wikipedia.org/wiki/History_of_programming_languages https://en.m.wikipedia.org/wiki/History_of_programming_langu...
- ModernMech 5y agoI think it's even more important to study history of PLs if you want to make a new one. The history of programming languages was shaped heavily by Moore's law, and the fact that if you waited 18 months, your previous slow program would likely be twice as fast on newer chips. The result was that programming languages rose to the top by riding this exponential wave through mechanical sympathy. Today, however, Moore's law has stalled, and a different kind of power law is on the rise: core counts. Languages which previously saw success by being imperative and optimized for single core execution are falling over trying to keep up. We see increased efforts to harness the power of multiprocessing through asynchrony and parallelism being first-class citizens in newer languages, while others struggle to stay relevant. Languages of the future will be built from the ground up to harness massive CPU core counts that will be available on consumer desktop machines in the near future. My advice to any budding language designer is stop looking to reinvent C and C++. There's currently a wave of programming languages that came of age circa 2010 - 2020 which are focused on just that (Go/Rust/Zig etc.), but if you're just looking to get into that space now you're late to the party. Instead look back to Erlang and the original promise of Object Oriented programming as the basis for a new language in 2022.
- 6gvONxR4sf7o 5y agoI expect an extreme version of this to be the future. Not just many cores, but many machines. My ETLs at work run on a spark cluster and are specified across programs organized in a separate DAG. That’s the kind of “program” with lots of head room to improve. I’d bet future many-machine heterogeneous-resource languages will make that a lot easier.
- OkayPhysicist 5y agoErlang and Elixir are already pretty strong in this regard.
- 6gvONxR4sf7o 5y agoAny ideas why the strengths of erlang and elixir haven’t made their way into the mainstream?
- ModernMech 5y agoI would say that the strengths of Erlang have made their way into the mainstream, but into infrastructure and tooling rather than languages. I believe the reason for that is because the current crop of popular mainstream languages will never forsake their imperative roots. Erlang's true strength is that it approaches the distributed computing problem from first principles, which yields a language that feels right to work with in that domain; whereas the mainstream attempts to shoehorn distributed computing onto an imperative foundation, which has always been very awkward since it's really just trying to square a circle.
- tomcam 5y agoYeah that list is glib. To include Brainfuck but not Pascal is telling.
- goodpoint 5y ago...and no mention of Nim, which shares a lot with Pascal, Python, C and Ada and is more innovative.
- OkayPhysicist 5y agoThe context of this page is that it's part of a university course, a per-requisite for which would have been already studying a lot of older languages. The examples listed there are a survey of modern languages, trying to hit as many paradigms/language design choices as possible.
- J253 5y agoThis is a great resource for pointing out the things you need to think about in designing a language. To see the nitty gritty line-by-line walkthrough of everything that goes into actually building a language (all the way down to writing your own VM) I HIGHLY recommend reading Crafting Interpreters[1] by Bob Nystrom. I’m not a language hacker but found everything about this book worthwhile and very interesting. [1] https://craftinginterpreters.com/ https://craftinginterpreters.com/
- lioeters 5y agoI'd also recommend Writing An Interpreter In Go [1] by Thorsten Ball, and its companion, Writing A Compiler In Go. [1] https://interpreterbook.com/ https://interpreterbook.com/
- Decabytes 5y agoIf you want to design a programming language, and are okay with building off of an existing language, I suggest giving Racket a try. It can do more than just create DSLs and compile down to Racket code. I recently learned about sham* which allows interfacing with LLVM. I've linked some examples and references below References 1. https://docs.racket-lang.org/guide/languages.html https://docs.racket-lang.org/guide/languages.html 2. https://docs.racket-lang.org/turnstile/ https://docs.racket-lang.org/turnstile/ Examples 1. https://github.com/soegaard/urlang https://github.com/soegaard/urlang 2. https://github.com/rjnw/sham https://github.com/rjnw/sham 3. https://github.com/ShawSumma/lure https://github.com/ShawSumma/lure 4. https://github.com/racket/rhombus-prototype https://github.com/racket/rhombus-prototype 5. https://github.com/lexi-lambda/hackett https://github.com/lexi-lambda/hackett
- hardwaregeek 5y agoOr do none of that. I understand that this article is meant to encourage people to learn some cool stuff within programming languages, but it’s also discouraging. The better answer in my view is to learn how to build a tree walking interpreter with Crafting Interpreters, then build whatever comes to mind. Want functional programming? Add immutability and first class functions. How about concurrency? Add an event queue. Then try to make a bytecode interpreter or a compiler. Sure these ideas require some of the knowledge detailed in the article, but you can learn that info JIT. Don’t try to learn it all before you get started. Just start and see what happens.
- OkayPhysicist 5y agoIt's a page from Loyola Marymount University's Compilers course, which involves building a compiler for a language of your own design. This is basically a syllabus for a course that has a lot more detail at each stage.
- brokencode 5y agoThere’s a difference between building a toy language and designing something people would actually use. I think the article is more aimed at the latter, whereas if you just want to get something working and have fun, your approach makes more sense.
- hardwaregeek 5y agoYeah you’re right. I guess I’m saying that you gotta build a few toy languages before the big one. I don’t think you can read all of the material in the blog, then go build a language that people would actually use. Ideally you should concurrently read the material, work on a toy language, and work on an existing language.
- lolinder 5y agoI think most people who are interested in programming languages would do well to start by making toy languages. There's a lot of pressure in trying to make something "useful", and you're almost certainly not going to succeed at that on your first attempt anyway. The list of prerequisites in the article is extensive, overwhelming, and largely unnecessary if you're just getting started. Most of the concepts that it lists as "prerequisites" are ones that I finally understood while implementing a toy language, not stuff that I studied ahead of time.
- agumonkey 5y agoMore than a programming language, what about new paradigms :)
- deweywsu 5y ago
- alcover 5y agoTo those having created languages, should I target LLVM or is transpiling to C a viable way (like I intend to) ? Transpilers to C seem rare, maybe for a reason..
- sealeck 5y agoTranspiling to C is certainly possible but the infrastructure for things (e.g. DWARF data for debugging) is much better when using LLVM IR directly. IIRC some operations are more pleasant (as in LLVM's definitions are more consistent/have fewer gotchas). That said C transpilation is certainly a viable root (e.g. Idris does this)
- von_lohengramm 5y agoOne of the bigger problems of transpiling to C is inheriting its oddities, such as the definition of overflow (or lack thereof) depending on the signedness of integers, etc., etc. Personally, I'd argue that transpiling to C combines most of the downsides of a new language with most of the downsides of C. I will admit, though, that the zero-effort FFI support of the approach is quite enticing.
- fsckboy 5y agoyou can use C to create any system you want including your preferred overflow, signedness, etc. Yes, it's that powerful. Then transpile to what you've created... which would still be transpiling to C. C lives outside the box, try to think that way.
- alcover 5y agoYes, that's how I see it. C can do anything - albeit ardously - and in the process of writing that transpiler to C in C I hope to make a huge leap in my understanding of C's model and of constructs in general.
- von_lohengramm 5y agoWithout compiler extensions galore, no C is not that powerful. Until C11, you couldn't even control alignment without hacky union workarounds that weren't great. You simply can't model exotic integer types in C like you can in LLVM IR. You can't disable struct padding without a GNU extension. The variance and portability of libc is pretty annoying too; you'd be surprised how many GNUisms you thought were in the spec. But worst of all, C's integer behavior is extremely unintuitive and basically force you to use case every operand and every binOp result to ensure desired behavior in all cases. You totally could transpile to C, but you'll basically have to master the C spec & its edge cases, write everything out in single-static-assignment form with explicit casts everywhere, avoid most of libc, use at least C11, accept some shortcomings, and avoid using most C language constructs and basically write assembly in C. Either do all that, or you'll inherit some of the quirks and shortcomings of C (and have your C compiler misinterpret your code). And even then, it probably won't optimize that well. Please, just output LLVM IR or something.
- whartung 5y agoWe did a programming language for a project. It was a clinical rules language. The distinguishing features of it were the data model (it had first class access to the temporal data model we had on the back end), and that we kept the tri-state model of SQL with values and NULL. Other than that it didn't have any real structured types, and just few high level actions. It was a straightforward project, ALGOL-esque, basic control structures. It compiled to Java source code, and the resulting classes loaded in to the app server. We used a "compiler compiler" tool, rather than doing it ourselves. It gave us an AST that we then walked. First time doing anything like that, especially with a tool like that. Especially in an ALGOL like language, getting the expressions to work is the "hard" part. That's where your "napkin to white board to syntax file" falls apart with reduce errors and what not. But when you get it to work, it's magic. When you get "a = a + 1" to work, and know that where 1 line of code works, 10000 lines of code will work, it's an amazing feeling. You just build the things a piece at a time, testing all the way. In the end, we had an unresolved precedence issue (as I recall), but we never bothered to fix. The funniest unexpected outcome was the classic SQL model of using NULL. Simply, 1 + NULL = NULL, and we expanded that to all expressions. It kind of fell apart in something like: IF A = 1 AND B = 2 OR C > 3 THEN... If any of those variable (A, B, C) was NULL, the entire expression evaluated to NULL, which was false. It took me by surprise when it happened, but, "duh", of course. I simply changed the NULL rule to no apply to boolean operators. Instead of evaluating to NULL, I had them all evaluate to FALSE, and that fixed that. Looking at Wirths work (Pascal, Oberon, etc.), you'll see that compilers can be simple. They're work, but they're simple work. We obviously make them more and more sophisticated all the time, but your compilers don't need to be that way to be effective, productive, and useful. We created thousands of lines of code using that language, it solved the problem very nicely that it was supposed to do. Runtimes can be hard, but that's a separate problem.
- Findecanor 5y ago> The funniest unexpected outcome was the classic SQL model of using NULL. Simply, 1 + NULL = NULL, and we expanded that to all expressions. > It kind of fell apart in something like: IF A = 1 AND B = 2 OR C > 3 THEN... That is similar to how NaN values are propagated in IEEE 754 floating point standard. However, a comparison with a NaN would cause an exception (in CPU or programming language, unless you're using a language such as C where FP exceptions are disabled by default). And then there are several min and max operators that don't cause an exception on every NaN but which have different preferences for propagating NaN or values. The distinction is that a comparison affects control flow whereas min/max are still considered data flow.
- zabzonk 5y agoSuprised that the article doesn't mention Forth, which is probably one of the easiest languages to implement, and one of the easiest to extend.
- wglb 5y agoI think a useful article in this vein would be building useful DSLs for real world applications.
- wirthjason 5y ago+1 I think this is a much more valuable exercise and much harder because it require knowledge of the domain.
- deleted 5y ago[deleted]
- lokedhs 5y agoThis article addresses the technical aspects of writing a programming language. However, regardless of the approach you take, it can easily consumer you since there is no no true target to reach. I wrote about that recently. https://write.as/loke/dont-write-a-programming-language https://write.as/loke/dont-write-a-programming-language
- jazzyjackson 5y agoAs someone 2 years deep into implementing a language, I enjoyed your article A minor typo spotted: > it is impossible [not] to keep thinking about ways to improve your project. Indeed the most productive days are those when I decide a major feature is unnecessary
- calrain 5y agoThis seems to be written by someone who is bragging about their technical capabilities, not someone interested in invention, discovery, inspiration, and trial and error. There is a time for 'the right' approach, and there is a time for crazy innovations that can take something to the next level.
- tobiasSoftware 5y agoI can confirm, I'm building a language with all sorts of crazy innovations and did not take the approach that this article does. However, now that I'm 80-90% of the way to v1 with my syntax and features finalized, I'm actually starting to go back through and clean up the code in ways that formalizes it a bit more.
- WalterBright 5y agoI wrote the equivalent article 8 years ago: https://www.digitalmars.com/articles/b89.html https://www.digitalmars.com/articles/b89.html
- throwaway17_17 5y agoAnd a rebuttal argument (or really just an article that takes a very different stance) written in response to Dr. Bright’s article from parent, that while I don’t necessarily agree with, I thought brought out some very interesting food for thought. https://medium.com/hackernoon/considerations-for-programming-language-design-a-rebuttal-5fb7ef2fd4ba https://medium.com/hackernoon/considerations-for-programming...
- WalterBright 5y agoI'm flattered you addressed me as Dr, but I only have a BS degree and am not entitled to be called Dr. But you may call me Ruler of the Universe if you prefer. Thanks for pointing out the riposte, I did not know it existed. Amusingly, C++ has adopted a number of D's innovations!
- stavros 5y agoErr, I'm sorry, but why are you entitled to be called Ruler of the Universe? I have seen photos of you and there are no equidistant markings anywhere on you.
- EdwardDiego 5y agoStudy Java and C# to be "enterprisey"... What's their definition of "enterprisey"? It feels somewhat like an implied perjorative. Maybe this could be rephrased as "study Java/C# to understand why many businesses choose these languages to build things that make them money"?
- xigoi 5y agoI take “enterprisey” to mean “optimizing for adoption by businesses, rather than for other qualities”.
- anamax 5y agoThis a lot of discussion about how to design a programming language without a mention of why you're designing a programming language. I mention why because different whys have different orderings of hows. (For example, if you're interested in some new semantics, working on a parser first is probably counter-productive.)