
There's never been an easier time to write your own language (2016) - lowmemcpu
https://joshsharp.com.au/blog/never-been-an-easier-time-to-write-a-language.html
======
_hardwaregeek
This article is bugging me for some reason. I don't disagree with it. It's
certainly easier to make a language now, even more so than in 2016 when this
article was published. But it feels like saying "it's easier to make a bridge
than ever". That statement isn't wrong. I'd much rather make a bridge with
modern technology. But it's still a damn hard task.

And citing parsing isn't a great example. Parser generators have been around
for ages. And they're usually not the hard part anyways. Defining a simple
grammar and parsing it, even manually, isn't that terrible of a task. Getting
decent error messages and figuring out recovery? That's trickier.

Code generation has certainly gotten easier. But you still need to go through
the process of figuring out how to lower your abstractions. My language is
still extremely basic but I've still had to map my high level types and
control structures down to WebAssembly. LLVM won't do that for you.

There's also more that your average user expects if you want a language that
people use. Decent tooling is important, so a language server and some syntax
highlighting packages in different editors. Good error messages. Decent type
inference. Most of these you can eschew in the first few iterations of your
language but eventually you'll need them.

I feel bad criticizing this post because writing a language has been one of
the most instructive experiences I've had. I've learned so much about code
generation, typechecking, the WASM spec, etc. But it's still a lot of tough
work to get to something people can use. I'm not sure parser generators and
LLVM make it that much easier.

~~~
estebank
A compiler is an error reporting tool with a code generation side-gig.

~~~
chrisseaton
I'm not sure that's true in reality - the code generation is what you ship in
practice. You can't skip on that feature.

~~~
estebank
I am being flippant, but what the user of the compiler uses it for the vast
majority of the time is to get feedback on whether they've missed something.
The vast majority of the code in the Rust compiler is dedicated to error
reporting. Efficiency of the generated code is important, but it is a well
explored space. Emitting good diagnostics is _hard_ and unless you make it a
priority it will always be subpar. Communicating with the user to help them
get to that generated binary is _at least_ as important, and in my eyes it is
_more_ important.

I also consider parsing and syntax to be the _least_ interesting part of any
language, as it is also a solved problem that requires little effort (modulo
malformed code recovery) in both design and implementation when put in
contrast with the rest of the compiler's functions and language design space.

------
vincent-manis
I'm all for writing one's own language. However, anyone who does this should
be sentenced to writing a significant program in this language afterwards.
Only then can they discover how wonderful or (more likely) horrible their
creation actually is. Writing Towers of Hanoi in it doesn't count.

Also, if this language isn't just going to be a toy, they need to write some
sort of specification document about it. I'm tired of seeing new language
websites announcing version 0.9 of the new language, accompanied by a
statement that “we haven't yet written a language manual, but here are some
example programs and some obsolete papers about prior versions”.

I used to work in a senior position at a multinational firm. At one point, I
went to the site of a company that had been recently purchased by my
employers. Their major product was a large online system that was
substantially written in a custom language. At that point, since the
principals in the original company had left, there was not one employee left
who understood this language completely.

------
poidos
+1 for LLVM. It's hard to grok at first, but the Kaleidoscope ([0]) tutorial
lets you hit the ground running. After that, it's very rewarding to learn
LLVM's API by googling, poking around their excellent source code, and having
clang emit IR for you (`clang -S -emit-llvm -O0 test.c`)

[0]:
[https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/index...](https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/index.html)

