News for hackers. Stuff that matters.
Re:Show HN: I'm 12, learning JS, and wrote Wolfram's cellula... by scottmf on Wednesday August 29, 2018 @04:43PM (#17871820)
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!

Re:Show HN: I'm 12, learning JS, and wrote Wolfram's cellula... by noobermin on Wednesday August 29, 2018 @04:56PM (#17871941)
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.
Re:Show HN: I'm 12, learning JS, and wrote Wolfram's cellula... by sb8244 on Wednesday August 29, 2018 @05:24PM (#17872194)
I second this. Knowing why something is better to use is most likely learned through doing it a worse way first.
Re:Show HN: I'm 12, learning JS, and wrote Wolfram's cellula... by vram22 on Wednesday August 29, 2018 @05:40PM (#17872314)
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 cellula... by dnadler on Wednesday August 29, 2018 @06:16PM (#17872555)
>...sometimes don't like it if such suggestions are made

I'll admit to occasionally being frustrated by comments like this. It's important to remember that not everyone is looking to learn. Sometimes, they just need to get something done ASAP.

It's a bit idealistic to assume that everyone has time to learn the canned solution. The real world doesn't always allow for that.

Re:Show HN: I'm 12, learning JS, and wrote Wolfram's cellula... by vram22 on Thursday August 30, 2018 @11:20AM (#17877434)
True. I did not mean it as an absolute statement. I did say above:

>I sometimes try to implement

It's each person's call, on a case-by-case basis. Had just shared my view with that newb, thinking it might help him.

Re:Show HN: I'm 12, learning JS, and wrote Wolfram's cellula... by pvorb on Wednesday August 29, 2018 @06:28PM (#17872624)
Sure, but it's still a valid advice that might be helpful to others.
Re:Show HN: I'm 12, learning JS, and wrote Wolfram's cellula... by taneq on Thursday August 30, 2018 @12:10AM (#17874033)
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.
Re:Show HN: I'm 12, learning JS, and wrote Wolfram's cellula... by dolessdrugs on Thursday August 30, 2018 @09:46AM (#17876639)
And yet, we also have nearly-infinite number of (reinvented) wheels...

Humans are the worst

Re:Show HN: I'm 12, learning JS, and wrote Wolfram's cellula... by crooked-v on Wednesday August 29, 2018 @04:49PM (#17871889)
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.

Re:Show HN: I'm 12, learning JS, and wrote Wolfram's cellula... by throwaway2016a on Wednesday August 29, 2018 @05:13PM (#17872104)
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.
Re:Show HN: I'm 12, learning JS, and wrote Wolfram's cellula... by crooked-v on Wednesday August 29, 2018 @05:35PM (#17872280)
> 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 cellula... by rickycook on Wednesday August 29, 2018 @06:14PM (#17872536)
current projects are a lot easier if you can use modern syntax that will eventually be supported in future projects, and which can be transpiled in either way
Re:Show HN: I'm 12, learning JS, and wrote Wolfram's cellula... by erikpukinskis on Wednesday August 29, 2018 @04:55PM (#17871935)
Good tips if you want your code to fail randomly on older devices.
Re:Show HN: I'm 12, learning JS, and wrote Wolfram's cellula... by Varcht on Wednesday August 29, 2018 @05:00PM (#17871985)
Older devices running node?
Re:Show HN: I'm 12, learning JS, and wrote Wolfram's cellula... by ateesdalejr on Wednesday August 29, 2018 @05:03PM (#17872012)
Surprisingly there are some embedded developers who use Node. I would assume those devices have a trimmed version of the Node stdlib.
Re:Show HN: I'm 12, learning JS, and wrote Wolfram's cellula... by ascorbic on Thursday August 30, 2018 @01:43AM (#17874333)
I'm sure when he ports it to Espruino he can handle Babel.
Re:Show HN: I'm 12, learning JS, and wrote Wolfram's cellula... by coldtea on Thursday August 30, 2018 @09:11AM (#17876368)
Not even businesses doesn't (and shouldn't) care for older devices when it doesn't make economic sense -- even less so a fun learning project.
Re:Show HN: I'm 12, learning JS, and wrote Wolfram's cellula... by scottmf on Wednesday August 29, 2018 @05:31PM (#17872247)
The code would fail to run on older devices without transpiling wnyway.