News for hackers. Stuff that matters.
Re:Show HN: I taught my little brother JS, and he made this ... by quadcore on Wednesday January 09, 2019 @06:06PM (#18869943)
Look at the code guys [1]. I love it. This is simple. There is not a single line of bullshit. I hope he gonna become a great programmer and continue to make beautiful code like that.

[1] https://github.com/S-poony/Ultra-Square-Catcher-USC-/blob/ma...

Re:Show HN: I taught my little brother JS, and he made this ... by userbinator on Wednesday January 09, 2019 @06:20PM (#18870042)
Agreed. There are so many JS projects these days composed of a dozen abstraction layers and barely-used libraries all mixed together and spread out across multiple files with an insanely complex "build system" on top, that it's very refreshing to see simple, self-contained JS.
Re:Show HN: I taught my little brother JS, and he made this ... by beatgammit on Wednesday January 09, 2019 @08:05PM (#18870649)
You don't need complexity until you do.

Our company needed an internal tool, and they wanted remote access to it, but it was basically just a tool to generate a file based on a few inputs. We already had a command line program for it, so I wrapped it up in a web server and had it take input as a form input without any JS. It worked great for years, and then someone got tasked with updating it (mostly just combining it with other tools). He couldn't figure out how it worked, so he rewrote it to use a ton of JS, using Angular and other stuff. And guess what? He took longer to rewrite it than I spent the first time and made no functional changes besides some CSS and a ton of JS.

With all these fancy new frameworks and browser features, it seems that many developers have forgotten (or never learned) how to do things simply. Frameworks and browser features have their place (I built an interactive HTML5 app as my first project at that company), but they're often completely unnecessary.

Re:Show HN: I taught my little brother JS, and he made this ... by jb3689 on Wednesday January 09, 2019 @10:27PM (#18871271)
To be fair, in my experience rewrites always take longer regardless of technology choices. You are often reverse engineering requirements which is really consuming both in time and energy. That said, I agree with the point you're trying to make though (I strongly prefer software with less dependencies/frameworks)
Re:Show HN: I taught my little brother JS, and he made this ... by akuji1993 on Thursday January 10, 2019 @02:25AM (#18872146)
Also, he apparently had to update / upgrade the application, so it's kinda to be expected that he will take longer for this.
Re:Show HN: I taught my little brother JS, and he made this ... by kennybomber on Saturday January 12, 2019 @01:40PM (#18892583)
Yes one should assume most frameworks will be dead 2 years from now. Dependencies problems suck. And create security holes. When development starts going into the cloud get ready for a lot of pain the world has never seen before.
Re:Show HN: I taught my little brother JS, and he made this ... by tracker1 on Friday January 11, 2019 @04:22PM (#18887184)
It depends on your needs... Are you building a complex application with several developers. You probably want a build system and module based JS. I prefer react + redux + material-ui. Some of the new stuff around hooks and context could displace redux for smaller apps easily.

If you need a one-off page that does a little dynamic stuff? Drop in jquery+bootstrap and a little wiring js and be done with it. Not a huge fan of the size of jquery + bootstrap, but it's a fast path to done depending on your one-off needs.

Re:Show HN: I taught my little brother JS, and he made this ... by jianzong on Wednesday January 09, 2019 @09:47PM (#18871114)
My brain hurts just imagining this.
Re:Show HN: I taught my little brother JS, and he made this ... by croh on Wednesday January 09, 2019 @11:24PM (#18871508)
Mine too
Re:Show HN: I taught my little brother JS, and he made this ... by apo on Thursday January 10, 2019 @12:50AM (#18871813)
Really well done and I like the brevity. Here are some ideas for revising the code:

1. There are two functions called "distance" and they're identical. Only the outermost appears to be needed.

2. As written, the game places variable and function names into the global scope. It doesn't matter for this game, but will be a problem for larger games. One idea would be to use the Immediately Invoked Function Expression (IIFE) pattern [1]. Another would be to take advantage of ES6 modules[2] (<script type="module">) to limit variable scope.

[1] https://developer.mozilla.org/en-US/docs/Glossary/IIFE

[2] https://www.contentful.com/blog/2017/04/04/es6-modules-suppo...

Re:Show HN: I taught my little brother JS, and he made this ... by tim1994 on Thursday January 10, 2019 @02:40AM (#18872203)
Also never use Math.pow for squaring numbers (used in the distance function) because it is significantly slower as it is designed for abitrary real exponents, not just integer ones. Cannot be learned soon enough IMO :)

Still a very good job for just a week of coding though.

Re:Show HN: I taught my little brother JS, and he made this ... by fenomas on Thursday January 10, 2019 @06:56AM (#18873222)
> Also never use Math.pow for squaring numbers (used in the distance function) because it is significantly slower...

Modern JS engines optimize hot functions at runtime - advice like this won't affect actual performance.

Re:Show HN: I taught my little brother JS, and he made this ... by ghusbands on Thursday January 10, 2019 @09:47AM (#18874170)
This advice is incorrect. Experimenting in the console in both Firefox and Chrome shows that there's not a significant speed difference between the two, even if you make sure you only call a given function with integers <10000.
Re:Show HN: I taught my little brother JS, and he made this ... by tim1994 on Thursday January 10, 2019 @10:47AM (#18874654)
On my laptop it is about 30% slower (tested with Firefox 64). However I agree, this was not very good advice for someone who just started programming with JS...
Re:Show HN: I taught my little brother JS, and he made this ... by therein on Thursday January 10, 2019 @06:12AM (#18873037)
Definitely great job. Reminds me of when I taught my physicist friend C and he wrote a raytracer and a game to demo it the next day. I had never witnessed so many trig functions used on a global context.
Re:Show HN: I taught my little brother JS, and he made this ... by Sean1708 on Thursday January 10, 2019 @06:46AM (#18873178)
Does the JS JIT not handle this? Seems like it would be incredibly trivial...
Re:Show HN: I taught my little brother JS, and he made this ... by johnwyles on Thursday January 10, 2019 @02:52AM (#18872251)
Fork it and submit him a PR!
Re:Show HN: I taught my little brother JS, and he made this ... by sbov on Wednesday January 09, 2019 @07:59PM (#18870615)
But what if he wanted to turn it into a AAA FPS game with RTS elements in a persistent online world that supports millions of simultaneous users?
Re:Show HN: I taught my little brother JS, and he made this ... by nurettin on Thursday January 10, 2019 @12:25AM (#18871739)
That was the next logical step during the early 2000s. Every bright-eyed college freshman on IRC was "recruiting" for his next awesome MMORPG idea.
Re:Show HN: I taught my little brother JS, and he made this ... by skocznymroczny on Thursday January 10, 2019 @02:41AM (#18872208)
It's still a thing. On gamedev forums and subreddits you still have people assembling a team. Of course he can't do any programming, he's only an idea guy and needs 5 programmers, 3 writers, 7 artists etc.
Re:Show HN: I taught my little brother JS, and he made this ... by kungtotte on Friday January 11, 2019 @01:43AM (#18881480)
No he can't pay you anything, you'll get shares in the company which eventually will be worth gazillions because the idea is so good.
Re:Show HN: I taught my little brother JS, and he made this ... by baud147258 on Thursday January 10, 2019 @05:29AM (#18872832)
No, right now it's the RPG elements that are trendy, RTS is soooo 2000.
Re:Show HN: I taught my little brother JS, and he made this ... by crooked-v on Thursday January 10, 2019 @03:48PM (#18877980)
RPGs are soooo 2016. The current thing is battle royale games.
Re:Show HN: I taught my little brother JS, and he made this ... by baud147258 on Friday January 11, 2019 @04:52AM (#18882169)
Touché. Between CoD, CS and BattleField, it's quite true.

I was more thinking of Assassin's Creed and Far Cry when I wrote that comment.

Re:Show HN: I taught my little brother JS, and he made this ... by cududa on Wednesday January 09, 2019 @08:35PM (#18870776)
If you're not joking and actually making that statement seriously you need to close your computer and go take a few hour walk.
Re:Show HN: I taught my little brother JS, and he made this ... by MetalGuru on Wednesday January 09, 2019 @09:55PM (#18871137)
He’s joking.
Re:Show HN: I taught my little brother JS, and he made this ... by finaliteration on Wednesday January 09, 2019 @07:48PM (#18870561)
My only complaint is the global scope pollution with the top-level variables and lack of ‘var’ for those. But other than that, I agree.
Re:Show HN: I taught my little brother JS, and he made this ... by etatoby on Wednesday January 09, 2019 @10:22PM (#18871251)
That's a complaint about the JS language itself, that variables are global unless otherwise specified.
Re:Show HN: I taught my little brother JS, and he made this ... by finaliteration on Wednesday January 09, 2019 @11:38PM (#18871562)
I do agree it’s a complaint about the language. However, I think it does ultimately fall on the developer to know how to work with the language including the bad/ugly/awful parts. I also think not polluting the global scope is a pretty foundational thing to know or be aware of. It’s really easy to shoot yourself in the foot or have naming collisions/overwrites happen if you aren’t careful.

Another example would be memory allocation/freeing in a non-GC language. Sure, it’s a pain that I have to deal with it, but it’s still on me to make sure my application works in the language I’ve chosen and doesn’t leak memory all over the place.

Re:Show HN: I taught my little brother JS, and he made this ... by klyrs on Thursday January 10, 2019 @01:22AM (#18871937)
> However, I think it does ultimately fall on the developer to know...

This person has been programming for a week. I think we can let this slide

Re:Show HN: I taught my little brother JS, and he made this ... by test1235 on Thursday January 10, 2019 @09:20AM (#18873972)
Well, no - not if everyone's raving on about how great the code is. Code quality is objective, not dependant on experience.

I don't get to write crap code at my work if I'm inexperienced, I have to learn to write good code.

Re:Show HN: I taught my little brother JS, and he made this ... by nicoburns on Thursday January 10, 2019 @05:41AM (#18872884)
Feedback is pretty useful for new programmers though. It's how they learn!
Re:Show HN: I taught my little brother JS, and he made this ... by finaliteration on Thursday January 10, 2019 @12:01PM (#18875478)
I’m not at all saying they should be an expert after a week. But learning those things is part of being a software developer/programmer and I don’t think, “Well the language sucks” is a valid argument.
Re:Show HN: I taught my little brother JS, and he made this ... by ngcc_hk on Thursday January 10, 2019 @05:32AM (#18872850)
Great comment. Great comment.
Re:Show HN: I taught my little brother JS, and he made this ... by jeena on Wednesday January 09, 2019 @06:14PM (#18869993)
> There is not a single line of bullshit.

Don't want to be the killjoy here but isn't line 77-79 the same as 85-87? With the rest I can agree.

Re:Show HN: I taught my little brother JS, and he made this ... by lucisferre on Wednesday January 09, 2019 @06:19PM (#18870038)
I'm going to guess that isn't intentional.
Re:Show HN: I taught my little brother JS, and he made this ... by 11235813213455 on Wednesday January 09, 2019 @06:28PM (#18870099)
The mix between French and English variable names or comments is a bit irritating, even for as a French guy
Re:Show HN: I taught my little brother JS, and he made this ... by HighSaysBob on Wednesday January 09, 2019 @07:05PM (#18870329)
From the source, Shift = Brake
Re:Show HN: I taught my little brother JS, and he made this ... by Imagenuity on Thursday January 17, 2019 @01:59AM (#18928916)
You would never know this unless you read the source. It's unlikely that you'd stumble across it.
Re:Show HN: I taught my little brother JS, and he made this ... by natecavanaugh on Wednesday January 09, 2019 @06:24PM (#18870076)
As far as logic goes, I totally agree, but personal preference nit pick, from a code writer and reader perspective, I think all subproperty access (`hero.acceleration.x`) could be cached to a variable, or just operate on plain variables and assign property access after mutations and only manipulate objects as needed. It makes the code easier to write and read, IMHO, and I believe older engines had infinitesimal changes in performance with updating objects, so it's more of a habit and code clarity thing for me. Of course, that's far less important than the fact that the logic is clear and concise, especially after learning JS in a week :)
Re:Show HN: I taught my little brother JS, and he made this ... by tmdroid on Wednesday January 09, 2019 @07:17PM (#18870410)
He did the game in a week, not learn JS from what I understand from the title
Re:Show HN: I taught my little brother JS, and he made this ... by natecavanaugh on Wednesday January 09, 2019 @08:13PM (#18870671)
Ahh thanks for the clarification :)
Re:Show HN: I taught my little brother JS, and he made this ... by Satsana on Thursday January 10, 2019 @01:35AM (#18871978)
Sure, with a duplicate distance function and one 100-line function? For me that in itself is horrible lol. But as a new programmer he should still be commended but bro, give credit only to where its due. And here its the fact that he's new, not that the code is "beautiful". (You're making me doubt what you think of beautiful code, but i guess since he's your brother you're definitely biased.)