Show HN: I'm 12, learning JS, and wrote Wolfram's cellular automaton in Node

8 years ago (bitbucket.org)

Liam, this is incredible!

I thought it might be useful for you to incrementally see how someone in industry would review or change this code, so here's a little code review via video: https://youtu.be/UkVOrcS--04

We very incrementally build up to the final code, which can be found here: https://gist.github.com/stevekrenzel/b490564bf1c7f98e232a6c8...

Hope you find it helpful!

  • Thanks Steve!

    I watched your video and although I don't understand everything, I learned a lot. Separating my program into functions is a good idea. Your video clarified the map function for me.

    Through your video, I understood that I was running code multiple times, when it only needs to run once (how I parsed my rules was one of these instances that you went over in your video), so thanks for pointing that out.

    Again, thank you so much for taking the time to review my code. I really enjoyed your feedback.

    • > Again, thank you so much for taking the time to review my code. I really enjoyed your feedback.

      Whatever you do, hold on to that. Never be mad about feedback just try your best to understand it, and if it's wrong explain yourself without getting frustrated, this is worth more than a dozen senior developers who explode at feedback (I would argue they're junior developers :) and you will have a wonderful career. Also look for good mentors, and don't be afraid to ask questions about direct feedback, if you didn't understand something he said just ask (this becomes an immediate learning opportunity and you will be better off for it), even if he doesn't get to answer, someone else might. This is a field where learning is endless, you will always learn something new as a software developer, new platforms are made all the time to be programmed on / with.

      Having soft skills[0] will be the biggest asset you can have as a software developer, whether you do it for money or just for fun, if you have to collaborate in the open you will need to communicate with others. Nothing breaks a team like terrible communication and someone who rejects feedback out of pride.

      [0]: https://en.wikipedia.org/wiki/Soft_skills

    • This whole interaction is really reaffirming my faith in humanity. You guys are awesome!

      Liam -- this response is just as impressive as the code that you wrote. You're obviously very smart, but that isn't good enough on its own. I've seen very-smart people who aren't open to critique, who get defensive rather than take the opportunity to learn new things. They don't get very far in life. On the other hand, the attitude you're showing here is tremendously valuable, and will serve you incredibly well throughout life. Never let yourself grow out of it!

  • If you would start a channel where you review code of random public repos I would definitely subscribe. Well done.

  • Instead of this:

        (rule & (1 << i)) === 0 ? 0 : 1
    

    You could just do:

        (rule >> i) & 1
    

    Otherwise it was a good review! I'd probably also extract parts of this long line so it's not as cumbersome to read:

        return state.map((item, i) =>
            rules[((state[i - 1] || 0) * 4) + (item * 2) + (state[i + 1] || 0)]
        );
    

    to

        return state.map((item, i) => {
            const prevItem = state[i - 1] || 0;
            const nextItem = state[i + 1] || 0;
            return rules[(prevItem << 2) | (item << 1) | nextItem];
        });
    

    It also uses bitwise operations instead of arithmetic, even though they are equivalent in this context, simply because we are effectively operating on arrays of bits.

    • Thanks for the edits! I can't change the video, but did mention that both of those lines are a little clunky. I did update the gist though! Much cleaner.

    • I like to break expressions across multiple lines, and line up any patterns that are repeated, so your eye can easily scan up and down and obviously see what's the same, and what's different.

      For example, instead of:

          var length = Math.sqrt((x * x) + (y * y));
      

      You can go:

          var length = Math.sqrt((x * x) +
                                 (y * y));
      

      That way you can see the similarity of squaring x, and squaring y. But breaking up the multiplications because they repeat the x's and y's would be taking it too far -- it always requires balance and thinking about how can I communicate my intent and the SHAPE of the problem I'm solving.

      You can also use indentation and formatting to bring out and make obvious other two-dimensional patterns and regularities, especially with two-dimensional cellular automata and graphics code.

      There are some examples of that technique in my 2D cellular automata machine code. (There's a lot of code, so don't be overwhelmed, since I've been working on that since around 1985 or so. So never give up and just stick to it! You don't need to understand the code, which is pretty esoteric, just notice the patterns.)

      https://github.com/SimHacker/CAM6/blob/master/javascript/CAM...

                              // Load the right two columns of the 3x3 window.
                              n  = cells[cellIndex - nextCol - nextRow];  ne = cells[cellIndex - nextRow];
                              c  = cells[cellIndex - nextCol          ];  e  = cells[cellIndex          ];
                              s  = cells[cellIndex - nextCol + nextRow];  se = cells[cellIndex + nextRow];
      

      [...]

                                  // Scroll the 3x3 window to the right, scrolling the middle and right
                                  // columns to the left, then scooping up three new cells from the right
                                  // leading edge.
                                  nw = n;  n = ne;  ne = cells[cellIndex + nextCol - nextRow];
                                  w  = c;  c =  e;  e  = cells[cellIndex + nextCol          ];
                                  sw = s;  s = se;  se = cells[cellIndex + nextCol + nextRow];
      

      [...]

                                  var sum8 =
                                          (nw & 1) + (n & 1) + (ne & 1) +
                                          (w  & 1) +           (e  & 1) +
                                          (sw & 1) + (s & 1) + (se & 1);
      

      [...]

                                      var tableIndex =
                                          (((c         >> plane) & 0x03) <<  0) |
                                          (((e         >> plane) & 0x03) <<  2) |
                                          (((w         >> plane) & 0x03) <<  4) |
                                          (((s         >> plane) & 0x03) <<  6) |
                                          (((n         >> plane) & 0x03) <<  8) |
                                          (((cellX             ) & 0x01) << 10) |
                                          (((cellY             ) & 0x01) << 11) |
                                          (((phaseTime         ) & 0x01) << 12) |
                                          (((plane     >> 1    ) & 0x03) << 13);
      

      [...]

      When the sub-expressions won't fit on one line, you can still use indentation to help the reader understand the spatial patterns:

                                  error +=
                                      (nw * kernelBytes[4 - kernelDown - kernelRight]) +
                                          (n  * kernelBytes[4 - kernelDown]) +
                                              (ne * kernelBytes[4 - kernelDown + kernelRight]) +
                                      (w  * kernelBytes[4 - kernelRight]) +
                                          (c  * kernelBytes[4]) +
                                              (e  * kernelBytes[4 + kernelRight]) +
                                      (sw * kernelBytes[4 + kernelDown - kernelRight]) +
                                          (s  * kernelBytes[4 + kernelDown]) +
                                              (se * kernelBytes[4 + kernelDown + kernelRight]) +
                                      frob;
      

      But that would probably be more readable if I used intermediate variables for the kernelBytes[...] expressions, gave them descriptive names matching their corresponding directions, and lined up all their calculations so you could see the similarities and differences, because right now all the kernleBytes[4 +/- kernelDown +/- kernelRight] expressions are jumbled around horizontally, when they could be lined up nicely by themselves if they weren't interleaved with the n/s/e/w/ne/nw/sw/se multiplications. (I'll leave that improvement as an exercise for the reader. ;)

      The point is you want to vertically line up as many of the repeated letters and symbols in nice neat columns as possible, so that your eye can easily see which are the same, and the ones that aren't stand out obviously so you can ignore all the same things and focus on the differences. (Which are typically variations like +/-, sin/cos, x/y/z, -1/0/1, nw/n/ne/w/c/e/sw/s/se, and longer series of names and numbers. Whatever changes should stick out visually, and be lined up and grouped together so your eyes can scan over them!)

      That not only helps other people understand your code, but it also helps you be sure that you wrote the right thing, what you actually meant, instead of making an easy to miss typo.

      The difficulty of reading you own code, which is HARD even for professional programmers, is that you usually see what you MEANT to write, not what you actually wrote. That's why it's so important to get other people to read your code, and to read other people's code, like pair programming and code reviews, or even explaining it to a duck.

      https://en.wikipedia.org/wiki/Rubber_duck_debugging

      It takes a lot more effort and concentration to slow down and look at what's actually there, instead of what you want to be there. (That's true for many aspects of life...)

      2 replies →

  • Nice of you Steve.

    Liam - whatever Steve suggested are very good pointers but please remember you are getting accolades here because you cared to publish your code. Don't hesitate to publish your initial version without any hesitation in future also.

  • Kudos for taking the time for doing this! It's places like these where the HN community really shines.

    Thanks a lot!

    • Thanks! I really enjoyed making it. HN has been such a huge part of my life over that last ~10 years that it's truly the least I could do.

  • Incredible code review!

    I wish this inspires clever people to produce huge amounts of parody-videos "refactoring" the same piece of code. :)

  • I'm a long time coder and still liked watching your video just for watching someone else work in emacs. How do you get emacs to highlight all occurrences of map? Was it a keybinding for "highlight-phrase"?

    • Thanks, glad you enjoyed it! And like another person already responded, this is vim with a split pane where the right pane is a `:terminal` (a relatively new feature of vim... though prior to that I would have just used tmux).

      Highlighting searches is enabled with `:set hlsearch`, and you can search for whatever word is under the cursor with ``. So I just type and it highlights all of the matching words. Nothing too magical!