------
efnx
The article takes the approach of gluing together disparate solutions to write
a language. With a functional language as your base, writing a new language
can be quite elegant and fun! A great series by Stephen Diehl
[http://dev.stephendiehl.com/fun/](http://dev.stephendiehl.com/fun/) covers
the subject in good detail and the fvg Lang
[https://github.com/Lemmih/fvg](https://github.com/Lemmih/fvg) is a nice
reference.

~~~
chrisseaton
> The article takes the approach of gluing together disparate solutions to
> write a language.

But so does Diehl! It's no different!

He pulls together a 'disparate' parser library (actually he implements it
himself, but it's a copy of an existing library) and he mentions using
literally exactly the same backend (LLVM)!

What do you think the difference is that using a functional language makes?

It looks like exactly the same process to me.

~~~
a1369209993
To be fair, they didn't say that using a functional language made it
_different_ from gluing together disparate solutions, just that it made it
_elegant_ and _fun_. Though admittedly, even that is at best subjective.

------
Someone
I am not sure I agree with the claim. What’s really easier with the proposed
approach (using a python port of lex and yacc and generating LLVM) than using
yacc and lex (with all their warts) to generate C code for your own language
was in 1980?

Yes, if your language doesn’t fit C, your implementation could be more
efficient (potentially a lot), but getting there isn’t easier.

I think we got a lot of complexity and options since then that distract from
“writing your own language”.

I think a claim that we can do better than lex and yacc nowadays (e.g. using
Haskell) would be a much stronger argument for “it’s much easier now”

------
100-xyz
Our platform lets users create animations in minutes. We use natural language
in our scripts.

Eg. Cowboy say "Hi there." Wait for 2 seconds. Cowboy run to Point P2 in 3
seconds.

It has been an eye opening and learning exercise. The advantage is even first
time users can start using our language. Disadvantage natural language has
such a wide variety of usage styles that it's a challenge.

[https://toonclip.com](https://toonclip.com)

~~~
hassancf
Off-topic: do you think this could be used to learn coding (by an 8-year old)?
Especially a kid who easily gets bored with things like Scratch (MIT). Thanks
in advance.

~~~
100-xyz
Yes. I am using it to teach small children the basics of coding. It helps them
understand simple abstractions

------
unnouinceput
It was always easy to write your own language. Hard was making that language
be a mature one with plenty of libraries for mundane tasks covering all needs
people want. And harder was to make said language to be adopted and become
mainstream.

------
xpe
Another option that may be useful: transform a custom syntax to an existing
language.

And while you are at it, why not try to write a parser to reverse the process?
:)

------
codr7
Use the Forth, Luke!

[https://github.com/codr7/gfoo](https://github.com/codr7/gfoo)

------
coding123
Don't forget IDE support (syntax highlighting and completion), debugging
support, and last but not least marketing.

~~~
xpe
Marketing may or may not be in scope, depending on one's goals with a
language. Some might use it for internal projects and not see a need for
external uptake. Others might eventually want more attention but may prefer
more organic (word of mouth) growth.

------
tmin
But why would you do that?

~~~
throw_m239339
Because every programmer should at least once. Writing a compiler/interpreter
is the ultimate exercise for any CS student/professional. that and maybe a
file system/database or toy OS or server, because it encompass most aspects of
CS.

Anybody that can do this things can probably take on any programming job,
because they require a fundamental understanding of how computers and programs
work.

Furthermore, It also help when suggesting realistic features to other language
developers, or write proposals, or assess languages themselves.

~~~
xchip
Nah this is not really essential.

------
b20000
like we don't have enough programming languages already?

------
xchip
Please don't

------
sys_64738
This applied to languages.

[https://xkcd.com/927/](https://xkcd.com/927/)

~~~
TuringTest
Creating a programming language is nothing like building a new standard to
replace all the others.

If anything, it's like writing a new novel. Why would anyone do that, when
there are so many already written?

~~~
jodrellblank
Can you answer that question? There are more novels than a person can read in
a lifetime.

More crime novels alone than a person can read in a lifetime.

Must be approaching that for any given category or niche soon, if not already.

Are they named “novels” because they are novel? If so a novel experience is a
distance from where you currently are, and can plausibly be had backwards in
time by reading an old book as well as forwards in time reading a new book, or
sideways reading a new genre.

~~~
TuringTest
New novels are not written because the writer thinks people have the need to
read that particular story, but because the writer has the need to tell that
particular story.

------
Vaslo
We don’t need yet more languages - it’s like the fall of the Tower of Babel
now.

