Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: I'm 17 and wrote a guide on how to build your own programming language (hackclub.com)
149 points by jianmin-chen 3 months ago | hide | past | favorite | 62 comments
Hey! I’m JC. I’m 17 and part of Hack Club, a nonprofit where we help teenagers ship programming projects with their friends while growing technically.

A while ago, I asked myself the question, “How exactly do programming languages work behind the scenes?” It seemed really daunting until I went to a half hour workshop at a high school hackathon about writing a tree-walk interpreter and realized that getting started was actually super fun.

This guide is designed in the vein of that - to get people, especially teenagers, started on learning how to build a programming language in a literal weekend by actually shipping one. It’s a stepping stone for learning the big things - compilers, optimizations for performance, etc. It’s very inspired by Crafting Interpreters and why’s poignant guide, but meant to be approachable in a weekend.

Some backstory on me: A year ago I finished high school early and joined Hack Club full-time to build projects like this. I’ve been programming since COVID, and learned how to code primarily by shipping things that seemed daunting to me and taking inspiration from people taking the time to break down various topics online.

Give it a try and take it out for a spin! Constructive feedback is also really appreciated.

It’s open source on GitHub at https://github.com/hackclub/easel




Congratulations on launching the project!

Making a programming language is a great way to better understand computation and start to explore different means of expressing concepts in code beyond those available in existing languages.

Programming languages are a difficult concept to get one's head around. Having one that implements a lexer, parser, and execution engine -- and is packaged as a resource for others to use -- is an impressive technical feat.

Writing a guide so others can learn is doubly impressive.

Asking a question like "How exactly do programming languages work behind the scenes?" is a great quality to have in your creative pursuits. Not to mention that such questions are the basis of HN: journeys that satisfy our creative curiosities.

Keep making cool things!

---

One piece of feedback: I find the size of the code instruction boxes on the page a bit small. There are no visual indicators that I need to scroll down to see all of the code. I would love for the boxes to be taller so I can read the code and retain all the context without scrolling.

---

Another idea: You may enjoy writing a post about what you learned making the language. What did you find more difficult than you thought? What challenges did you run into? How did you solve them? Why did you choose the syntax you used?

I love reading about the how behind cool projects :D


If I were to pick one book that has had the most impact on how I think about programming languages it would be the textbook Programming Language Pragmatics by Michael Scott.

https://www.goodreads.com/book/show/89197.Programming_Langua...


That's great!

You have excellent inspirations, both of them.

It's also awesome that your adventures with parsers happen quite early in your coding life, that's a big plus, you will look at things from different perspective. (Btw, contrary to some other commenters here, I think it's great you have mentioned your age xD).

Btw, I totally recommend getting into VM-based approach from the second half of Robert Nystrom's book. It's not only closer to how hardware works, but also it resembles how early compilers were written when memory was scarce. I implemented stuff based on that approach and learned a lot, even though I am coding for thirty years. If you had some comments, questions or even already hacked on that, I'd love to hear about it - you can find the email on my profile page here.

Good luck!


Very cool. Someone correct me if I am wrong but I dont think this is accurate.

>Minimally, should have the following features: variables, looping (think: for/while loops), conditional branching (think: if/else statements) and some form of recursion (think: functions). Why? These are what make a programming language Turing-complete.


Either an infinite for/while and if or unbounded recursion are necessary but you don't need both for Turing completeness.

[1]: https://en.wikipedia.org/wiki/Turing_completeness#Examples


My understanding is theyre two sides of the same coin.

Any loop can be written recurisvely or iteratively.

And a loop is really just a move to the same instruction, or equivalently a replication of the same instruction.


Trivially, you can get Turing completeness out of a Turing machine, which does not have these features, so no, it is not accurate to say they're absolutely necessary. There's a practical side to this, though. What sort of syntactic conveniences should you provide such that anyone might actually want to use your language? That's probably what it should say. The mov instruction is Turing complete, but you likely want some higher level of abstraction that allows for things like developer ergonomics, the possibility of type checking, allowing for human readable source code.


On the practical side, I can think of one Turing-complete language people actually use that doesn't have loops or variables: Erlang.


In fact, NAND gates are enough to build a Turing complete machine. ;-)


My favorite turning complete language is Fractran - https://en.wikipedia.org/wiki/FRACTRAN

    17 78 19 23 29 77 95 77  1 11 13 15  1 55
    -- -- -- -- -- -- -- -- -- -- -- -- -- --
    91 85 51 38 33 29 23 19 17 13 11  2  7  1
That computes prime numbers.

Iterate through the list (start with n = 2) and iterate through until the fraction is an integer. Repeat with the new number.

For this, after 2, the next value is 15 (when it gets to 15/2). Then it will be 825 (15 * 55/1). Then it will be 725 (825 * 29 / 33) and so on. At some point, n will be 2^x where the sequence of when the number is just a power of 2 will be: 2^2, 2^3, 2^5, 2^7, 2^11 and so on... the exponents of 2 are the prime sequence.

2, 15, 825, 725, 1925, 2275, 425, 390, 330, 290, 770, 910, 170, 156, 132, 116, 308, 364, 68, 4, 30 ...