Congratulations!

I showed your project to my 12 year old son who has just started to learn programming (in JS no less!) and his jaw dropped.

In addition to being a programmer, you are now a role-model. Really well done.

  • Thanks a ton!

    Tell your son that it took me a while, and a lot of work, but it feels great to finish something (there are a lot of projects that I don't finish...).

    I began learning using Scratch a long time ago. They even featured me last year (the project was a solar system in which I used sine and cosine to calculate the rotation of the planets). I then used blocklike.js to move to JS.

    I watch a lot of YouTube videos. I like The Coding Train, Carykh, and Code Bullet, and I get a lot of my ideas from their projects.

    • Startup Idea: Start a slack/discord group for aspiring students between the ages of [pick your age range, say (8-18)] and start a mentoring/support group with these like-minds...

      You'll learn, build relationships and some of you will go off and found companies together.

      10 replies →

    • I've got a 10 year old who's been making a lot of stuff in Scratch since he was 6. I've been trying to think of how to phase him over to less limited languages and wasn't aware of blocklike.js, so thank you for that idea.

      Having a lot of projects that you don't finish is completely normal, so don't worry about that.

  • >I showed your project to my 12 year old son who has just started to learn programming (in JS no less!)

    It would be much better if he would start with Scratch, Processing, Smalltalk, or even Python.

    On JS he'll have to lose time coping with complicated build tools, horrible package system, async etc.

    • Is this serious? I started programming around 9 or 10 on a Commodore 64. I would go to the local library to get programming books for it. Now you can hit F12 in your browser and get a powerful console into JS. JS is fine, encourage the thirst for knowledge.

      10 replies →

    • You need none of those things to get started with JS development

      It’s still perfectly possible to just create a html document, shove in a script tag, and start developing

      And if you want to use packages from the npm ecosystem you can easily use https://unpkg.com/

    • The only thing you need to learn programming with JS is a text editor and some rudimentary HTML knowledge.

      Everything else is unnecessary, at least as far as the programming language itself is concerned.

Great work! I made a quick Observable notebook out of your code, in case anyone wants to see what it does without downloading or running it on their own machine:

https://beta.observablehq.com/@jrus/wolfram-cellular-automat...

  • Dang, that's a neat tool. It's different enough from a Node environment, though, including some of the necessary rewrites of stuff, that I wonder if a "more Node-y" sandbox would be more useful for this particular case. An example: https://codesandbox.io/s/r0kwk0o28p (I tweaked the rule number, column width, and output to print to the page, but otherwise it's the same as the original.)

  • Hi Jacob, I never got to thank you for doing the observableHQ notebook for my quasirandom sequencing. For your information, I have linked to it on many occasions which includes in my post "Unreasonable Effectiveness of Quasirandom Sequences" which is on front page of HN right now! :) https://news.ycombinator.com

