News for hackers. Stuff that matters.
Re:Things I Regret About Node.js [video] by bartread on Wednesday June 06, 2018 @05:08PM (#17251144)
I think the problem with "bloat-free" is it's a fine ideal until you try to solve any kind of reasonably complex problem, and honestly it starts to creep in even when you're solving something that isn't particularly complex.

Here's a concrete example. Your classic node.js or express.js sample app is something fairly simple like a hello world, or an IM server. A more complex sample probably looks something like that venerable nodecellar app from a few years back. In all cases the spiel is, "Hey, look how easy it is to create a web server with node."

Except that I'm looking at my node server source right now - for an honestly fairly simple app containing a handful of pages and a blog - and here's what I have:

- Routing (obviously)

- Cookie and body parsing

- Session management

- MongoDB integration

- Passport.js for authentication with a couple of providers (FB and Twitter)

- File system access

- HTTPS and SPDY/HTTP2 support

- Compression support

- Logging with winston and morgan, including loggly integration

- Referer spam filtering

- Pug templates

- Hexo blog integration

- Path resolution support

- Request validation and redirects

- Static content support

- Stripping headers such as X-Powered-By, and adding other headers such as the all-important X-Clacks-Overhead

- Error handling

There's probably a couple of other items I missed, but you get the idea. It seems like a lot but, as far as I'm concerned, this is express.js app MVP for anything you might want to put into production.

I haven't even mentioned the gulpfile I use to build all this, which targets desktop, mobile, along with embedded versions for a particular mobile app due to launch in the near future, and has become something of a behemoth[1]. Nor have I mentioned that I have Cloudflare to sit in front of this, primarily to deal with the heavy lifting of some of the media files I serve up.

On the face of it, this might feel like "bloat" but it's all necessary to run the application and, like I say, a lot of it is the bare minimum for an MVP web app in node.

[1] Yes, I know I could/should switch to webpack, but gulp works, and switching to webpack "just because" doesn't justify itself with the value it might add.

Re:Things I Regret About Node.js [video] by mikekchar on Wednesday June 06, 2018 @06:22PM (#17251607)
IMHO, the point of using a no-frills library/framework is because you want you write the rest of it yourself. The advantage of this is that it meets your requirements exactly and is therefore smaller/less complex.

When doing a project that takes only a few weeks, I would probably choose a framework that has everything in the box. But if you are building something that is going to be developed over a period of years, the reduction in complexity achieved by building your own can be life saving.

When I look at your list, most of the things fall into the categories of "Pretty easy to implement" or "Don't want at all". However, there is an advantage for not reinventing the wheel if there is no reason to do so. If there is a nice library that gives me what I want and doesn't impose itself too much on the design, I will use it. But the main advantage for not baking it into a big framework is that I can pick and choose what I want.

As an older programmer, I come from an era where libraries and frameworks cost a lot of money. We built stuff by hand because there were not a lot of other choices. These days, though, virtually every library and framework is free software (not only free of charge, but you get source code too!) It's like living in Candy Land, and I'm not about to complain about it :-) However, I think that programmers today reach too quickly for the pre-built and do not understand the long term advantages of bespoke development. Like most things, there is a balance to be maintained.

Re:Things I Regret About Node.js [video] by pknopf on Wednesday June 06, 2018 @09:56PM (#17252652)
The gist, every dependency you bring in your app should be thought about, really hard.

If your using 10% of the lib, just implement it yourself.

If the lib is critical, like openssl, bring it in. Other people have solved the hard problems for you.

But yeah, it's a balance.

Re:Things I Regret About Node.js [video] by fnordsensei on Thursday June 07, 2018 @12:39AM (#17253342)
Unless you're using something that has competent dead code elimination, like Google Closure Compiler. Then you can go ahead and include 30mb of libs, knowing that only a fraction will actually be shipped in the production version.
Re:Things I Regret About Node.js [video] by menor on Thursday June 07, 2018 @03:03PM (#17259073)
I don't come from that era but couldn't agree more, every time one of my coworkers suggest using a library I tell them that is ok as long as they maintain it, I prefer to spend my time coding and like to understand as much of the codebase as I can, instead of having to learn and maintain tens of external libraries. Specially if we only need a couple of functions from that library.

I normally lose those debates though, and the thing reaches a point where the complexity of the code makes it impenetrable.

Re:Things I Regret About Node.js [video] by p2t2p on Wednesday June 06, 2018 @07:18PM (#17251961)
This why I love Java so much. Take a look at what Spring Boot does for me:

- Routing is done in two lines of code: @Controller @RequestMapping("/myroute")

- Cookie and body parsing - no need to write any code to do that, I just have method parameters and all of the data flies in. Whant a validation? Only one keyword on a method parameter - @Valid. Custom validators are supported as well.

- Session management. It just here for me and does the right thing by default. I can replace storages with custom implementations but by default no code is required from me.

- MongoDB integration - Spring Data MongoDB and you only need to define interfaces using naming convention. The code to access the actual database is generated for you.

- Spring Security supports multiple authentication mechanisms and gives you neat DSL to configure it.

- File system access kind obvious thing.

- HTTPS and HTTP2 support provided by Spring MVC as well.

- Compressions support - it just "server.compression.enabled=true" in your config

- Logging - slf4j + logback come with Spring Boot and there plenty custom appenders available to put you logs into logstash/splunk whatever

- Referrer spam filter - not sure about that one but CSRF protection comes OOB and enabled by default.

- Multiple tightly integrated template engines to chose from. Zero configuration code as well.

- Static content comes OOB and enabled by default, just put your stuff into resources/static.

I mean yeah, modern webapp is a complicated thing! So whenever I see somebody trying to do anything "not bloated" it means that I end up writing low level code that has been written multiple times again and again.

The other day I was trying to code a simple thing in Clojure because I love Lisp. Well, it's just embarrassing. I got to simple page showing stuff from Postgres and the boilerplate/business code ratio was at about 70%. Manually configure connection pool, manually start it, manually prepare your component systems, manually mention all of the dependencies for components, manually configure template engine, manually enable static resources support in ring, manually configure and enable session support in ring. Then we come to authentication and don't even try to sell me Friend. EVERYTHING is manual. The only good thing was "environ" which did the right thing but again with "bloated" Spring Boot it comes OOB and I don't need to configure it!

If you don't use something "bloated" it only means that you're writing code yourself, again and again.

Re:Things I Regret About Node.js [video] by sidlls on Wednesday June 06, 2018 @10:29PM (#17252790)
No, Spring Boot is one of the best examples of the worst kind of terrible patterns in the land of Java development. The bloat in that framework is awful, and the gods help you if something goes wrong in the annotations-everywhere code for anything but the most trivial of applications.
Re:Things I Regret About Node.js [video] by humbleMouse on Thursday June 07, 2018 @01:33AM (#17253526)
If you limit the annotations to only the basics,(controller,config,bean,requestmapping,etc.) - not much can go wrong. It sounds to me like you haven't worked with any large spring boot apps and experienced the stability annotations can provide.
Re:Things I Regret About Node.js [video] by swsieber on Friday June 08, 2018 @08:27AM (#17264623)
Except circular dependencies. I work on an app where a circular dependency failure happens depending on what order spring finds our annotated classes. It made writing a faster bean scanner a little tricky because I had to replicate Springs ordering method.
Re:Things I Regret About Node.js [video] by humbleMouse on Friday June 08, 2018 @09:13PM (#17270959)
To clarify what you said - You wrote a custom "fast bean scanner" and it's not working properly? Or you had to re-write it because spring's bean scanner wasn't working? What version of spring is this?
Re:Things I Regret About Node.js [video] by swsieber on Friday June 08, 2018 @10:40PM (#17271229)
Ah, the spring bean scanning was working, but startup wasn't. The reason? Our app was apparently very brittle and the mere act of registering beans in the wrong act would cause a circular dependency error during startup.

To be more concrete, to the original spring bean scanner, we were passing in a set of package names, which it would scan. Spring registers those bran defininitions in yhe order that it scans the beans. My custom scanner (found and registered all the same beans), broke our app because it wouldn't startup anymore due to a circular dependency error. Once I sorted the bean definitions by the original pack path inputs, that startup error went away.

I think we are 4.x

Extra details: I used the fast -classpath-scanner library. I subclassed the annotation cand date componend scanner class (well, something like that), and rewrote a method to load the resources for the string specified, treating the path a a fqcn, not a package path. Then I could feed that class the output from the fast classpath scanner (which was the list of classes with the annotations). Until I sorted the input by the original package paths, my app wouldn't start. Mind you, the method I overwrote simply created bean definitions. But that ordering difference made all the difference.

I can dig up exact class names if you are curious. The scanner of course didn't replicate all spring bean sear check capabilities - just the ones we were using. But it cut the scan time by 60% (several seconds).

Re:Things I Regret About Node.js [video] by p2t2p on Thursday June 07, 2018 @01:29AM (#17253507)
Could you provide an example of what you consider terrible?
Re:Things I Regret About Node.js [video] by EtienneK on Thursday June 07, 2018 @01:11AM (#17253442)
Agreed. Spring Boot is how you do frameworks right.

It is opinionated and provides libraries and solutions for almost everything you need to do, BUT it always allows you to use your own if required.

I love Spring Boot and I wish there was something even remotely as good and full featured in other languages.

Re:Things I Regret About Node.js [video] by i_made_a_booboo on Wednesday June 06, 2018 @10:12PM (#17252731)
I'm switching to Rails after doing years of Spring Boot apps. The bloat of Java is 3x to 5x.
Re:Things I Regret About Node.js [video] by cutler on Wednesday June 06, 2018 @10:34PM (#17252812)
Spring Boot 2 with Kotlin can be a lot less bloated, especially with the async Reactive Web option which uses Netty.
Re:Things I Regret About Node.js [video] by pjmlp on Thursday June 07, 2018 @02:46AM (#17253789)
Good luck running it fast enough.
Re:Things I Regret About Node.js [video] by jrochkind1 on Thursday June 07, 2018 @10:14AM (#17255878)
Meh, not really an issue.
Re:Things I Regret About Node.js [video] by cutler on Wednesday June 06, 2018 @10:31PM (#17252797)
Have you tried Luminus? It comes configured with Buddy for auth though the docs for both Luminus and Buddy could do with some work.
Re:Things I Regret About Node.js [video] by p2t2p on Thursday June 07, 2018 @01:33AM (#17253524)
I haven't. But I definitely will try to use it, I'm really eager on getting to the same level of productivity in Clojure that I have in Java with Spring. I have a huge hope that Clojure + something like Spring Boot for it could make me even more productive. Some of the stuff that we have in Clojure really is wonderful, hugsql for example.
Re:Things I Regret About Node.js [video] by cutler on Thursday June 07, 2018 @06:23PM (#17260862)
You'll never get anything close to Spring Boot for Clojure. Spring grew out of J2EE and Clojure's culture is diametrically opposite, favouring curated libraries. Clojure's main/(only?) web framework - Luminus - has a very small team behind it, though it does a fine job.
Re:Things I Regret About Node.js [video] by Jach on Thursday June 07, 2018 @02:26PM (#17258684)
What are the barriers to using the Spring stuff through Clojure's interop capabilities?
Re:Things I Regret About Node.js [video] by i_made_a_booboo on Wednesday June 06, 2018 @10:09PM (#17252714)
Nevermind the additional complexity of integrating with payment gateways and handling complex authorization requirements and team invitations etc.

Even a 'simple' web app is a convoluted mess of shit if you are to run a real world production grade system. I'm so sick of all these 'hello world' toy examples.

Re:Things I Regret About Node.js [video] by royjacobs on Wednesday June 06, 2018 @05:13PM (#17251171)
It's interesting that you mention gulp and webpack when those tools too are now considered too complex and set to be usurped by something like Brunch.

It's a shame these tools keep being rewritten because there are definitely good ideas in all of them, but for some reason they can't seem to be unified.

Re:Things I Regret About Node.js [video] by Arnavion on Wednesday June 06, 2018 @05:19PM (#17251211)
All these tools start off as simple alternatives to the existing bloated tools. Then as they gain more and more features to support real-world situations they end up becoming as bloated as the tools they set out to replace.
Re:Things I Regret About Node.js [video] by mediumdeviation on Wednesday June 06, 2018 @11:03PM (#17252929)
Webpack and Gulp were never meant to be simpler alternatives. Gulp used streams instead of serially processing files like Grunt, which made it faster, but obviously streams working in parallel are more complex than just processing the files one by one.

Webpack pulls dependencies into one file and deduplicates them. This is obviously even more complex since now you have dependency resolution logic as well as dealing with the various module systems JavaScript has invented.

Re:Things I Regret About Node.js [video] by royjacobs on Wednesday June 06, 2018 @05:37PM (#17251313)
Right. I'd just hope that at some point that cycle ends and people try to fix existing tools instead of replacing everything wholesale with something new that will eventually fail again.
Re:Things I Regret About Node.js [video] by Moru on Wednesday June 06, 2018 @06:10PM (#17251512)
Sorry, there is always a new developer thinking "I can do this much better if I just start from scratch, getting rid of all the bloat".
Re:Things I Regret About Node.js [video] by panopticon on Wednesday June 06, 2018 @06:55PM (#17251822)
> It's interesting that you mention gulp and webpack when those tools too are now considered too complex and set to be usurped by something like Brunch.

While Webpack is a little dense, it appears to strike the right balance between complexity and customizability (and probably more important for longevity, library buy-in). It doesn't seem like anything on the horizon is going to unseat it anytime soon... certainly not Brunch.

Re:Things I Regret About Node.js [video] by pknopf on Wednesday June 06, 2018 @09:59PM (#17252668)
> While Webpack is a little dense, it appears to strike the right balance between complexity

I don't know, I thought the same thing about Browserify.

And now Parcel is here, gaining steam...

Re:Things I Regret About Node.js [video] by pknopf on Wednesday June 06, 2018 @09:58PM (#17252659)
> usurped by something like Brunch

I've been out of Node for like 6 months, wth happened! I give up!!

Re:Things I Regret About Node.js [video] by chrisco255 on Thursday June 07, 2018 @12:17AM (#17253248)
Brunch is not usurping Webpack. But these are tools built on top of Node.js. They're for front end development, and have nothing to do with running a Node.js server on the backend.
Re:Things I Regret About Node.js [video] by spiralx on Friday June 08, 2018 @08:21AM (#17264586)
Brunch was between Gulp and Webpack, so don't worry! And since Webpack there's only been Rollup and Parcel to consider :)
Re:Things I Regret About Node.js [video] by yen223 on Wednesday June 06, 2018 @10:30PM (#17252793)
Somewhere along the line, we as developers have abandoned the Unix philosophy, especially the oft-forgotten second part ("Write programs that do one thing, and one thing well; and write programs that work well together").

Without the ability to compose multiple small libraries to form the exact solution that we need, we had little choice but to rely on the One True Framework to solve every problem that we will have.

This means if the One True Framework doesn't serve the exact need you have (and it almost definitely won't, there's a combinatorial number of requirements out there), it's time for a rewrite!

Re:Things I Regret About Node.js [video] by zzbzq on Thursday June 07, 2018 @12:07AM (#17253199)
NPM is the closest environment to the Unix philosophy apart from Linux. Lots of small packages instead of a large base class library like all the other language ecosystems.

The thing is, even with Linux distros, most of the stuff you want is built-in by the distro. Once you start to add your own stuff, it can get really ugly and you have to be really pro to get anything done. It seems like every time I'm working on updating a Linux image I have to do some really bizarre thing where the package manager doesn't even work right and the instructions or some forum have me doing some mind-blowing workarounds I don't even understand.

So I think you are combining two different topics. I am all-in for libraries over frameworks. But the larger, more heavily curated libraries where you only need minimal customization are just objectively better. Having a large, curated standard library != a framework.