News for hackers. Stuff that matters.
Re:Old Code Gets Younger Every Year by joekrill on Monday June 08, 2020 @05:01PM (#23460754)
This sounds like the sort of thing I hear from folks who have only passively dealt with the Javascript ecosystem but somehow still seem to think they have a really great handle on the entire situation, how it got there, what exactly the root of the problems are, and (sometimes) how it can be fixed.

And while I partially agree in some cases, I don't think this is in any way a problem specific to the JS ecosystem. There is definitely a lack of quality in a whole lot of JavaScript code out there. But I've also seen TONS of horribly written Ruby gems, .Net libraries, Java apps, even Dockerfiles.

It is just much more prevalent when those ecosystems are still "maturing" - which I think JS, Node, NPM, etc still very much are. Even the early Android days were plagued with tons of horrible options for networking libraries, SQLite helpers, or whatever else wasn't fleshed out well. And that was just the _platform_ maturing with a language that was already quite mature. With JS you have not only the language itself maturing and changing rather quickly, but also all the underlying platforms, package management systems, security issues, etc.

Patterns, best practices, and standards often take quite a while to surface and become established. And they seem so obvious in hindsight! Which is why I think we get a lot of people coming from other ecosystems who seem to have selectively forgotten about that happening in their own established tech niche.

Re:Old Code Gets Younger Every Year by kerkeslager on Monday June 08, 2020 @09:16PM (#23462618)
> This sounds like the sort of thing I hear from folks who have only passively dealt with the Javascript ecosystem but somehow still seem to think they have a really great handle on the entire situation, how it got there, what exactly the root of the problems are, and (sometimes) how it can be fixed.

Never in the last 11 years have I not been professionally developing JavaScript to some degree, and I fully stand by what was said in the post above.

> It is just much more prevalent when those ecosystems are still "maturing" - which I think JS, Node, NPM, etc still very much are.

Then why are things getting worse?

> Patterns, best practices, and standards often take quite a while to surface and become established.

The best practice for JavaScript at this point is to use the few good libraries (in most cases, that's literally only React) and beyond that, do as little in JavaScript as you can to minimize its impact on your system. User experience comes before everything, so that means you still have to do a lot of JavaScript.

Re:Old Code Gets Younger Every Year by tashoecraft on Monday June 08, 2020 @09:27PM (#23462686)
It's very limited to think that the user experience comes before everything. If I focus purely on the user and not my business I don't have a business. If I do something good for the user experience but in fact breaks the law, then I am no longer in business. The user is incredibly important, but it's all a balancing act of resources and where to dedicate them.
Re:Old Code Gets Younger Every Year by kerkeslager on Monday June 08, 2020 @09:49PM (#23462832)
If your business doesn't serve its users, I am not particularly concerned that you don't have a business.

Its my impression that most relevant laws are geared toward protecting users from businesses, but I'd be open to hearing if you know of any exceptions (GDPR isn't one--secretly collecting data on users without their consent isn't serving users, it's harming users).

Re:Old Code Gets Younger Every Year by tashoecraft on Monday June 08, 2020 @10:06PM (#23462926)
User experience is a broad term. People here generally think of speed, but in fact that can actually result in a worse user experience. I believe users react better to a loader that takes longer for certain tasks like calculating tax returns because they like to think the computer worked hard to get the best result. It’s not always black and white.

I have had to implement features that are awful for the users, but are required by law to have. Others to protect the business from liability.

I’m not saying doesn’t serve users as the original comment was “user experience” and was specifically mentioning JavaScript in terms of a presumably slow site. User experience is many things and all of them need to be considered. I totally agree that sites have gotten way to bloated, but the js community is recognizing that and trying to work on it, lazy loading and improvements to module bundling are going to help. I think the craze of tiny packages is coming to an end. Libraries post proudly when they have zero dependencies. As the community evolves it’ll improve, though some sites will probably continue to get worse as higher ups demand more features.

Re:Old Code Gets Younger Every Year by kerkeslager on Wednesday June 10, 2020 @08:16AM (#23476243)
> I believe users react better to a loader that takes longer for certain tasks like calculating tax returns because they like to think the computer worked hard to get the best result. It’s not always black and white.

This is a concern with creating the impression that you're serving the user, rather than actually serving the user.

> I have had to implement features that are awful for the users, but are required by law to have. Others to protect the business from liability.

This is basically what you said in the previous post, and remains lacking in concrete examples.

Re:Old Code Gets Younger Every Year by marvy on Tuesday June 09, 2020 @01:03AM (#23463813)
> awful for the users, but are required by law

I am really curious what sort of law does this. (Though maybe I'm better off not knowing...?)

Re:Old Code Gets Younger Every Year by orange8 on Monday June 08, 2020 @11:26PM (#23463369)
> Never in the last 11 years have I not been professionally developing JavaScript to some degree

I know a designer who has also been professionally developing JS to some degree for over 15 years. Still very much a JS novice.

The terms "passively dealt with the Javascript" and "to some degree" sound like the same thing to me.

Re:Old Code Gets Younger Every Year by no_wizard on Monday June 08, 2020 @09:46PM (#23462803)
How’s it getting worse, exactly? I must admit I am intrigued by this contrarian view Than the average, but this feels light in specifics so I don’t have any way to address it on a point by point basis. Could you elaborate your positions here?
Re:Old Code Gets Younger Every Year by kerkeslager on Monday June 08, 2020 @10:09PM (#23462939)
Classes: JavaScript developers couldn't be arsed to learn prototypical inheritance, so they added class-based inheritance. Except they didn't really--classes in JavaScript are just an abstraction built around prototypical inheritance. So now you have to understand prototypical inheritance to understand how the class abstraction leaks. It's fewer lines of code, but it brings in a bunch of implicit complexity.

Promises: this is just syntactic sugar around callbacks, and does nothing to address the underlying problems of why callbacks were painful. It does introduce two ways of doing the same thing though, so now if you want to write any sort of abstractions you have to handle both ways.

Leaning hard into global frameworks that actively resist reusability and composition: Angular, Ember, etc. just start from the assumption you're writing an SPA. React is a rare gem of an exception, and is an awesome project, but there you have Flux/Redux/etc. trying to turn every React App into an SPA. This is probably the clearest example of JS projects being unsustainable: if you sacrifice reuse and composability in order to have a framework that does a lot for you, that lets you spin up projects quickly, but the project will slowly grind to a halt. React projects are great as long as you can fight the fight to keep Redux et al out, but eventually Redux fanboy gets it in and it quickly consumes your project. Global state is bad, folks. And don't tell me about reducers: I know, and if you think that means there isn't global state, that's only because you don't understand what global state and/or reducers are. I also am not interested in hearing about the other library you use to clean up your Redux code--instead of piling on more libraries to fix the problems you introduced, don't introduce the problems in the first place.

Re:Old Code Gets Younger Every Year by csnover on Tuesday June 09, 2020 @12:10AM (#23463562)
The classes thing is even worse than what you are describing since it is the only way to create correctly functioning sub-types of built-ins (e.g. `Error`). So not only is it still syntactic sugar for prototype-based inheritance for most things, there are also these edge cases where there’s actually no fully functional prototype-based equivalent.
Re:Old Code Gets Younger Every Year by no_wizard on Tuesday June 09, 2020 @12:03AM (#23463523)
So, I see small bits here, that all boil down to developers not understanding enough about their language of choice. The web being the vast platform that it is and JavaScript eating so many domains may very well be a situation where not having full mastery of a language will still get you very far perhaps - which says a ton of positive about the platforms imo- but that’s the heart of what I’m seeing here.

So, perhaps the issue Heyer is lack of education, not that the ecosystem itself is unquestionably broken?

Also, curious, how do you handle state full actions without some kind of global? Genuinely curious

Re:Old Code Gets Younger Every Year by kerkeslager on Wednesday June 10, 2020 @11:48AM (#23478424)
> The web being the vast platform that it is and JavaScript eating so many domains may very well be a situation where not having full mastery of a language will still get you very far perhaps

Sure, it gets you into a project far enough to commit a lot of resources to it, and then falls over.

> So, perhaps the issue Heyer is lack of education, not that the ecosystem itself is unquestionably broken?

The problem may be a lack of education, but that becomes a problem with the ecosystem when the uneducated are determining the direction of the language. Classes are a feature of JavaScript now: that's irreversible damage done to the language. We can educate people about prototypical inheritance and explain to them why hacking classes over top of them is a bad idea, but that's too little too late: we can't remove classes from the language because there's already too much code that depends on them. And we can't even add classes into linters and say "don't use them", because as another commenter pointed out, core language features now depend on it. At this point, we have to embrace the suck.

And there's a fundamental opposition in the JS community to education. Education starts with admitting you don't know something, and you can see in this thread a lot of people jumping in to defend the JS ecosystem. But the type of defenses you see are telling: instead of discussing the technical merits of the decisions made, people are shooting the messenger[1] or taking it personally[2]. The only defense of JS that's vaguely technical is brundolf's post, which isn't so much a defense of JS as a strategy for writing good code in a crappy language. Not a single post here is actually defending the JS ecosystem on technical grounds.

> Also, curious, how do you handle state full actions without some kind of global? Genuinely curious

Let's say you are writing a configuration interface for virtual servers. You have three attributes on sliders bars: memory units, CPUs, and solid state drives. There's also a total cost field. The Redux global state way looks something like:

1. Have the CPUs, Memory Units, SSDs, and Total Cost in a global store.

2. Create 3 actions and corresponding reducers that update the Total Cost when any of the slider bars change.

3. Create 3 slider bar components, which dispatch to the global store with the proper actions.

4. Create a base component that renders the whole thing.

This approach already runs into some problems:

1. First, you've got three slider components that are basically the same. You can pull out the rendering code into a Slider superclass, and that reduces the repetition, but your reusability is limited: every time you want to add a slider elsewhere in the app you have to write a whole new component. And when you look at those components, you've got a lot of implicit code being pulled in by the superclass, which means you have to switch between the component and the supercomponent to understand what's going on.

2. Your reducers operate on changes in different pieces of data, but ultimately each all have to know about all three data sources to calculate the total. You can check out "Reusing Reducer Logic"[3] and that's certainly a better idea than repeating yourself three times, but you can see that there's a complexity explosion happening here.

3. In actuality, what happens too often is the duplication is just left in the three slider classes, and you have three reducers since reuse is too complex. Even if you're very disciplined about it, the complexity of achieving reuse sometimes mean you don't have time or energy to do it. In short: this design punishes reusability and rewards duplication.

4. If you want to have multiple private servers, you now have to change literally every single one of these components, because every single one needs to know in some way which server it's operating on.

Let's design the same functionality, without Redux:

1. Have a slider component which accepts a min, max, initialValue and onValueChanged callback as props.

2. Have a parent component that holds the three values in its state, and renders the three sliders with onValueChanged callbacks that update the parent component's state. The total can be rendered without being stored in state, but if you want to have multiple servers on the page, you might want to put the total in state.

At first glance, each of these components is slightly larger, and it seems annoying to have to pass all the info into the slider components. But consider the benefits:

1. All your server state is in one place. No one else stores information on servers, and nowhere else even knows that servers exist. It's decoupled.

2. Because of this decoupling, the slider is a reusable component. You can use the same slider to modify literally anything with a min/max/value, favoring composition over inheritance[4].

3. The only thing you have to understand here is React components. The complexity is greatly reduced.

4. If you want to have multiple servers on the page, the parent component is already most of the way to being a reusable component. All you have to do is expose props for the initial server configuration, and an onServerChanged handler. There's one gotcha here: changes to the sliders need to propagate up to the parent of the parent component and still trigger the proper events and re-rendering. Pitfalls can be avoided here by using an immutability library--I prefer Immer, but I imagine ImmutableJS can do the same things. You could even roll your own, since you really don't need much to handle this--a simple set of copy-on-write functions would be adequate, although they would stop being performant if your data structure gets more complex.

[1] "This sounds like the sort of thing I hear from folks who have only passively dealt with the Javascript ecosystem"

[2] "Almost every comment thread, regardless of topic, has someone shitting on front-end developers and it's extremely demoralizing."

[3] https://redux.js.org/recipes/structuring-reducers/reusing-re...

[4] https://en.wikipedia.org/wiki/Composition_over_inheritance

Re:Old Code Gets Younger Every Year by no_wizard on Thursday June 11, 2020 @06:50PM (#23494064)
Just to say, I was taking a neutral position on this, genuinely not trying to get caught in the lack of details I was seeing in the back and forth, so I appreciate the detailed response.

I'll say this with redux: precisely. You can achieve reusability if you build with that in mind, but even fresh projects I've seen get caught at some point on duplicating code irresponsibly here. The fact that they didn't just make this a core part of the redux experience - I'm referring to the abstraction they use in the example on the page named `createNamedWrapperReducer` specifically - to simply allow you to pass a unique identifier you can associate with a component (which it could then offload from the state container if the component is removed from the page, saving memory) or even requiring it as a prop (people might grumble, but it'd catch on regardless) would have been a much more effective way to do this. I'm shocked 5 version sin we don't have this as the default...leaving it up to the user to create a very basic abstraction around this just irks me, as I don't see how consumers benefit from that.

Yet, I don't want to create _yet another library_ since redux is so well entrenched. Internally where I used to work, we had a library that basically was just what I described. You specified a special prop on a component and any reducers were created from a factory that respected the prop, worked well enough.

Now, with that said, I have to say this:

I think JavaScript is a great language. I think TypeScript is an even better manifestation, despite some quirks.

Now, onto some technical bits.

Classes are more than just fancy wrappers on prototypical inheritance. The way its going with the standards committee, and the way I've interpreted the point of having classes, is to have formal encapsulation[0]. With things like the private fields & method proposal[1] already well on their way to formal standardization, classes are starting to make more sense. They also provide a way to extend builtins in a way the engine understands (This is also the logic behind Web Components I feel like everyone misses, but that's another story).

While I know there is plenty of object oriented pitfalls everyone has seen, like abuse of inheritance, I find that the very common pre-class way was just, if not more so, prone to pitfalls. Extending classes is pretty obvious to most programmers - I mean this in terms of syntax and typical expected behavior - I coded up a simple example here to illustrate just how gnarly ES5 "classes" are.

https://gist.github.com/ScottAwesome/67d2d10761bd4993eec9d9d...

I also think classes provide the correct abstraction for exposing public and private APIs, as I already mentioned the private fields and method proposal, but also its more conventionally straightforward to encapsulate this even using a WeakMap to make private methods/fields unexposed to the consumer, (one of its primary use cases when it was introduced). Plain objects, without some sort of system to manage their creation (like factories) and their visibility (Object.seal, Object.freeze, Object.preventExtension, Object.DefineProperty - all of which work on classes too, of course), they're otherwise going to leak their members and its all too easy to find private APIs on object members. I know you can with classses - sans using a WeakMap or the new private fields API. I find it feasibly easier however to integrate classes when I need to encapsulate a well defined interface with properties & methods, in large part because I can keep the private APIs private more easily, via an internal WeakMap, without sacrificing extensibility.

I know you can do this with objects, however its much more clear that you get a discrete instance with classes. When that sort of thing is important, I think classes are useful.

I also think there is a lot of value to the mixin pattern.

I also think this reaches into what most developers just expect out of a language. Arguably, the complete lack of usage of the Reflect[2] APIs I see in the wild and where I've worked tells me most people just don't reach for these kinds of APIs. Therefore from a language development point of view, I can't argue classes are bad, either.

Now I understand you can get there with plain objects, and I think this is an under-utilized mechanism of the language. In fact, I think the plain javascript object are amazing, and very few languages have such a powerful construct. I'm a big fan of composition over inheritance (to which end I have leveraged the stamp specification and its toolkit[3]. I think it would have been nice to see more specialty objects (with a static `Object` factory to create them) over having to just introduce classes. Alas, they are here to stay.

Truth be told, I don't use classes that often, preferring pure functions & plain objects most of the time, but sometimes there just isn't a better way to encapsulate behaviors than the a class, in fewer lines of code, that's easy to reason about and maintain.

Now one trend I don't like, is that a lot of things are becoming class only APIs (Web Components being a major one). This complicates things, but you can certainly 'hide' the implementation details via factories if you don't want to expose classes directly, so far in these cases, that's pretty straightforward to do.

Worth noting: I'm just not strongly opinionated enough to say you're right or wrong on this. We already acknowledged a massive education problem in the industry, one that, I will admit is in my personal experience seemingly true, that not enough people take the language serious enough to spend the time to learn how to work with it appropriately. Until that's solved, I don't think its worth fighting over other minutiae in this particular discussion. Solving the problem of good developer evangelism in the JS ecosystem is a discussion for another time, though, and one that will ultimately be futile if we can't get the major stakeholders to have some agreement on what that means.

[0]: https://en.wikipedia.org/wiki/Encapsulation_(computer_progra... [1]: https://github.com/tc39/proposal-private-methods#private-met... [2]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... [3]: https://github.com/stampit-org/stamp-specification

Re:Old Code Gets Younger Every Year by vlovich123 on Monday June 08, 2020 @05:29PM (#23461029)
That could be the case. It could also be the case that those deeply rooted in the Javascript ecosystem aren't listening to domain experts.

The numerous security problems with how NPM installs dependencies was pointed out as problematic from the get go by language maintainers, package manager maintainers, & security experts from other projects.

I think it's possible that Javascript is getting better & more responsive here & I bet at least some of the defensiveness was that it has also been unfairly criticized which makes it hard to separate signal from noise.

Re:Old Code Gets Younger Every Year by brazzy on Monday June 08, 2020 @05:34PM (#23461053)
> It is just much more prevalent when those ecosystems are still "maturing" - which I think JS, Node, NPM, etc still very much are. Even the early Android days were plagued with

Node is about half a year younger than Android, and npm another half year. Javascript is, of course, over a decade older.

If JS, Node, NPM, etc is "still maturing" after all that time, then that is a pretty strong indication that there is something wrong with that ecosystem.

Re:Old Code Gets Younger Every Year by hombre_fatal on Monday June 08, 2020 @07:00PM (#23461720)
You compare it to Android as if Android dev isn't full of its own problems. Here is some Android complaints that I agree with from the other day: https://news.ycombinator.com/item?id=23438732

Android is definitely still maturing. So is iOS/macOS dev.

I guess client development isn't as easy as we told ourselves.

Re:Old Code Gets Younger Every Year by joekrill on Monday June 08, 2020 @06:01PM (#23461300)
It's not a scenario where you can look at "absolute years from inception". It's all relative. With the JS ecosystem, you have rapidly changing Web APIs and standards, varying degrees of browser support and Node versions. And no real "central authority" to guide things in a specific direction. With Android you have a much more managed platform, with Google providing at least some guidance on best practices (explicitly or not). I'm sure the recent introduction of Kotlin added some complexities and confusion to that system. But I still don't think things are changing as rapidly as they are in the JS world, and from so many different angles.
Re:Old Code Gets Younger Every Year by kerkeslager on Monday June 08, 2020 @09:37PM (#23462753)
> With the JS ecosystem, you have rapidly changing Web APIs and standards, varying degrees of browser support and Node versions. And no real "central authority" to guide things in a specific direction.

All of these (except Node versions) are constraints of the original problem domain: running user interface code in a browser. These are unavoidable for client-side Javascript.

But these are not constraints of server-side or command line code, so it's absurd to write server-side code under these constraints. Server-side JavaScript should not exist. Command line utilities written in Javascript should not exist.

What part of using having a bunch of completely different ways to bind to events to read a file makes any sense? https://stackoverflow.com/questions/9168737/read-a-text-file...

Re:Old Code Gets Younger Every Year by akiselev on Tuesday June 09, 2020 @02:02AM (#23464124)
> But these are not constraints of server-side or command line code, so it's absurd to write server-side code under these constraints. Server-side JavaScript should not exist. Command line utilities written in Javascript should not exist.

This is a myopic view entirely disconnected from reality. The purpose of code isn't to be perfect or pretty, its purpose is to do useful work. The most relevant constraint is always available resources which is dominated by human capital and experience. Productivity is measured using useful output, not code quality.

> What part of using having a bunch of completely different ways to bind to events to read a file makes any sense?

The part that puts food on the table. I can't name a single language I have any experience with that has One True Way™ of binding to events except for C and assembly which can only pass callable pointers around.

Re:Old Code Gets Younger Every Year by kerkeslager on Tuesday June 09, 2020 @09:52PM (#23473039)
> The most relevant constraint is always available resources which is dominated by human capital and experience.

Which is why it's particularly puzzling that JavaScript community ignores vast swaths of human capital and experience. Global state? Awesome! Principle of least astonishment? For the birds. Caring about security of your dependencies? What on earth for?

> Productivity is measured using useful output, not code quality.

Useful output is strongly correlated with code quality, and that correlation grows stronger as a project grows.

> The part that puts food on the table.

Sure, my billable rate is the same no matter what language I'm writing and if that's all you care about, okay I guess. But I've rewritten a server-side JavaScript application in Python, and my clients wouldn't hesitate to say that they got more for my billable hours than they did for the team of three JavaScript developers who wrote the original application.

> I can't name a single language I have any experience with that has One True Way™ of binding to events except for C and assembly which can only pass callable pointers around.

You need to take a bigger step back to understand what I'm saying. It's not about having One True Way, it's about keeping your code simple enough that you can read it when you come back to it a year later, you can break it into composable chunks, and reuse it. Every one of the ways on the page I linked forces you to think about an event loop in a process that's fundamentally procedural. It's fundamentally the wrong abstraction for the situation, but JavaScript literally can't represent a better abstraction.

Re:Old Code Gets Younger Every Year by mgkimsal on Tuesday June 09, 2020 @08:59AM (#23466253)
I don't think the GP was saying JS is bad because there's not 'one true way' to read from a file. I think the GP was saying it's bad because we're trying to get it to read from a file in the first place. ('Server-side JavaScript should not exist')
Re:Old Code Gets Younger Every Year by halostatue on Tuesday June 09, 2020 @01:21PM (#23468627)
SSJS has existed more or less from the beginning of JS.

https://docs.oracle.com/cd/E19957-01/816-6410-10/816-6410-10...

Any general purpose language will be used in ways and places that it was not expected to be used. Both Netscape and MS offered some level of SSJS, and MS added a JScript Windows Script Host.

Re:Old Code Gets Younger Every Year by bena on Monday June 08, 2020 @07:46PM (#23462071)
I mean, if Javascript is eternally stuck in a state of "still maturing" or it's environment make maturation take much longer than other ecosystems, then wouldn't that make it just a bad ecosystem?
Re:Old Code Gets Younger Every Year by hinkley on Monday June 08, 2020 @06:08PM (#23461353)
npm is not 'maturing'. It is now regressing.

There is no spec, there is no feature list, and so patches keep breaking behavior and then it gets declared as being on purpose.

I am using several flags for CD builds that are not documented on the npm page (or at least were not when I started using them).

If you are thinking of deflecting by talking about how maybe my builds are too complex then you can save your breath, because I don't want to hear it.

Tinker toy apps won't have any maintenance problems, aren't the sort of things you get paid to work on for years, can be replaced instead of mucked with. And quite frankly, bringing up happy path applications just dates you as a young developer with no field experience (or worse, an idiot).

Re:Old Code Gets Younger Every Year by brazzy on Tuesday June 09, 2020 @02:19PM (#23469182)
I think you replied to the wrong person.
Re:Old Code Gets Younger Every Year by rudolph9 on Monday June 08, 2020 @07:18PM (#23461847)
People seems to forget how many people program in JavaScript. Just because the average is low doesn’t mean there aren’t just as many really good ones out there as any other language. It might be common to have lots of dependencies but I can tell you gist hand you only need a few with a really shallow tree to build a full featured web app (both server and client).
Re:Old Code Gets Younger Every Year by koolba on Monday June 08, 2020 @08:05PM (#23462214)
It’s not just the average that’s low. It’s the median as well. There’s an incredible long tail of skill with JS and the related ecosystem.
Re:Old Code Gets Younger Every Year by kerkeslager on Monday June 08, 2020 @09:39PM (#23462761)
It's possible to write good code in bad languages.