Hey looks good :)! Just a few things you might not know about:

Google String.prototype.padEnd. It’s built in to JS and should be able to replace your zero fill function.

And instead of mutating the ruleSet array you should be able to use Array.prototype.map like this:

const ruleSet = zeroFill(8, rules.toString(2)) .split('') .reverse() .map(item => parseInt(item, 10));

And you can clone arrays like this, instead of using loops:

const oldArr = [...arr];

Also arrays are still mutable even if you assign them to const variables.

I’d offer more help but I’m on mobile. Sorry for the poor formatting. Hope this helps anyway. Good luck!

  • I think it is good he's learning to do the loops by hand first. It's good to have an understanding of algorithms first when learning to code.

    • In fact this "you should never code FizzBuzz yourself, just use util.FizzBuzz(n) to print the first n iterations" mentality probably contributes to the surprising number of software developers who can't code.

      1 reply →

  • Though, keep in mind that some of this stuff (most notably the [...arr] syntax) won't work in old browsers if you make a web project (IE 11 is a big offender here). See https://caniuse.com/ for a useful source of info on what will work with what for stuff like that.

    If you do web stuff (and you don't want to just say "no IE 11" - some people, and even some big companies, do that!), usually the easiest way to handle stuff like that is to use the newest syntax you're comfortable with, plus a tool like Babel that will produce a "time travel" version with older syntax that will work in all browsers.

    • This project explicitly says Node. But in any case, these days I generally recommend using Babel to transpile the newer JS to browser friendly JS as the productivity and readability improvements in newer versions of JS are worth the effort to me to set up the babel build step.

      2 replies →

Good for you young jedi. I started coding around that age as well. I made the mistake of not going through comp-sci but have still been able to work for Google, publish books, lead teams and companies and products. You'll do just fine.

You have the ability to write some code! If you want to get a jumpstart, you should take the princeton algorithms course (for free!): https://www.coursera.org/learn/algorithms-part1

Or read the textbook by sedgewick that accompanies the course. https://algs4.cs.princeton.edu/home/

There is very little math in there - it may take some elbow grease and mentorship to help to convey some of the ideas - but I believe that you could implement and solve most everything in there. That was my path - I had a teacher at the age of 14 who would explain to me how different algorithms worked and I would go and implement them. Drawing a circle (in memory - it was in C!) or sorting a list (we did bubblesort first IIRC!)

I think you could do it! I believe in you! The course material is approachable - much more so than basically every other algorithms/data-structures material I've found. it may take you some time but you'll be soooo far ahead with your thinking about code.

If you ever start working with Object oriented languages like Java, another book that may help you when you've gone down the road a bit is the Head First Design Patterns book. http://shop.oreilly.com/product/9780596007126.do It's very easy to read, mostly pictures. It is made to be very easy to read (all of the books in that series are so look around at them.)

It's helpful to do both - code and also take in some material, but at 12 I imagine some of the material may be a bit daunting. You're doing really well - keep it up.

Liam, brilliant!

I am not saying you don't do this, but please please ensure you always sleep well, follow a good diet and go out and play.

Sometimes, computers make us give up good habits!

Kudos for your great work and keep learning, keep shipping!

Woah - very cool! I'm a part of Hack Club (https://hackclub.com), which is a nonprofit worldwide network of high school coding clubs. Hack Club has an amazing community of young developers - I actually lead a Hack Club at my high school, and I definitely recommend that you join their slack (https://hackclub.com/slack_invite) to connect with other young makers!

By the way, I'm a 17 year-old developer (https://shamdasani.org), but I probably started ~14. My main project is Enlight (https://enlight.nyc) to teach others to code by building projects. If you'd like to contribute, that would be awesome - feel free to shoot me an email :)