https://oeis.org/A007542

https://news.ycombinator.com/item?id=35966537

https://softwareengineering.stackexchange.com/questions/2201...

https://web.archive.org/web/20150923211455/http://www.cs.vu....


How will you do unbound computation with only NAND gates? Either you need a clock (not a NAND gate) or you need to implement a clock using NAND gates, but that assumes physical aspects such as power propagation speed.

Typically you say that you can make arbitrary functions between any two closed domains using only NAND gates.


Turing completeness isn't about having everything you need to build the physical computer, just about expressing program logic that can perform a certain class of unbounded computations. Like, given any C program's logic that takes some input and gives an output, you could calculate the same thing (painfully) with NAND gates.

Anyway, bringing up Turing completeness is overly theoretical when talking about a programming language. It's pretty hard to make a language not Turing-complete, and it doesn't say much about what you can use it for IRL.


> you need to build the physical computer

Exactly.

Now tell me how you will do unbound computation (ie. write on the n+1 cell in the Turing machine) with a fixed number og NAND gates and without a clock.


Oh, I see what you mean. Yeah it seems like you need a clock.


NAND gates are enough to computer any boolean function. Being Turing complete requires some notion of state and state transition.

However, a RAM machine where the program counter is memory mapped, can be Turing complete with a [single machine instruction]( https://en.m.wikipedia.org/wiki/One-instruction_set_computer).


While true, to build a language using NAND gates, the language has to specify how to assemble those gates, which will still require conditionals and loops if you want it to build any machine.


Either conditional looping (like the for loop in C) or recursion is enough for Turing completeness. Practically speaking, conditional looping generally requires mutable variable bindings, but I can imagine a SSA-based language where variables are unnecessary. With recursion, you have no need for mutability as the function call primitive gives you the variable rebinding you need.


This was an awesome read, really amazing job. Most particularly though, I love your style of teaching through storytelling. I was so captivated by the story; it's not just a guide or tutorial, but it adds another layer of mental stickiness. Are you planning to write other guides like this about other programming topics?


Very cool. I especially like the programming language jam, and the fact that the guide pairs with it.


Excellent work. When I was your around your age, it was QuakeC that exposed me to programming concepts and really sparked my interest in programming. If you’re interested you may want a follow up project to create a stack or register based VM.


Valve GoldSrc for me


Really cool - I'm looking forward to reading through this. Since you mention, Crafting Interpreters, how would you compare this guide to that?


This is amazing, love the work JC


very cool


[stub for offtopicness]


Totally unrelated to the content of your post but labeling posts with "I'm [a teenager] and X" has always irked me. It either serves to undermine the content (older people immediately questioning the authority of a teenager) or people respond with meaningless praise ("Wow, great job! I was playing video games when I was your age!"). It also harkens back to the 2000s and 2010s when the industry was obsessed with "teenage savants" for some reason. So much money was wasted by being thrown at teens due to tech's obsession with youth and the errant belief in its ability to drive innovation.

Your post could have been titled "Show HN: I wrote a guide to help teens learn how to build their own programming language." I dunno, maybe I just need my coffee and I'm being grouchy


This comes up every time someone posts like this, and it's not really very helpful.


What are HN's guidlines on young people mentioning their age in a Show HN like this post here? Should we take it graciously, admit they are young and encourage them for what they did or should we point out not to mention their age?

IMO, if we take the age out, some of show HN's might not look very interesting. Same goes for a Show HN where someone mentions they are not a programmer and yet built a thing.


There's no official guideline (we try to keep that list minimal), but I think it's harmless and the main thing commenters should do is not complain about it. These complaints are always the same, always offtopic, and usually balloon in size to the point where the offtopicness drowns everything else. That's a terrible outcome for a thread like this.

Even if you dislike "I'm $X years old and I $Y" posts, it's not helpful to give a kid a grumpy patronizing response. We want HN to be a helpful community, not some weird age competition.


For whether age should be mentioned: Does there need to be a guideline? There are plenty of things that have no specific guideline, things which are fine to do or not do.

For whether there should be comments about age being mentioned: existing guidelines already denounce low value commenting especially at the root level.


I guess the point is that saying you are a teenager in the title can seem like an unfair way to game your post ranking by garnering awe/sympathy.

Lots of middle aged people build cool things too, but they can't pull the age card to boost their rank on the front page (at least, not until they are at the other extreme - like 80 or 90 years old)


Not just that; plenty of teenagers build their stuff without announcing that they're teenagers too.


Is it truly an unfair ranking boost if it's highlighting a substantially rare circumstance? I think many people prefer to discover rare things.


These kinds of feats aren't more or less impressive with age. Maybe the opposite, teens have so much free time.

When I was 17 I was working on a programming language, and I promised myself I would find the time to finish it during college. But during college I didn't have the time.

I have two friends who founded a startup at 16, one of which was quite succesful. I can think of two seperate friends who started a Minecraft hostar at 16, both of which makes up the majority of minecraft servers hosted in the Netherlands currently and one of them is now a generic hostar with his own datacenter.

And this isn't a problem in and on itself, but phrasing it like this discourages older people to work on pet projects. I started working as a Cyber Security TA at a private IT school and older students keep telling me "I'll never be as good as you because I didn't start so young" and it's a harmful mindset. Because it only took me a few years to learn what I know. Stating your age everywhere as a young developer reinforces this mindset in people.

If you want to see a teen/student do cool stuff. I suggest checking Adam McDaniel on GitHub. That dude really is impressive.


Yes, the problem is there are a fresh supply of 17 (or whatever) year olds, who haven't seen the old-man-yelling-at-cloud messages like OPs that are posted when they do this.


I think it guides responses to it. If a teenager writes a guide that says O(n) algorithms are always faster than O(n^2), I'm likely to tell them that I see what their thinking is, but here are some counterexamples that make it more nuanced than that. If a friend with a PhD in compsci said that, I might tease them more... assertively.

In this conversation I see people discussing the requirements for being Turing complete. Because OP is a teen, everyone so far seems pretty nice about gently pointing out inaccuracies. I doubt they would be, or should be, as easy on me if I made similar misstatements.

And that's the value I see in "as a teenager..." here. It's not so much about their age as that they don't have decades of education and experience under their belts. Another person posting "as a professional dog groomer..." might get similar responses: hey, that's pretty neat coming from someone who hasn't been doing this for a living for many years!


Totally agree on every point and I'm not being negative, the thing is that stating the age is something most people wouldn't even think (I like to believe we all still see ourselves as kids in our minds), so if someone puts it there themselves (as opposed to being a news article written by someone else) then they are doing it for marketing purposes.

I did lots of cool stuff "for being made by a 17yo" but in retrospect it was not objectively great.


I don't think there's an issue. Discourse on HN can be daunting for anyone. Sometimes it helps to know there are people your own age doing cool things. It makes it more accessible, which is a good thing.


There’s been a concerning trend of less and less young, successful founders. Where is the modern Zuck, Gates or Patrick Collison?

I say good on OP for putting themselves out there and keep pushing. We need young people to come up with great ideas and if that comes with them pointing out how young they are, I’m totally fine with it.


I think there have been fewer young technology founders because I think technology has become less and less accessible. There is so much more to sift through to get from an idea to a project or product than there was 10-20 years ago.

I'm saying this as someone who is relatively young, so keep that in mind.


For some parts of the landscape like mobile app development, yes. Its hard to say if they are doing it with hidden intention, or if they sincerely believe enforcing their "best practices" on everyone yields greater good. Probably a bit of both.

The part where you build a demo/prototype showcasing if an idea works, I believe it should be much easier than before as long as you postpone understanding/deciphering the implementation. In those major ecosystems there are huge collections of single-purpose libraries doing a subset of what you want to do, all you need might just be a reasonable amount of python to string them together.

However, ensuring the correctness and actually deploying them for planet-scale mandates following a reasonable subset of "best practices" which is very overwhelming, but doable. People doesn't usually build planet-scale product 10-20 years ago.


> However, ensuring the correctness and actually deploying them for planet-scale [...]

I think this is specifically a big part of the problem. Not everything needs to be planet scale to be good. People didn't focus on being planet scale 10 years ago. 20 or so years Mark was worried about getting The Facebook available at one or two schools.

Worrying about getting things working for the world has made it way harder for us to get things working for indoviduals or small groups.


Kids and especially teens seem to do this implicitly whenever they are doing things that they feel is advanced for their age


That's survivor bias.


No it isn't


Of course it is. If a project doesn't state that it was made by a teenager you wouldn't know.

I never stated my age on my projects when I was younger. Neither did any of my developer friends.


The observation was on kids declaring their ages around projects that they feel are advanced for them. It is not survivorship bias and has nothing to do with that term. The term doesn't even apply to your own example anyways


While I want to agree, your comment just sounds salty


Thanks for absorbing the downvotes. Helpful or not, I mostly agree with your reaction. Let the work stand on its own without injecting identity into it.


Andy Rooney, is that you?


Definitely just grouchy.


HN is so full of negative comments like these. OP I’m very impressed you learned all of this at 17! I started coding when I was a teenager but still haven’t released something like this 10 years later.


I don't think you need to lead with your age. It's a cool project and you should be proud of it regardless of your age.


As a 30 something, I completely agree.


Honestly, very cool good for you.

Side note, I'd discourage leaning on your age/precociousness when doing stuff like this. It's a strategy with a limited shelf life, and sooner or later your work will have to stand on its own merit anyway.


Yup, that's a piece of advice I'd give to younger me.


Well done!

Ignore the grumpy haters in this thread and keep going.


This seems like nothing more than an ad for hack club.


[flagged]


The primary reason it should not be listed is that it entirely distracts from the content, as one can see by there being few comments (as of right now) that talk about the contents. Only comments about age.


Then why don't you make it irrelevant in a civilised way by ignoring it...


Ignoring what someone puts on a stage would be uncivil.


smart answer, but I think you know what I meant: ignoring the thing about age and let her enjoy what she wrote more




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: