News for hackers. Stuff that matters.
Re:Old Code Gets Younger Every Year by _bxg1 on Monday June 08, 2020 @04:23PM (#23460361)
> The primary reason for this is because the people writing JavaScript do not know what they are doing.

Hello. I'm a JavaScript programmer who cut my teeth on Java twelve years ago, followed by C++ two years later and throughout the course of my Computer Science program, and over the years I've done personal work in half a dozen other languages including Rust, Clojure, Python, C#, etc.

Despite all of that TypeScript remains by go-to general-purpose language of choice, for any arbitrary project without particular constraints.

Take your flame-bait elsewhere, please.

Re:Old Code Gets Younger Every Year by HeWhoLurksLate on Monday June 08, 2020 @05:02PM (#23460765)
It's always neat to read reasoned replies to comments like these.

> > The primary reason for this is because the people writing JavaScript do not know what they are doing.

I think GP has a point here, though- it feels (to _me_, someone with only a small amount of programming experience) that there are all too many beginner tutorials that jump straight into framework-of-the-week.js and that leave huge knowledge gaps- if people start with node.js and angular and and and and, they might not know that they can do xyz in a vanilla install of JS, thus making their core knowledge of the language dependent on a particular framework.

Re:Old Code Gets Younger Every Year by _bxg1 on Monday June 08, 2020 @05:09PM (#23460853)
I think there's some truth to this, but the same is true in, say, the Java world where you're almost not even writing things in Java-the-language, you're writing things in Spring. That said, it's probably more true in the JS world because it is so feasible to teach someone to make something in a JS framework before they know the fundamentals. Which is, honestly, an enormous compliment to the language, not an indictment! But it does come with some interesting side-effects.

I do feel the need to make one small correction (the OP actually made the same mistake): Node.js is not a framework, it is a runtime. If you want to run JavaScript the way you run Python, you use Node (or, very recently, an alternative called Deno). You also don't have to do anything special with your code to run it in Node, like you would with a framework, unless you want to use its system APIs which of course do not exist in the browser. But even those are really more like libraries.

But yes, your overall point is valid

Re:Old Code Gets Younger Every Year by Cthulhu_ on Tuesday June 09, 2020 @04:32AM (#23464856)
I personally (anecdotal) feel that the Java world is a lot more formal; there are some Strong Opinions held in what "good" Java code is, which is missing in Javascript. This is in part due to great books like Effective Java, and in part due to editor / IDE support that will warn you and help you write great code - keep in mind that good IDE support has been missing in Javascript for years because of its lack of support for e.g. modules or namespaces, and its lack of Opinions.

Java's community has been Opinionated, whereas the JS community has been a lot more freeform. JQuery and NodeJS have been very influential in adding an opinion to the language; jquery by adding a kind of namespacing and scoping (also thanks to its predecessors / peers like YUI), NodeJS by adopting a module system (CommonJS) and centralized dependency management (NPM).

I came into JS via Java and while the lack of standards and rules / expectations was liberating, I was also missing it. It took a while before the best practices of Java made it into Javascript; in my experience, AngularJS was a big push for that, in that it was a much more opinionated way to structure your components and application - with a strong emphasis on (unit) testability.

Re:Old Code Gets Younger Every Year by bobthepanda on Monday June 08, 2020 @07:07PM (#23461769)
This is mostly because there is not really a formal way of learning webdev, which is both a strength and a curse. JS's closest thing to a prescriptive and authoritative guide to do things is the MDN, which isn't very prescriptive at all; there's certainly nothing like the C programming book, or even contenders equivalent to something like a Headfirst Java book. If you want strong direction and strong opinions JS does not have an overly dominant one unless you pick something that starts off with its own ecosystem like React.

Asking for something on vanilla JS is like asking for an "original" English copy of the Bible, whatever that means.

Re:Old Code Gets Younger Every Year by bena on Monday June 08, 2020 @07:50PM (#23462097)
I think the inclusiveness of the statement is the issue. He didn't say "the majority of the people writing JavaScript", he implied all of them.

I'm sure there's a lot of people who are writing decent JavaScript. But running JavaScript is easy. Every single computer comes with a JavaScript development environment. Because all you need is a text editor and a web browser. The barrier to entry is so low it might as well be non-existent.

So a lot of people with no clue of what they're doing will get in there and write some atrocious code.

Re:Old Code Gets Younger Every Year by quickthrower2 on Monday June 08, 2020 @06:42PM (#23461598)
Vanilla JS for UI work is like using Windows Forms (the Microsoft tech from 2002 for building windows UI in .NET). Unless you want something pretty basic, you are going to be writing your own frameworks. Maybe not a bad thing from a learning perspective, but I'd prefer a battle tested framework in general.
Re:Old Code Gets Younger Every Year by jagged-chisel on Monday June 08, 2020 @04:28PM (#23460409)
I'm interested in your take wrt to the dependency hell GP mentions.
Re:Old Code Gets Younger Every Year by brundolf on Monday June 08, 2020 @04:39PM (#23460507)
Personally, I:

1) Keep my direct dependency list slim and mostly limited to "too big to fail" projects backed by major companies

2) Avoid frameworks in favor of libraries

I don't stress about indirect dependencies. If one of React's dependencies stops being maintained, or has a security problem or a bug, Facebook isn't going to not address it. Far too much money is riding on React as a whole, so whether they have to switch to a new dependency, or update the version, or reimplement the functionality themselves, they will. On top of this, the left-pad catastrophe can't happen again, because NPM publications are now impossible to remove after 72 hours: https://docs.npmjs.com/cli/unpublish

On the other hand I'm not going to add a direct dependency that I don't truly need. If it's a one-off function that I can write myself, or copy, I'll do so. On time I copied and pasted Lodash's debounce function into my codebase because that was all I needed, and I didn't want to bring in the whole library.

Libraries, compared with frameworks, are easier to predict, to fill gaps in, and to replace if necessary. And even some things that we call ""frameworks"" like React can really be used as libraries. If you only use React as a rendering layer - what it's best at anyway - it actually has a very thin and elegant boundary with your code: you construct a data structure, and you hand it off. Others, like Angular and Aurelia, are truly frameworks and I tend to avoid them as a result.

I wrote a blog post recently about the libraries/frameworks thing which got some attention/discussion here on HN: http://www.brandonsmith.ninja/blog/libraries-not-frameworks

Re:Old Code Gets Younger Every Year by speedgoose on Monday June 08, 2020 @04:50PM (#23460630)
There is a NPM package lodash.debounce if you only want this feature from lodash. Lodash is available splitted in many small packages.
Re:Old Code Gets Younger Every Year by _bxg1 on Monday June 08, 2020 @04:54PM (#23460682)
The point remains, though, that I avoided an unnecessary dependency. I copied that function once and never needed to mess with it again, because it was 15 lines and I could verify personally that it did what it needed to do.

For contrast, we wanted to be able to incorporate new versions of React, because it isn't a simple enough thing that it can be written once and be done. It evolved, and offered real improvements in terms of performance and useful features.

As in all things, there are costs and benefits to making something an external dependency or not. The key is to realize that there are indeed tradeoffs, and that outsourcing every single thing you can isn't necessarily ideal.

Re:Old Code Gets Younger Every Year by entropicdrifter on Monday June 08, 2020 @05:00PM (#23460748)
Right, but his point about that was essentially:

"Why depend on that as a dependency rather than just have a copy directly in my project that I know will never behave any differently?"

Re:Old Code Gets Younger Every Year by speedgoose on Monday June 08, 2020 @05:29PM (#23461026)
Because it's one line to a dependency with a name, a documentation, a bug tracker, many users, and that could be improved in the future.

If you are scared about packages behaving differently, you should know that npm has lock files that describes your full dependency tree with versions and checksums.

Re:Old Code Gets Younger Every Year by majormajor on Monday June 08, 2020 @05:53PM (#23461220)
"Could be improved in the future" is a risk when it comes to a simple utility function that does a simple thing that you don't want to change.

In the same way that someone constantly tweaking your utility functions in your own project would be a risk - and you'd understandably want to code review all that - the more you choose to (or have to) outsource "trivial" stuff, the more brittle your project is.

Re:Old Code Gets Younger Every Year by ioseph on Monday June 08, 2020 @09:16PM (#23462617)
Hence the lockfile, on the flipside if you've copy and pasted source across which contains a security update you'll most likely not realise
Re:Old Code Gets Younger Every Year by snovv_crash on Monday June 08, 2020 @05:42PM (#23461124)
In any other package ecosystem you'd be laughed out of the room for suggesting to add a dependency for a 15 line function, instead of just copying it into your codebase. And the 15 line function here is a fairly major function. People add dependencies for 2 or 1 line functions!
Re:Old Code Gets Younger Every Year by elagost on Monday June 08, 2020 @05:39PM (#23461089)
"one of React's dependencies"

Which one? There are... several. (someone posted this here a while ago, and it's lovely to look at)

http://npm.anvaka.com/#/view/2d/react-native

Re:Old Code Gets Younger Every Year by williamdclt on Monday June 08, 2020 @06:52PM (#23461667)
That's react-native. React (http://npm.anvaka.com/#/view/2d/react) does have... several: 5 of them.
Re:Old Code Gets Younger Every Year by elagost on Monday June 08, 2020 @09:20PM (#23462644)
Guess I'm wrong then! Thanks for the correction.
Re:Old Code Gets Younger Every Year by _bxg1 on Monday June 08, 2020 @05:55PM (#23461239)
The point is that it's not my problem. Those things, together, comprise "React" as far as my application is concerned. React being a huge project which millions of dollars have been poured into, and which billions of dollars probably ride on, is going to be kept working, one way or another. As long as it continues to provide a functioning interface for my code, that's all I care about.
Re:Old Code Gets Younger Every Year by noobermin on Monday June 08, 2020 @06:33PM (#23461540)
The problem isn't just what you see, the problem is sustainability for the whole ecosystem as a whole. FB has a lot of money but how do you know they won't determine at some point this is not sustainable and in two years you have to learn some other framework?
Re:Old Code Gets Younger Every Year by _bxg1 on Monday June 08, 2020 @06:38PM (#23461573)
I don't know if you realize how massive the React user-base is at this point. That would be like saying, "how do you know they won't determine at some point python is not sustainable and in two years you have to learn some other language?" I mean, I guess. But even in that scenario, I'm sure the hundreds of companies who depend on it would pick up the slack.
Re:Old Code Gets Younger Every Year by wolco on Monday June 08, 2020 @08:26PM (#23462325)
It happened to Angularjs. It didn't die just stopped evolving in the 1.x branch. Everyone had to accept 2.x or move on or stop evolving.
Re:Old Code Gets Younger Every Year by frosted-flakes on Monday June 08, 2020 @05:59PM (#23461284)
That React has a lot of dependencies isn't a problem in itself. At this point, React is stable. It's backed and relied upon by a gigantic company called Facebook. It's used by millions of developers around the world.

If there's a major problem with one of React's dependencies, it will be promptly fixed.

Re:Old Code Gets Younger Every Year by kerkeslager on Monday June 08, 2020 @09:44PM (#23462795)
React doesn't have a lot of dependencies. The person you are responding to linked to React Native, which is an entirely different thing.

I think it's a bit misguided to think that code quality won't be visible to users. As someone who has used both React and React Native, the quality of these two projects from a user perspective is worlds apart, and I have little doubt that their different approaches to dependencies are partly to blame for that.

Re:Old Code Gets Younger Every Year by kerkeslager on Monday June 08, 2020 @09:39PM (#23462765)
That's not React, that's React Native.
Re:Old Code Gets Younger Every Year by Mandatum on Monday June 08, 2020 @07:32PM (#23461963)
I cut my teeth on VB6. Then PHP, .NET and finally Java.

I look back at all the code I wrote.. And it's all bad. Except anything I wrote 2 weeks ago, that was my crowning achievement. In 2 months I'll hate it, but right now - it's perfect.

Re:Old Code Gets Younger Every Year by fulafel on Monday June 08, 2020 @05:07PM (#23460819)
Another perspective: It's nice that there are many nicer languages that target JS, besides the fairly new TypeScript there's ClojureScript, ReasonML, Elm, CoffeeScript, Dart, Haxe etc etc.
Re:Old Code Gets Younger Every Year by mrlala on Monday June 08, 2020 @05:07PM (#23460826)
But, but, but, if you don't write in C and manage your memory you are not a real programmer! Says slashdot/HN...