That's awesome. What resources did you use to learn Node and JS? Just looked at your code. Kid. You're a badass. Keep this up, you'll go places.

  • Thank you! I'm watching a lot of Youtube videos. This is how I got to cellular automata. My dad showed me git last week.

    • > My dad showed me git last week.

      Anyone else miss learning this quickly?

      In all seriousness, congrats. Keep at it. There is always something else to learn. It's the career that never stops giving.

    • That's pretty quick!

      Do you have any plans for future projects? Maybe a simple place where you could chart your progress?

      I think one of my favorite uses of cellular automata besides conway's game of life (if you are interested in it) is modeling simple fluid mechanics (water flowing from place to place) in games like dwarf fortress http://www.bay12games.com/dwarves/

    • > My dad showed me git

      Cheater! :) Seriously though, great work. I started around your age (which I guess means I've been coding for half my life at this point.) Keep challenging yourself with new and interesting projects and you're going to learn a lot and have a lot of fun.

Looks great. I tried it and it runs fine. Nice syntax and convention.

Just a tip, you don't need to include `npm init` in your instructions. That command only needs to run when you create a new project. It worked just fine for me with just a `node index.js 18`

Great work!

Great that you start so early, I've did the same. For me it was a great way to gain confidence and build a skill which is very useful. I wouldn't be the same person now if I didn't program so early.

Seeing how things come to life that you've build with your own hands is a very empowering experience. Keep it up! :)

Far better than I could do at that age!

I think the furthest I was getting at that time was building out really terrible looking web pages in Notepad and making awful little animations in BASIC and Turing (learning lang).

Keep it up!

  • I made a colourful ASCII birthday cake in Pascal that beeped happy birthday at that age. Still one of my proudest programming moments.

  • I was on my Atari 800XL making games at that age. I started hitting problems that I thought should be easy. Like, I wanted to draw circles. But the library was just pixels and lines ( when I got to assembly programming, suddenly lines became a problem too ). There was no googling the answers, but luckily I could go "Daaaad..", who was a physicist, and he happily introduced me to trig and I eventually learned to draw circles....slow drawing circles, but still, circles.

    • +1. Reading your answer made me think you were talking about me. Except I had a TI99/4A, and "Daaaad" was my real google. My circles were probably slower and more pixelated

Great job! One way to improve this code is to add comments. Use comments to describe what each function does and what the parameters are supposed to be. Then you can tell at a glance what the function does without having to analyze the code later on.

Us old people tend to forget things.

  • Also, if you use JSDoc a lot of modern editors can use that to automatically provide type hinting, documentation references on mouseover, etc.

This is awesome! Keep up the good work. As a fellow developer who began writing software around your age, I have some advice that is definitely subjective and biased, but which you may indeed find helpful.

1. Keep practicing. Practice makes perfect. Explore different languages, frameworks, and problem spaces (interfaces, servers, distributed systems, statistics, etc.) to see what you find most interesting. You will make mistakes, and that is okay. That is how you learn.

2. Take frequent breaks. Programming is hard work. It can be truly exhausting, and you should not be afraid to step away and go for a walk or something.

3. The most valuable people in the industry are called "T"s. I.e. people with a little bit of knowledge/experience across broad range of topics (the horizontal part of the letter T), but who have deep knowledge/experience in one or a couple particular topics (the vertical shaft of the letter T).

4. Begin to develop the skill of taking feedback and accepting criticism. There's a lot of people out there who will be quick to criticize everything you do if you put it out into the open. It's a whole skill in itself to be able to interpret this feedback and separate the signal from the noise. Try to empathize with the person or group providing feedback and understand that their motives/perspective may be different from yours. Sometimes that's a useful thing. Sometimes it's a distraction.

5. Dn't take things too personally. You are not your code. A criticism of your code is not a criticism of your character. The less you take things personally, the easier it is to work with others. After all, the most impressive systems require immense collaboration.

6. Don't take yourself too seriously. Have some fun with it! Programming is super fun, so you should ask yourself regularly "am I still having fun?". If the answer is "No", maybe find something else interesting to focus on for a bit.

7. Broaden your perspective. Along the lines of #1 and #2, it's important to maintain a broad perspective and push yourself to keep expanding your perspective. This doesn't just apply to technical problem areas or languages or frameworks. The best engineers are good problem solvers because they have a broad perspective not just of the problem space but also more generally of the world they inhabit. Try to learn about different industries, cultures, people, and places. You will become a more well-rounded character for doing so, with a higher ability to empathize with others and understand the complex mechanics of how the world works.

8. Be social. I made the mistake of hiding in my room on a computer for much of my childhood, and it wasn't until high school that I really began to understand the value of social interaction and maintaining strong solid friendships. It's as important to spend time away from the computer as it is too keep practicing.

All the best. Good luck!!

  • I'm 27, and learned this over over years, but still I needed to hear this again! And I'm sure I will need this advice again. Bookmarked :)

  • This is not just good advice for a successful programming career, but if you can pull it off, pretty much any field that one is passionate about.

    As a scientist, if one is a scientist and has abided these ideas, they'd ramp up the food-chain pretty quickly.

  • Would you please provide an example on how one proceed with T shaped learning and expertise?

    • That's a good question. I left that intentionally broad so as not to prescribe a certain type of learning system or self-education.

      There's a lot of ways to learn anything, but I would say that the first step is pursuing a variety of subjects that you find interesting, and even some you think are boring. A lot of seemingly boring things I've found turn out to be quite fascinating when it comes down to it. (e.g. database design)

      Over time, you will pick things up, and put them back down. You will return to some, and stay away from others, but eventually you will build a repertoire of knowledge and experience in a variety of different fields. I would also bet that at least one subject will interest you so much that you keep coming back and in which you will ultimately develop expertise.

      Experimentation is the name of the game!

      1 reply →

    • I work in cloud, and one of the things I look for when recruiting solution architects -- another role where broad is a pre-requisite and some narrow depth is expected -- is systems design skills. Besides whatever you study and learn how to do as a programmer. these days it's not often commercially applicable unless you know how to make it run well in the cloud, with all the caveats that apply.

      Among the things that aren't common knowledge among basement programmers: network configuration (VPCs, load balancing, CDNs, security), security/IAM, non-relational datastores, ML model development & training, and the list goes on and on and on (microservices & containers, devops, serverless, advanced logging/monitoring & problem solving, high availability, HPC/grid, blockchain, and oh so much more.

      The point I'm trying to make is that you can become a T shaped programmer by continuing to study and learn various programming skills, but you may want to alternatively consider becoming broad in ways that expand your value beyond just coding.

      1 reply →

    • A phrase I came up with that I like more than "T-shaped" is "molecular skillset". A chemist would probably laugh at me but I think of it as developing seemingly independent skills (molecules <--> skills, experience, knowledge...) that end up forming bonds with other skills, sometimes in surprising ways, that together prove really powerful and can bond up even further. "T" and other tree/tendril-ish shapes are then just special cases of different bond arrangements. You can acquire skills haphazardly (though as a serial dabbler I'd caution against actively pursuing the dabbler's path without a ton of introspection), you can also take the efficient road like a university sequence where most skills are visible and have unsurprising connections to the next skills. You might have to take some seemingly unrelated course too, but you can look at those optimistically as another potential source of surprising bonds. Duds are of course possible -- I have some useless things in my brain that I don't think will ever connect with anything useful, at best they might aid in social signaling one day. (A lot of education is just signaling to show you can talk about a lot of stuff...)

      Trivial example: at some point around age 17 I installed Gentoo successfully and learned a lot about gnu/linux (and some bsd) in the process. Lots of little skills formed and connected, and they continue connecting with other things to this day. Got my initial hook on vim then. Saw how nicely colorized my terminal prompt was and that opened the door to many bash customizations. One of the skills I had to learn was to understand how hard drives worked (at least to the ability to successfully partition, format, and boot them -- I did accidentally wipe a windows xp partition the first time). Some years later (age 20?) I had accidentally rm'd a couple weeks of java work without having committed it yet. But prior knowledge of the system let me know the data was still there, and I was able to recover it by scanning the disk device partition directly for the bytes. (Ended up using "grope.tcl" referenced here http://wiki.yak.net/592 which was a lot more efficient than what I was making.)

      3 replies →

