News for hackers. Stuff that matters.
Re:jQuery v4.0 Beta by QuadrupleA on Tuesday February 06, 2024 @11:06PM (#39284378)
Look at your own link - the "modern" way of doing it is always about 2-3x as verbose as jQuery. Editors let you type that mess faster, but you'll still have to read through it, maintain it, scroll it into view in your editor, see less of it onscreen at a time, etc. I'll take a clean, succinct API over a noisy verbose cumbersome one any day.

And what are we saving by eschewing it and going vanilla? One little 30kb-gzipped javascript file - smaller than most jpegs. I agree for super simple tasks it might be best to skip it.

The DOM API is a sloppy and hastily-designed pile of crap from the OOP era that we're unfortunately stuck with for legacy reasons. jQuery shows what it could have been.

Re:jQuery v4.0 Beta by austin-cheney on Wednesday February 07, 2024 @02:02AM (#39285432)
That is not correct at all. The DOM API is entirely functional based upon traversal of a lexically scoped model. It may not be as declarative as you like but lying about what it is because it makes you feel uncomfortable is rather ignorant.
Re:jQuery v4.0 Beta by troupo on Wednesday February 07, 2024 @02:25AM (#39285596)
> The DOM API is entirely functional based upon traversal of a lexically scoped mode

wat

DOM APIs have been, and still are, 90s-era OOP style with zero attempt at being functional, declarative, or composable.

Even the newly developed API are usually stuck in the same mindset (see everything developed for web components)

Re:jQuery v4.0 Beta by austin-cheney on Wednesday February 07, 2024 @02:36AM (#39285660)
The DOM is a big in memory object but the DOM APIs are entirely functional. Functional is not the same as declarative.
Re:jQuery v4.0 Beta by troupo on Wednesday February 07, 2024 @03:47AM (#39286100)
> DOM APIs are entirely functional.

(Almost) none of the DOM APIs are functional. They are literally `object.methodCall()`

Re:jQuery v4.0 Beta by austin-cheney on Wednesday February 07, 2024 @06:01AM (#39287050)
Yes, functional programming can have methods. Methods are functions. OOP is all about polyinstantiation and inheritance. Functional programming is all about functions and input/output, which is entirely what happens in this case. The only OOP here is the method assignment you don’t see: Element.prototype.getElementById = function () {};
Re:jQuery v4.0 Beta by troupo on Wednesday February 07, 2024 @06:47AM (#39287370)
You're making no sense. Functional programming is more than just "about functions".

DOM APIs are the embodiment of 90s-era OOP. There's literally nothing functional about them. All [1] "functions" are methods defined on very specific objects. You can't even get a proper reference to them without binding them to specific object instances

What exactly is functional about this?

  const newDiv = document.createElement("div");
  const newContent = document.createTextNode("Hello, world");
  newDiv.appendChild(newContent);
  const currentDiv = document.getElementById("div1");
  document.body.insertBefore(newDiv, currentDiv);

Okay, here's an easier question. What will happen here, and why?

   const function_reference = document.getElementById;
   function_reference("#id");

[1] Technically speaking, not all all. The more recent `fetch` is probably the only piece of browser APIs that can be called functional for some very limited definition of functional

Most (all?) other "global" functions are defined on the instance of the window object: getComputedStyle, getSelection etc.

Re:jQuery v4.0 Beta by austin-cheney on Wednesday February 07, 2024 @07:00AM (#39287490)
> What exactly is functional about this?

A series of function calls that each do something and each returns a value.

> Okay, here's an easier question. What will happen here, and why?

A function call that does something and returns a value, because in this language complex types are passed by reference.

Re:jQuery v4.0 Beta by troupo on Wednesday February 07, 2024 @07:06AM (#39287533)
> A series of function calls that each do something and each returns a value.

Doesn't make it functional

> A function call that does something and returns a value,

Ah, so you don't know.

Here's what will actually happen:

      TypeError: Can only call Document.getElementById on instances of Document
Because it's a method on an object. And you have to bind that method to a specific object instance before you can call it.

If it was functional this would never be the case. But since this is 90s-era OOP, you have to do this:

      const function_reference = document.getElementById.bind(document);
      function_reference("#id");
Re:jQuery v4.0 Beta by _rend on Wednesday February 07, 2024 @12:00PM (#39290998)
> A series of function calls that each do something and each returns a value.

This is not what functional programming is. Functional programming is a completely different paradigm for writing code, and it _is_ declarative by definition. The Wikipedia definition is pretty decent:

    Functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that map values to other values, rather than a sequence of imperative statements which update the running state of the program.
The "Comparison to imperative programming" section[1] offers a decent example of the paradigm, but DOM manipulation in JavaScript is pretty much as imperative as it gets. Having functions is necessary, but not sufficient, for functional programming.

[1]: https://en.wikipedia.org/wiki/Functional_programming#Compari...

Re:jQuery v4.0 Beta by koromak on Wednesday February 07, 2024 @01:43PM (#39292456)
Hate to pile on, but this is absolutely not the definition of functional programming.

Functional programming uses stateless, immutable transformations to contorl data flow. The second you instantiate an object with some internal properties that change in memory, you are no longer programming functionally

Re:jQuery v4.0 Beta by andrei_says_ on Wednesday February 07, 2024 @10:24PM (#39297641)
You just described why I use slim-lang in all of my projects. produces clean, correct HTML with zero noise.

Ends up eliminating 50-60% of the code, and the time for writing and reading it.

As for jquery I haven’t needed it much since stimulusjs but loved it whenever I used it.

Re:jQuery v4.0 Beta by antifa on Friday February 09, 2024 @09:46AM (#39315295)
I'd only drop jQuery/lodash if you were adding Typescript. And I do prefer dropping them for Typescript, but the previous are still cool.