Live data from Hacker News

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

bitbucket.org

91–100 of 304 posts

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

#91
post #58

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 u…

Good tips if you want your code to fail randomly on older devices.

The code would fail to run on older devices without transpiling wnyway.

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

#92
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.

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

#93

Earlier quoted context omitted.

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 s…

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.

> This project explicitly says Node.

While that's true, future projects are a lot easier if one doesn't have to keep re-referencing "what works in Node" vs "what works on the web".

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

#96
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??

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

#97
post #90

Earlier quoted context omitted.

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.

I second this. Knowing why something is better to use is most likely learned through doing it a worse way first.

I third this. Speaking from personal experience. I sometimes try to implement the logic of some library or algorithm myself, even if I know there is well-known or canned solution for it. For the same reason as you and your parent comment said.

Interestingly, some people (typically newbies who are looking for rewards without commensurate effort. but others too) do not think that way, and even sometimes don't like it if such suggestions are made. I once made such a suggestion to a poster (an obvious newb) on comp.lang.python. He asked how to do some small task in Python. I suggested that he may learn more if he tried it on his own first. He misunderstood the intention behind the advice, and made some comment to the effect that my idea was not helpful, or something like that. Another regular pitched in and pointed out that my comment was meant in the spirit of helping him learn better, because a) if you try it yourself first and do get a solution, you just got better at something, and it will boost your confidence, and b) even if you do not get a solution, you will learn that the thing is not as easy or trivial as you thought (or why were you asking in the first place, except if wanting others to do your work for you) (which would happen if you just blindly used some library to do it). And will gain a new respect for the depth of your profession and all that it entails.

Related: How To Ask Questions The Smart Way:

http://www.catb.org/esr/faqs/smart-questions.html

It's by Eric Raymond, author of The Cathedral and the Bazaar and The Art of Unix Programming.

There are many interesting points in that article, e.g.:

http://www.catb.org/esr/faqs/smart-questions.html#noprivate

Seen people ask for private replies. IMO some of them do it because either a) they don't want to be seen as not knowing the thing if it was obvious, or b) not wanting others (likely their peers) to get the answer too. Both not good.

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

#98

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 readab…

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

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.

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

#99

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...

Post reply on HN