This is awesome liam. im just over twice your age and am just now writing game of life simulators.... man, what was i doing at 12???

  • Trust me, there can be downsides to starting early. In my case, I virtually skipped having social interactions not on the internet until I was around 20 or so. Not everyone will have this kind of affliction, but you can't have it all - you gotta choose what's important to you. I hope this doesn't come off as being too negative, I mostly say this because I think you should try to appreciate what you did learn rather than lamenting about not being able to start with coding super early.

    ...that being said, this is way cleaner than any code I'd written at 12 I'm pretty sure.

    • With that said, it can also have the opposite effect. Success in online interactions at such an age gave me the confidence I needed to be successful in irl interactions.

    • > I virtually skipped having social interactions

      That was me, too. It was a trade-off for me. I was reading Hawking in primary school and there was no one to talk to, so I was feeling lonely.

      Programming was my lifesaving straw, but I don't wish any kid the kind of isolation that I've felt in my youth. I had to learn many of the social stuff later in life so it evens out IMO.

I guess I'm the only one here doubting that the combination of both this project and the language used in the comment replies is coming from a 12 year old.

Take it as a compliment if it's legitimate.

  • Probably not the only one, it's very common for people to be extremely prejudiced against the young. As with other prejudices, of course, it's wrong and only scores accurate evaluations by chance. The only thing which prevents any person, of any flavor or age or background or whatever, from producing such work and comporting themselves in such a manner is not having learned it or not practicing it themselves. Anything blamed on 'age' is normally just an indictment of the society that hasn't provided appropriate education or incentives.

    I was a precoscious kid myself, and took to online communities with vigor specifically because it permitted me to interact with adults as equals without them constantly dismissing me without basis apart from my age. I've not forgotten that, and if anything society now is even more egregiously bigoted towards the young than ever. Next time you read an article about "kids" or "teenagers" or "adolescents", try mentally substituting in "women" or "African Americans" for the group identity they're talking about. You might be surprised how identical the claims made, and the weak support given for them, are.

    • No, it's not the same as doing that for women or black people.

      People lie about their gifted child to get them exposure all the time. People doing that with art comes to mind. Or even just a parent doing assignments for their kid.

      You're not being creative enough if you can't imagine a world in which someone would lie about something on the internet for attention.

  • That makes two of us. My first thought was "Why would someone lie about being 12?", but then i remembered this is the internet. I would ask for proof, but it looks like everyone has already made up their mind or doesn't care.

Hey man, great job! You got some great advice here from the HN crowd and I'd just like to add one more: blog.

Set up your own site and blog about your journey and the lessons you've picked up along the way. Learning is about working and reflection. Blogging is a good platform for that. The very act of writing the content itself is reinforcing your knowledge. Dive into the work, research, reflect, stay hungry and repeat. That's what it's all about. Apart from that, you'll be expanding your network as well. Having some amount of folks following your journey is not just a good way of inspiring oneself, but also gives you an opportunity to inspire others as well.

Anyways, keep it up! You're definitely going places.

