Live data from Hacker News

How true hackers write JavaScript

news.ycombinator.com

211–220 of 342 posts

Re: How true hackers write JavaScript

#211
post #201

Write it with all the modern "proper" approaches, and good luck even just recompiling it in 10 years. While this code - however imperfect - remains just as maintainable today as it was when originally written (which is probably more than 10 years ago).

That's true if you're talking about using React, Vue, etc. but do you really think ES5 JavaScript is more likely to be supported in the future than ES6?

Re: How true hackers write JavaScript

#212
post #98

I don't understand why people are dissing this. It does what it's designed to do, and fills a specific need for one website. It's not there as a teaching aid, nor is it meant to be shared for other people to use elsewhere. Not everything has to be gold-standard code full of perfect variable names, extensive comments and good whitespacing. If you have a day job that isn't primarily writing code, and/or you are likely…

> As long as the code works, anything else is just gravy. Nonsense. Maintainability almost always matters. As the adage goes: code shouldn't merely work, it should clearly work. > If you were to peel back the layers on all the major websites out there, I'm sure you'd find less than stellar code everywhere. Indeed, but Sturgeon's Law shouldn't make us feel better.

In this particular case, the fact that the code is so terse makes it immensely more maintainable than a whole architecture + framework.

The HN code is meant to be understood as a self-contained piece, and that's contextually very different from most code out there.

Re: How true hackers write JavaScript

#213
post #211
post #201

Write it with all the modern "proper" approaches, and good luck even just recompiling it in 10 years. While this code - however imperfect - remains just as maintainable today as it was when originally written (which is probably more than 10 years ago).

That's true if you're talking about using React, Vue, etc. but do you really think ES5 JavaScript is more likely to be supported in the future than ES6?

I'm talking about NPM modules and the build toolchain (which consists of even more NPM modules). This stuff goes stale very quickly (at the 10-year scale). It's good for a project that is kept continuously alive (i.e. when there is a team of developers that is continuously making changes to the project), but not when the project sits on a shelf for 10 years and then needs to be modified.

Re: How true hackers write JavaScript

#214
post #137

Earlier quoted context omitted.

> It costs almost nothing more to write "event" instead of "ev" or "removeElement" instead of "remEl", but it makes the code much more readable. No, it doesn't. Unless you're an absolute beginner, it takes you a couple of seconds to realize that in this codebase, "ev" (or "evt" or even "e") means "event". The same goes for "remEl". If that's consistent, then it's not a big deal at all. Having less characters makes co…

Less characters really only makes sense in some scenarios, e.g. "unimportant" variables (for loops, temporary storage inside a procedure). Verbose 'variablesToKeepTrackOfPositionInThisLoop' is obviously pointless when 'i' will do. However renaming "important" things to make it quicker to read or type is, in my experience, a mistake if your code base is more than just a handful of files. Descriptive names make it much…

> Verbose 'variablesToKeepTrackOfPositionInThisLoop' is obviously pointless when 'i' will do

Based on a Fortran convention, IIRC. Within a web setting, "el" and "ev" are extremely conventional.

Re: How true hackers write JavaScript

#215
post #158

Way better than loading megabytes of .js just to display stupid animations and other useless gimmicky stuff. This file is just in consonance with this website's style: concise, terse, to-the-point and with minimal bs. Of all of my currently in-rotation news websites, this loads and reacts the fastest, no matter where I am or how crippled my current connection is. I am sure they are factoring load times and speed over…

I was at the bottom of Africa last month with unstable internet connection barely faster than dial-up. HN was the only site I could connect before getting timeouts and bs.

Re: How true hackers write JavaScript

#216
Everything has a context. If your site has:

  - minimal functionality
  - rarely if ever changes
  - is maintained by a very small group (Hacker News)
...then something like the example linked is perfect. Most web app developers don't live in this world. The more common situation is:

  - large and/or transient teams
  - large quantity of inter-dependent features
  - constant changes
...which means that the thing you need to optimize for isn't pretty/fast code. It's clarity and resiliency in the code. Can a junior and senior dev both work on the same code base? Can someone new to the project be effective with minimal ramp up time? Can you work on a feature without accidentally stepping on another persons current task?

Modern web apps are less about being performant and minimal, and more about dealing with the complexities of large software teams

Re: How true hackers write JavaScript

#217
I feel like this was written in this particular style assuming it was not going to be minified. I think it's ok to use this style if only maintained by a couple of people, or for a small project like this. I do like it's conciseness, but I don't feel the title is appropriate.

Re: How true hackers write JavaScript

#218
we are way overdue for a source code and architecture evolution history here. the way this started as a toy and exploded without any noticeable performance problems shpuld be a good case study.

Re: How true hackers write JavaScript

#219
post #207

Earlier quoted context omitted.

This 100x times. There is very little code there . Any effort in trying to bring it up to modern webdev standards would likely make the code expand significantly, and that's not even counting the complexity of the deployment pipeline. This here, it's just 150 lines of plain code. It's not hard to work with something like this.

I'm not saying a rewrite is necessary at all, but refactoring this code to use more modern standards would NOT increase the line count at all, my guess it it might cut it by 15%+ in total size if you leveraged the beautiful builtin functions. Compare these: function addClass (el, cl) { if (el) { var a = el.className.split(' '); if (!afind(cl, a)) { a.unshift(cl); el.className = a.join(' ')}} } Could turn into somethi…

el.classList isn't supported by IE < 10

Re: How true hackers write JavaScript

#220
post #219
post #207

Earlier quoted context omitted.

I'm not saying a rewrite is necessary at all, but refactoring this code to use more modern standards would NOT increase the line count at all, my guess it it might cut it by 15%+ in total size if you leveraged the beautiful builtin functions. Compare these: function addClass (el, cl) { if (el) { var a = el.className.split(' '); if (!afind(cl, a)) { a.unshift(cl); el.className = a.join(' ')}} } Could turn into somethi…

el.classList isn't supported by IE < 10

And is it accurate to describe IE < 10 as "more modern"?
Post reply on HN