News for hackers. Stuff that matters.
Re:The Build is Always Broken by skrebbel on Wednesday January 08, 2020 @03:06AM (#21989372)
People love to complain about Webpack, but it pretty much does all of this out of box, all the way down to hot-reloading UI components. In that sense it's way ahead of all C++, C#, Java, etc build systems I know.

Doing an `npm run dev` type of command in a reasonably set up JS project is very much this staged execution model the author talks about. Everything gets cached, on disk and in memory, only changes are recompiled, and reloads are fast, partial, and often hot-swapped. It's quite close to the maximum level of "liveness" I can imagine.

It's kind of amazing how JS took over older and more established languages in this sense - and we're still not content (judging by how popular it is to complain about webpack). This is great.

Re:The Build is Always Broken by tobr on Wednesday January 08, 2020 @06:16AM (#21990388)
I’ve never had anything close to this experience with Webpack. In my experience all the magic “it just works” of incremental updates and live reloading is extremely fragile and just gives up silently all the time in large-ish projects. Adding to that, it’s incompetent at what’s supposed to be its core feature: bundling JavaScript modules. I would count it among the least reliable software systems I have to work with regularly.
Re:The Build is Always Broken by commandeer on Thursday January 09, 2020 @07:54PM (#22007535)
I think what it does is amazing in terms of hot reload, etc. But yea, I always make sure someone on the team I am working on is a master at it, because some people are and some people aren't and if nobody on the team 'thinks' in the way webpack does, it can be terrible.
Re:The Build is Always Broken by Cthulhu_ on Wednesday January 08, 2020 @04:31AM (#21989838)
I understand where Webpack et al came from, but the more I work with it the less I like it. There used to be a time when the JS I wrote was the exact same that was executed. Now, even in development mode, it gets pulled through several tools (webpack/babel and a heap of their plugins, a minifier, source maps get generated etc) before my changes are visible, even in an incremental / hot reloading build.

It's not just build time, it's the indirectness. I'm seriously contemplating dropping it for a next project and just writing straight JS, whichever dialect (es6?) has the widest adoption.

Re:The Build is Always Broken by SamBam on Wednesday January 08, 2020 @10:44AM (#21992372)
Which is fine, if you have no need of any dependency management (stick everything in script tags and reference globals), your script is going to be made up of only a few individual .js files (every one has to go in the header), and you have no use for JSX or TypeScript.

For most people working on larger projects, though, the advantages of real dependency management (however broken NPM is) and transpiling JSX or TS is worth the compilation, which you get used to.

Re:The Build is Always Broken by ratww on Wednesday January 08, 2020 @01:56PM (#21994546)
If you don't need backwards compatibility, you can use ES6 modules directly in the browser [1] and even load NPM packages in module format from Pika or Unpkg.

Living without a bundler was alright.

At my last job we checked Google Analytics and almost 100% of our users were on greenfield browsers, so we moved to that and had no issues.

[1] https://www.sitepoint.com/using-es-modules/

Re:The Build is Always Broken by mishoo on Wednesday January 08, 2020 @04:20AM (#21989791)
You won't get what true "liveness" is until you work in Lisp or Smalltalk. The ability to change a function in a running program, without restarting it. Automatic reload might seem cool, but reload means your application restarts and loses state. Imagine you have some Web app and you open some menus/dialogs, perhaps it's connected to some server via WebSockets etc. and you find a bug somewhere, you go to the code to fix it, but reloading the page means you start from scratch and need to open again those menus/dialogs, and reconnect the sockets, in order to test your fix.

Common Lisp had true liveness for decades; it's almost mandated by the standard, it's designed in such a way that you can actually recompile a function, or even redefine objects, adding or removing properties or methods, at fucking runtime without restarting the application. Objects already instantiated will remain so and will be updated to reflect the change. You don't restart. That's the true "liveness", but seriously you don't get it until you try it, and once you get it you become depressed because you realize it doesn't really exist in any mainstream language.

JavaScript is some decades behind this dream, even with stuff like Webpack.

Re:The Build is Always Broken by jcrites on Wednesday January 08, 2020 @06:01AM (#21990302)
> You won't get what true "liveness" is until you work in Lisp or Smalltalk. The ability to change a function in a running program, without restarting it

This can be done in a number of other common languages today such as Java (JVM languages) and C# (probably all .NET languages). Most IDEs I've seen for those platforms support it.

Substantial enough changes to the code can require an application restart, but most changes you might make like changing the implementation of a function, adding new functions to a class, etc., will not. Hot Code Replacement (HCR) has been supported since Java 1.4: https://wiki.eclipse.org/FAQ_What_is_hot_code_replace%3F

Fully dynamic languages like Lisp and Smalltalk permit a greater degree of this than statically typed languages do, however, since they don't have types and a type system to wrangle with. When I've used it, hot code replacement supported most of the changes that conceptually make sense to support.

Re:The Build is Always Broken by mishoo on Wednesday January 08, 2020 @06:46AM (#21990529)
You'd be surprised to find out that Common Lisp has actually quite a strong type system (not Haskell-level but much better than C++/Java); just that it's optional. You get the best of both worlds — fast prototyping, and then when you decide upon the types, you can add type declarations, which usually result in (much!) faster code and robustness.
Re:The Build is Always Broken by HereBeBeasties on Wednesday January 08, 2020 @04:27AM (#21989819)
If you use webpack's hot reloading properly with something like React, then you get to keep your state - it's only the functions that get swapped out. So it's actually exactly what you describe, and it's brilliant - so much more productive. This isn't even all that new (in web dev terms) - I had this working probably four or five years ago now on a project.
Re:The Build is Always Broken by fenomas on Wednesday January 08, 2020 @06:18AM (#21990401)
Huh?

I do procedural music in JS/web audio, and my projects are set up so that changes to the logic and instruments all happen live, while the music continues to play.

How is that different from what you're describing? What specifically can't webpack/HMR do?

Re:The Build is Always Broken by partyboat1586 on Wednesday January 08, 2020 @07:38AM (#21990837)
What tools do you use? Just web audio api? Or a higher level library?
Re:The Build is Always Broken by fenomas on Wednesday January 08, 2020 @07:47AM (#21990882)
I first started out using Tone.js (and recommend it!), but later wound up rolling my own engine and so forth. So I'm just using WebAudio directly (or via libraries I wrote).
Re:The Build is Always Broken by baddox on Wednesday January 08, 2020 @04:28AM (#21989824)
It’s relatively simple to have live reloading of individual JavaScript modules in Webpack. If you change the text on a React button component, that module will be recompiled and its new version injected into your browser and re-rendered. The text on the button in your browser will change, but other state will not change (e.g. something in your Redux store).

I’m not an expert, but I think the way it works is that Webpack provides a way for JS modules to register callbacks for what should happen when Webpack detects changes in them and recompiles them. React then provides such a callback implementation for component modules that causes the individual component to re-render. Webpack’s development server also provides a way to inject new code into your app running in a browser.

Things get a little more complicated if you want to hot reload things that deal intimately with state, like Redux reducers or middleware. AFAIK people usually just have the browser do a full page reload when changes are detected in those modules. I think Webpack will actually automatically trigger a full page reload if it detects a change in a module which does not explicitly declare how hot module reloading should be handled.

I only mention React and Redux because it’s the only major stack I’m at all familiar with; I don’t know if other stacks provide similar functionality.

Re:The Build is Always Broken by skrebbel on Wednesday January 08, 2020 @04:24AM (#21989808)
FWIW hot reloading React/Vue components come quite close to this.
Re:The Build is Always Broken by LandR on Wednesday January 08, 2020 @06:09AM (#21990348)
So does ClojureScript and Figwheel.
Re:The Build is Always Broken by dragonwriter on Wednesday January 08, 2020 @04:52AM (#21989964)
> You won't get what true "liveness" is until you work in Lisp or Smalltalk. The ability to change a function in a running program, without restarting it.

Erlang provides this as well, as do many dynamic languages. However, aside from certain Lisps and Smalltalk that are image based, and a few others, liveness and source persistence are typically traded off for each other. I can make a live change to a Ruby system if it is set up to provide a REPL, but unlike a live Smalltalk change I won't then have the source code for the changed but available the same way it is for the rest of the system. As a result, in many languages live coding features are mostly a tool for experimentation (usually in nonproduction environment!) on code that will eventually be incorporated into traditional source tree for a from-scratch build.

Re:The Build is Always Broken by toolslive on Wednesday January 08, 2020 @05:13AM (#21990062)
- IBM's visual age for java provided most of this for Java too. (yes, it was modeled to the smalltalk env with the same name)

- Zope (python app server) had a feature where you could debug a web application (in production) in a private session, so all code modifications you did in your session were private until you committed the code.

Re:The Build is Always Broken by javajosh on Wednesday January 08, 2020 @05:21AM (#21990102)
- Jrebel is a commercial tool that also lets you replace bytecode in a running program without loss of state.
Re:The Build is Always Broken by bzzzt on Wednesday January 08, 2020 @07:40AM (#21990850)
"Hot code replacement" is a Java VM feature. What makes JRebel useful is support for live reconfiguration of a gazillion Java frameworks (e.g. Hibernate, CDI, Spring etc) so you don't have to restart your server after changing some configuration annotations. It's expensive though and slows down startup so it's a tradeoff.
Re:The Build is Always Broken by imtringued on Wednesday January 08, 2020 @05:43AM (#21990218)
Webpack has 600 transitive dependencies. There is no way you can use that in a serious business if you care about security.
Re:The Build is Always Broken by zelly on Wednesday January 08, 2020 @03:57AM (#21989676)
Arguably Skaffold and other container tools are approaching Webpack in its nonstop build-edit-rebuild workflow. But it's still not part of the code's build process. I'd like to see something like Webpack for native code.

The hypothetical build system can, whenever files change, run the build again (in a container), execute tests (complaining when you break one), or let you keep the debugger open while you're editing (best attempt made to fast forward).

This is probably better suited for modern languages with proper modules and incremental builds, like Rust, C++20, Java9.

Re:The Build is Always Broken by Insanity on Wednesday January 08, 2020 @03:53AM (#21989652)
I'm not a web dev but used webpack some years ago. Is the issue not that webpack works fine once you finally get it working, and the complaints are about all the issues before it does?
Re:The Build is Always Broken by skrebbel on Wednesday January 08, 2020 @04:00AM (#21989689)
Yes it is, but this article highlights what an achievement it is that webpack is possible at all. I think Bracha would gladly struggle through some config if that was all that stood between him and his holy grail of liveness.

Plus webpack got a lot better even in that regard, and there's alternatives like Parcel pushing the curve. Web devs sometimes don't realize how good they have it :-)

Re:The Build is Always Broken by baddox on Wednesday January 08, 2020 @04:20AM (#21989793)
Perhaps, but you’d get similarly unsatisfactory reviews from any technology before you have learned how to use it. Criticism of how difficult it is to learn a technology is valid, but it’s not a valid criticism to say that a technology is not working well before you have learned how to use it.