IANAL and all that and it doesn't bother me, but the first thing I thought of was the age related ToS restrictions from the HBO Silicon Valley show.

From the HN "legal" page:

> If you are under 13 years of age, you are not authorized to register to use the Site.

https://www.ycombinator.com/legal/

I assume no 12 year olds actually try to follow this boilerplate on the internet. Do sites that require a DOB to sign up reject those under 12?

  • The legal restrictions are not actually on Liam, or any user. They are on the site itself. The law in the US prevents the collection of any personal information from anyone under 13 years of age. Once you are 13 years old, you are a trackable, surveillable, profilable, saleable commodity. Prior to that, though, your personal info is protected from collection.

    But... HN doesn't actually collect any personal info. So, that's likely either a reflex inclusion of such a clause or just an abundance of caution.

  • I just assumed no people actually try to follow this boilerplate on the internet, glad to see the this knowledge is being passed down through generations.

  • If he's not authorized to register on the site then the ToS can't apply to him, can they? At which point he can register, but then...

  • HN doesn't take PII (just a username/password), and doesn't take a birthdate either for verification, so COPPA probably would not apply.

Good job! I mentor college CS majors whose code is not as clean as this. Seriously.

I would also recommend checking out The Coding Train. NYU ITP Daniel Shiffman's lectures on creative coding. It's time to get started with graphics ;)

https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw

And to get a headstart in Artificial Intelligence, from the same author comes the ml5.js library: friendly machine learning for the web. Best of luck!

https://ml5js.org/

I like how the array named 'map' reflects our original use of this word, rather than the special meaning which it has acquired to programmers.

In Javascript and other languages 'map' has become a kind of "functional operation" so we cant call things 'map' anymore (in public). We have to say 'space' or 'state' or 'grid' or something... but I do still think 'map' was good.

Congratulations on a very efficient and readable project. Bravo !

  • Programmers got it from mathematicians. I had the impression it was a fairly long standing use of the word.

    • Mathematicians got it directly from cartography. A “map” “maps” points from one set of coordinates to another, for example when you want to plot latitude and longitude on a flat paper.

    • I expect ideas of mapping functions are only a couple of hundred years old at most, and really quite obscure to most people who are just familiar with the concept of 'maps' and 'mapping' things 'out'.

      In functional programming I understand map as just a clone and convert operation. I noticed C++ has a 'map' data structure which is most suitable for associating references. A C++ map is not suitable for storing positions in space.

I'm particularly fond of this because at 12 when I was learning to program I never thought it was important to keep my work safe, or even documented at all, and it all exists on a hard drive in landfill now.

If you pursue a career in programming, you'll look back at your early work and have a great personal self-documentation tool to remind you of how far you've come.

Everything about it is optimism-inducing on a very deep level. The post itself, the reaction, the answers, the discussion.

  • Well, you either congratulate, or you get downvoted for not being nice. Your choice here on HN.

It's amazing that at the same age Steven Wolfram himself had written his first 100 page book "concise directory of physics) and at just one year older wrote his first book on quantum physics.

  • From all the amazing things Mr. Wolfram has done at such a young age almost makes him the Chuck Norris of science.

    • It's really not all that unusual. History is littered with amazing minds that accomplished tremendous things well before adulthood. The modern fiction that humans are useless until adulthood is one we have to construct by force, through active neglect of education, denigration of intellectual pursuits ('Go outside! Get a life! Do anything else but read or sit and think!'), and adamant insistence that it is normal to be ignorant and incapable until adulthood. Pascal recognized his triangle as a youth, Gauss was similarly known for early feats, etc. Those are just accidents of history, mostly, that they are remembered. The actual number of fertile and productive minds is doubtlessly orders of magnitude higher. It's only through diligent refusal to believe, or to tolerate the notion that maybe we should have expected a bit more of ourselves in our own youth, that we can keep up seeing intellectual achievements of the young as an unusual occurrence.

    • Catching the disease of cellular automata isn’t a good thing. Fredkin was also affected. This young person has many years to do useful things.

      1 reply →

I feel bad for all the other 12 year olds whose parents just saw this :)

  • It's great to be writing code at 12 if you want to write code, and clearly this kid has a talent for it, but that doesn't detract from what all the other 12 year olds are doing. So long as they're happy and safe to do what they want to do it's all good. Growing up is not a competition.

    Also, while it may seem great to learn early, I've worked with people who didn't write a line of code until they were in their 50s and they were far better at it after a few years than I am despite having 20 years more experience. Some people have a gift. Others have to really work at it. Sadly I'm in the second group. :)

    • What about those of us in the 3rd group - started late and have to work hard at it!

  • Any parent who thinks they have a place in determining what pursuits their adolescent child is interested in is in for a wakeup call...

This is so great and I am really impressed, and even a little inspired! When I was 12 there was no internet and learning programming was really hard, but it was more fun for me than anything else. Your project has reminded me how I felt so many years ago when I was 12 and I would sneak out of bed to program QBASIC on my APPLE 2C. Thanks for the inspiration and keep up the great work! Keep working hard like this and you will become a master programmer of the first rank.

Congratulations!

Are you familiar with code golf? If not, I recommend it. In Code Golf, the objective is to complete a programming task in the shortest program possible, measured in bytes. While doing so, you really learn about the nuances of your language and its obscure features.

When I was about your age, I joined the code golf community at Stack Exchange, and since then my JS skills and general programming skills have improved greatly. I hope that you would find it to be useful too.

