Earlier quoted context omitted.
It might be interesting to see an example of a comment that you (or anyone) thinks would add to maintainability. What isn't expressed in the code? If there is such information, there are two possibilities: either we could easily modify the code to express it; or we could not. Each would be interesting, but for different reasons.
It's probable that HN is so feature-frozen it's not worth doing at this point, but if it were not, there are a few good reasons. The parent's example in hideStory() is a good start: for (var i=0; i This way, if (for instance) someone were to try to modify the layout to use margins rather than spacers, or if someone were to strip whitespace from the rendered HTML, a quick search (or manual skim of the code when someth…
How true hackers write JavaScript
321–330 of 342 posts
Re: How true hackers write JavaScript
#322Maybe I'll respond in a general way to what's come up here. This code isn't unreadable, or accidentally readable—it was written specifically for readability. Similarly, it isn't unmaintainable or accidentally maintainable—it is written specifically for maintainability. Unlike in most programming debates, we can actually prove this. Here is the proof: I've talked to everyone whose job it has ever been to read this cod…
Re: How true hackers write JavaScript
#323Earlier quoted context omitted.
No, it is because some array-like objects like node lists actually aren't Arrays and don't have those functions in their prototype.
this is why I usually go for something like const $ = (el) => [...document.querySelectorAll(el)]
Re: How true hackers write JavaScript
#324Earlier quoted context omitted.
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…
The point I'm making is not "use short variables everywhere", it's that in this case , the verbose alternative is not "much more readable". Abbreviating "element" to "el" or using "attr" instead of "attribute" (etc.) can significantly reduce noise in web client code. Everybody either knows what it means, or they shouldn't be editing the code in the first place.
Re: How true hackers write JavaScript
#325I approve of those wrapper functions in the first few lines... those would have saved me so much time when I was a web dev I'd say I'm going to copy them next time but there is no license header...
const $ = (sel, elem = document) => [ ...elem.querySelectorAll(sel) ]
is nicer as you can use CSS selectors.Re: How true hackers write JavaScript
#326Criticisms and bizarre fawning over beauty that a couple of people have made aside, the one thing that bugs me the most is the inconsistent usage of ;
I should fix that, since sctb probably agrees with you and is too polite to say so. Any suggestions for me as a shitty semicolonist?
I prefer Standard JS, but either way it's easier to not need to think about the exact details IMO :)
Re: How true hackers write JavaScript
#327function $(id) { return document.getElementById(id); } Nice! Now I don't need jQuery.
https://gist.github.com/paulirish/12fb951a8b893a454b32
It let's you do
$('p').on('click', el => /* ... */)
which is handy for smaller scripts :)Re: How true hackers write JavaScript
#328While everyone's freaking out over the code I'm remembering the old code that was only 2 functions[0], which leaves me to believe this code was changed not too long ago. I wish we had a github or something of some of these front-end changes to HN just to see how things change over time. I figure it wouldn't be too much, but still. The original JS was inlined and contained two functions: hide and vote. [0] https://new…
We expanded it for collapsible comments a few years ago.
Re: How true hackers write JavaScript
#329Earlier quoted context omitted.
> Nonsense. Maintainability almost always matters. The last three large corporations I worked for never cared about maintainability because the application or portal would only be in use for maybe a year or 18 months before a complete rewrite or total redesign. All of the recent projects I've been on take the same approach. Get it stood up, make it look pretty and release it. Because agile development makes business…
the application or portal would only be in use for maybe a year or 18 months before a complete rewrite or total redesign Why on earth is this such a popular idea? Do customers somehow prefer to see all the buttons in new places and old urls broken every other year?
Now? I think newer technologies come out faster and capture people's attention. They want to use the new shiny thing. I think the "business people" want to have a big budget project to get recognition within large orgs. I think developers want to use the latest and coolest stuff. I think people feel like we already live in a disposable culture, why would our sites and apps be any different? You combine all of these and suddenly the pressure and inertia not to move or rebuild or redesign regularly is too much to overcome.
I still remember going to a ReactJS class and the guy running it kept saying, "Don't get me wrong, BackboneJS is still a hell of a library and is still relevant and awesome to build stuff with BUT React does a few things better."
This is where we are. Huge financial investments, time and energy to get a 3-5% bump in efficiency? Doesn't make sense to me.
Re: How true hackers write JavaScript
#330I'm not sure if this was linked fatously, but this is actually pretty good JS. - All functions - The functions are simple and decomposed into smaller functions - No usages of "this" (except one necessary one in an event handler) - No ham fisted attempts at doing OOP with JS Only complaints really are naming and code style is overly compact which would potentially make it harder to understand, but in this context I th…
should be using fat arrow functions.