Congrats.

> dimensional cellular automata in witch all possible rules are encoded into one byte as described here

Small typo here - should be "which" instead of "witch"

Hi Liam! I'm your occasional HN neighbour I live currently just below your post :) (Show HN: A smarthome dashboard concept using zircle-ui).

It's a pleasure to see the impressive reception that your post is having. Also I want to join all the voices of congratulations you have received for your work at your age! Keep doing this kind of things, It is very inspiring for all!

Nice work. I'm not a JS expert but I think I saw a bug.

Inside of animate() you are calling setTimeout() to automatically call animate repeatedly but this is also calling setTimeout() every time animate runs but setTimeout() should only be run once.

You should be able to take

  setTimeout(() => {
    animate();
  }, 100);

and paste it over animate() on the last line

  • What you mean is setInterval and does work well for synchronous execution. His approach is correct and would even work if the animate function is asynchronous as the next tick gets scheduled at the end of animate function execution.

You're off to an amazing start!

I'd say just find stuff that genuinely interests you and try to build it. I got my start focusing on games, but whatever gets you excited. You're already way ahead of the curve, so have fun with it, experiment, and you'll do great things :)

Off topic for the main achievement :)

But: if I open the bitbucket link on mobile, the left part of the text is clipped and it doesn't allow scrolling left.

With "request desktop site", it works perfect.

Why does mobile mode even exist if the desktop site works better??

  • I tend to read my own code in bed on the phone after I commit.

    The new Bitbucket interface really dropped the ball on this. It is almost unusable.

    I hope they’ll fix it...

This is really amazing, reminds me of my childhood days..

I showed this to my girlfriend's sister whom has shown interest in programming, today I learned that she decided to drop her art classes in favour of some programming courses!

Well done!

That’s so cool! When I was 12, the best I built was a game of Who wants to be a millionaire in Qbasic and this is whole another level from that! You are inspirational!

Great work :-) I had fun programming Basic and Z80 assembler when I was 11 as well. I always remember it as being a great time of discovery and passion.

Just stepping by to say, congrats for shipping, congrats for posting ! Im 32 and will be posting my public beta next week !

Congratulations Liam!!!

You're doing phenomenal. You'll be role model for up-coming generation.

Great!!

congrats! when I was 12 I was war dialling BBSes and pirating shareware games. hopefully your future turns out bright.

Excuse my portion of scepticism, it's not the fact that a "12 year old" built this, sure anyone can learn how to code and we can't know how much help this person got along the way. But it's rather the person's language when writing plain text, here in the comments for example. It doesn't feel adolescent but more grownup to me ... But maybe it's just me realising my own shortcommings as a 12 year old, as I only was playing with my friends and the odd computer and video game.

  • Do kids really do their own science fair projects? We have different rules of ownership for age-appropriate levels of mentorship.

    Also, I and likely you come from a different generation (I'm aged late 30s) where my parents knew nothing about coding and I genuinely had to learn everything on my own reading books at a library when my parents would drop me off.

    I only had access to a very expensive family computer where my parents would freak out if I changed something on the fancy appliance they poorly understood and essentially every language other than qbasic needed a pricey proprietary compiler costing hundreds of dollars.

    These days with the accessibility of the internet, explosion of open source, craigslist laptops perfect for learning going for under $75 and the commonality of programming as a stable career, it wouldn't surprise me to find children living in say, the silicon valley with programmer parents who successfully get their child excited about programming early.

    It's a different set of circumstances and a 12 year old able to write graphics demos doesn't sound that implausible.

  • I was extremely lucky and got Internet access in 1990 (pre-web) when I was myself 12 years old. I was entirely conscious of the fact that if the adults figured out that I was 12, I was dead meat. They wouldn't listen to a thing I had to say, and wouldn't feel the need to defend their claims against any argument from me. So, I spoke well. It's not all that hard to do. As such, I can't recall a single time I was ever called out. When I did on occasion choose to reveal my age, I often encountered disbelief, but by then it was usually after I'd already won them over so they could overcome their bigotry. And that's really what it is, I've realized in the years since. It's just simple 'they're not like me, any difference must be negative, it must be rooted in what they are and insurmountable, I will always be above them' bigotry. Despite the clear fact that if a 12 year old is taught to install a kitchen sink, something I'm sure anyone could see as possible, then clearly they'd be superior to most adults who don't know how to install kitchen sinks. So why is anything else different?

  • I think that to post here, is a good sign. Show HN wherever you are able to do, alone or after a 100M financing is one of the reason forums like this one exists. The other is to just share your code and meet digital people.

    > It doesn't feel adolescent but more grownup to me

    Showing skepticism is also fine, our industry is not just nice code review and beautiful moments where people want to encourage you.

  • it is incredibly to rare to produce a prodigy without a very involved parent or a close mentor.

    Mozart, Tiger Woods, Terrence Tao all had parents helped them start extensively from a young age

Technically, you shouldn't be using this site ;)

> If you are under 13 years of age, you are not authorized to register to use the Site.

But I applaud you for getting into programming this early.

Great work. I will give you a different piece of advice. Make sure to work out 360 out of 365 days in a year, without weights.

  • Ok I'll bite....where is this very specific advice coming from?

    • From a guy that was doing cool things with a computer at age 12 but instead of starting to workout at age 12, started at age 18. Any age is good to start working out but sooner is better.

      3 replies →

I think what I love most is that he/she is using version control, and the version control of choice is Bitbucket!

All your work is in 1 commit and you only have 3 total commits in your repo. I'm skeptical that YOU wrote this program.

I'd happily be proven wrong.

  • This comment violates HN's rules. Please assume good faith and don't attack people.

    https://news.ycombinator.com/newsguidelines.html

    https://news.ycombinator.com/showhn.html

    Consider the ridiculous downside of someone being 12, posting their program to HN, and meeting with this as a first comment. How awful.

    • Going to be honest, when I was 14 and learning to program, I quickly learned how shitty and harsh the internet can be, especially the types that frequented forums.

      2 replies →

    • Guys, I think you should ALL calm down and stop playing SJW. He simply stated that he doubts the kid wrote the code. Since when having a doubt is considered BULLYING??? Did he insulted the kid? Did he used a slur against him? No. He expressed his legit and reasonable doubt.

      So please turn on your neurons and stop playing mother hen and SJW ok?

      Being skeptical is a right we all have to take advantage of and since it has been made in a respectful way, there are no reasons why attacking the user in the way you all did.

      This politically correct thing is slipping thru your fingers and out of your control of you REALLY and SERIOUSLY think that expressing a legit doubt is considered an act of bullying. Ponder about that.

    • No it's not awful. People will doubt him sometime, and it's better to learn how to deal with that and gain a life skill rather than expecting every person to be sweet and supporting.

      There are some kids who just goes on game chats to mess with others, play loud music, bully them, grief them etc. They are usually around 12 years old to 16 years old. I'm sure these things are not new to this kid.

      Welcome to the planet.

      6 replies →

  • I disagree. I'd say having all of the work in 1 commit makes it more likely to have been created by a young programmer. What impresses me the most, and makes me skeptical, is the good code style. I know at least 3 12 year old programmers who might be able to do this, but none of them have this diligence for style.

    The program is short enough and I was enough of a nerd at this age to be interested in doing something like this. I just focused on making poorly-designed computer games instead.

  • Everything being in 1 commit seems perfectly normal for this situation.

    He likely wrote the entire thing without Git (because he's the only one working on it), then decided to push it to BitBucket when he wanted to publish it.

  • So you're saying it's more likely that this 12-year old would have written this thing if he had split everything nicely into small readable commits?

    That makes absolutely no sense

I need to get a job in a diffrent field. Things like this make me remember how stupid everyone in IT really is.

  • Maybe so, but please don't post unsubstantive comments to Hacker News.

At 12, I was writing 6809 and 68k asm, and cracking games.

The most impressive demos in the Atari scene were written when we all were around 15.

Because we had plenty of spare time and still lived at our parent's house. And because we loved programming.

Nowadays, kids are just not interested in computers any more, besides playing Fortnite and more generally, using apps or wasting time on Youtube and Instagram.

Trivial lines of code in Javascript are now supposed to be a wonderful achievement for a 12 year old kid. Sad.

Good work.

For a next step, I would suggest giving a try at breaking it up into multiple files using import/export statements (it doesn't need it but it's good practice), and using a bundler like Parcel to build the finished file.

    npm i --save-dev parcel-bundler

...then move your source JS files to a folder named src, and add to package.json...

    "scripts": {
      "prepare": "parcel --target node src/index.js"
      "start": " node dist/index.js"
    }

In your individual files, you do like...

    // file-1.js

    import somethingName, { whateverName } from './file-2'

    // file-2.js

    export function whateverName { ... }

    const somethingName = '...';
    export default somethingName;

...and then run...

    npm run prepare
    npm run start

(The prepare script is also a "magic word" that will auto-run anytime someone does 'npm install', so usually an end user won't have to manually run it.)

A bundler isn't strictly necessary if you plan to only run something in Node, but it lets you make a package that's usable in both Node and web projects, and it makes it simple to use Babel, which lets you Javascript features from the future that aren't actually in Node proper yet.

  • How about we let the kid learn how to program (which will outlive your favorite bundler and file hierarchy anyway) first? It's a 100 line script, one of the mistakes I made learning how to program was trying to be like the adults and focusing on minutiae like code organization rather than good code.

    EDIT: story time. I once tried to make a 2D game engine in my late teens, but I wanted to be like the adults and have a proper class hierarchy. Suffice to say, I never finished it. Come to find a few years later, now class oriented OOP is passé and I was wrong to waste that time on it.

    Learning to code and get things working is more cool (and in the end, more profitable) than making your code fit the norms of the day, which won't last anyway.

    • My intent is less "code structure", and more "most of the pieces you need to make a Node project also work in the browser". Imports/exports and Parcel would get liamilan most of the way towards being able to do...

         if (window) {
           document.write(...)
         } else {
           console.log(..)
         }
      

      ...and have it just work, without having to write everything twice.

  • That last thing a 12 year old needs is a complicated build toolchain.

    • Everybody needs a build toolchain eventually, and learning it early saves the eventual "this webpage has become a 5000-line JS file and it's incredibly unwieldy to maintain" hassle with a more complicated project.

  • It's a program that fits in one screen and has 3 functions. No need for these trendy overcomplications.

    • The fact that it's dead simple is the point of the recommendation. It gives an opportunity to learn the tool with the bare minimum of moving parts involved.

      2 replies →

  • Of the things to learn when one is starting out, I would not put code modularisation and toolchains at the top of my list (especially for something so small).

    Additionally, this runs in Node, so you don't need to compile the source files with `parcel`.