News for hackers. Stuff that matters.
Re:A love letter to jQuery by brakmic on Saturday February 27, 2016 @02:28PM (#11188086)
Whenever I hear "You don't need jQuery!" I immediately ask myself: is this guy/girl younger than 25?
Re:A love letter to jQuery by nostrademons on Saturday February 27, 2016 @03:31PM (#11188352)
I'm 34, been developing web stuff for over 10 years now, and started using JQuery back when John Resig was still personally meeting & greeting people who were using JQuery at meetups.

I'm pretty firmly in the "You don't need JQuery camp", and the reason is that you don't need JQuery now. It was an amazing piece of software when it came out; it made rich JS development not only practical, but easy, without worrying about cross-browser issues. But it succeeded. Resig's goal - from very early on, at least as soon as he started to working at Mozilla - was to get JQuery baked into browsers, and he's largely done that. We got querySelectorAll. We got a unified event model that all browsers support. We got FormData. We got a consistent box model, and consistent getComputedStyle() behavior. We got animations and transitions, and the native versions even run on the GPU for fast mobile performance.

As a result, most of the problems that JQuery solved just aren't problems in modern web development. Cross-browser issues are minor and getting smaller every day. Selectors are baked in. Animations and transitions are CSS one-liners, rather than needing to spin up a setTimeout loop and manually calculate the delta in the property each tick.

That doesn't deny the historical significance of JQuery, or just how much it improved web development back in 2007. But we build apps for the world we live in today, and today, JQuery gives you some minor programming convenience in exchange for 30K of download size and a bunch of layout thrashing if you use its CSS or dimensions methods.

Re:A love letter to jQuery by karlshea on Saturday February 27, 2016 @02:31PM (#11188096)
I think even people that are older sometimes forget how terrible it was to develop with JavaScript before things like Prototype and jQuery came on the scene. Just moving from alert() to console.log() was a revelation.
Re:A love letter to jQuery by brakmic on Saturday February 27, 2016 @02:33PM (#11188106)
You're right!

Forgetting to say "thank you" to people who helped us a lot is something that happens more than often in IT.

I still remember when I heard of jQuery. It was in 2007 and it was so amazing.

Yes, I admit, the 'alert()/console.log()' was amazing :)

Re:A love letter to jQuery by karlshea on Saturday February 27, 2016 @02:46PM (#11188161)
I'd just like to go back and show 15-year-ago me Firebug or Chrome/Firefox's DevTools and inspector. It's pretty stunning how far the tooling has come and what you can do with it.
Re:A love letter to jQuery by antod on Saturday February 27, 2016 @03:16PM (#11188282)
Heh, nearly that far back I was wishing I could install Venkman in IE.

JQuery and Firebug deserve a lot of credit for bringing some sanity to JS/web development. Sure things have moved on now, but they were ground breaking.

Re:A love letter to jQuery by aidos on Saturday February 27, 2016 @03:58PM (#11188456)
Man, it was 2006 (10 years ago!) when Firebug, Drosera [1] and Web Inspector [2] were all released. There were definitely a lot of people eager to have some tools to make front end web dev easier back then.

I never worked with Venkman but I recall all too well the hellish time I had debugging JS back around the turn of the millennium. IE was laughable, if there was an error in a script somewhere it would often just say error on line -1.

[1] https://webkit.org/blog/61/introducing-drosera/ [2] https://webkit.org/blog/41/introducing-the-web-inspector/

Re:A love letter to jQuery by antod on Saturday February 27, 2016 @06:21PM (#11188963)
That part about the line numbers in IE error messages was exactly the pain I was thinking of :)
Re:A love letter to jQuery by brakmic on Saturday February 27, 2016 @02:56PM (#11188201)
Sadly, we can't go back in time. But we should at least be grateful in the opposite direction.
Re:A love letter to jQuery by vatotemking on Saturday February 27, 2016 @07:11PM (#11189110)
I'd like to say thank you to the author of iepngfix. You da real mvp. [0]

[0] - https://www.twinhelix.com/css/iepngfix/

Re:A love letter to jQuery by dj_doh on Saturday February 27, 2016 @04:06PM (#11188493)
Write less, Do more. In its truest sense.
Re:A love letter to jQuery by alexc05 on Saturday February 27, 2016 @03:03PM (#11188227)
Well, I'm 40 and prefer using front end frameworks (angular, mithril, react) to jQuery nowadays. Additionally, there are times when I find (for little things) native javascript is quicker and more useful.

I think the sea change for me was not using front end frameworks, but when I first started trying to play with nodejs.

As soon as I started working with that AND started coming to understand the async nature of javascript, my entire world shifted underneath me.

In hindsight, I'm amazed that I managed to remain employed for so long while NOT knowing that javascript was async. Oh well. Such is life.

Anyways, I've definitely said "you don't need jQuery" on numerous occasions. There are plenty of places where it is the best and cheapest solution, but other times when it isn't (or isn't available).

Re:A love letter to jQuery by DonHopkins on Saturday February 27, 2016 @04:58PM (#11188703)
Two important things about JavaScript that enables easy "asynchronous programming" are:

1) First order functions that you can pass around.

2) The fact that those functions can be closures over the local scope, so it's easy to pick up from where you left off.

Two big mistakes in the design of JavaScript that work against easy "asynchronous programming" are:

1) That "this" is not lexically bound in the local scope (technically it's a magic "keyword" that's dynamically bound by the interpreter), even though in most cases capturing "this" lexically is what you really mean to do.

To mitigate that problem, you have to do silly stuff like "var self = this;" to copy dynamically scoped "this" into lexically scoped "self".

2) Each { block } doesn't have its own variable scope, so variables you bind inside loops that repeatedly create closures (like callbacks for a list of menu items) have their value changed out from under them to the last loop iteration when those closures are called later on.

To mitigate that problem you have to wrap another function(){ ... }(); around the loop body to capture the values for each loop individually.

Both problems cause subtle hard to find bugs, even when you know about them and are expecting them and programming defensively to avoid them. And both problems were bad naive design decisions that many other languages had previously gotten right.

But modern bleeding edge JavaScript now has "=>" fat arrow functions that bind this lexically, and "let" that declares block scope variables. (But that's not supported in all browser yet.)

Yay for progress! Worse may be better, but once you've wiped out the competition and taken over the world, there's no reason to keep it worse on purpose.

Re:A love letter to jQuery by jnbiche on Saturday February 27, 2016 @06:46PM (#11189032)
I absolutely agree with you about the importance of first-class functions and closures for async programming.

However, I disagree with your number (1). First, you shouldn't have to use "var self = this;" very often, unless this is your preferred style. Many JS libraries will let you pass in the context as the final argument in a function call. And if you can't do this, you should look to `bind` and `apply`, they're very handy for handling contexts [1].

I do strongly agree with your (2). But if I'm not mistaken, the latest versions of many browsers do support block scope already. I know Chrome does, and Firefox and Edge may as well.

1. http://javascriptissexy.com/javascript-apply-call-and-bind-m...

Re:A love letter to jQuery by DonHopkins on Saturday February 27, 2016 @07:37PM (#11189181)
As often as I program in JavaScript myself, and warn other people about the "this" binding problem (it's really hard to explain to newbies, but important), I get nailed by it all the time myself. I just can't seem to remember to go out of my way every time and use "var self = this;" or call bind, and it's quite easy to miss it when visually inspecting code. It's the first thing I look for when things goes inexplicably wrong. The second thing is variables changing out from under closures in loops.

I am looking forward to the time that most major browsers support => and let.

Re:A love letter to jQuery by meo2 on Saturday February 27, 2016 @03:20PM (#11188297)
Re:A love letter to jQuery by alexc05 on Saturday February 27, 2016 @04:03PM (#11188482)
Ahh.... lovely, thank you. So what I'm referring to as "asynchronous javascript" is technically a colloquialism used to describe the event-driven callback-y nature of the code.

I'm not sure I'm still against referring to javascript as asynchronous or at least as having asynchronous methods for the purposes shorthand and quick communication.

Consider the code (or paste it into a chrome console)

     function _done(){ console.log(arguments) }
     var db = window.openDatabase("dbfoo", 1, "test db", 5e6)
     db.transaction(function(tx){
        tx.executeSql('CREATE TABLE t1(a, b PRIMARY KEY);', _done, _done)
     })
     console.log("i happen before the line above me")
Notice how the lines of code complete out of order. I think it's really useful to think of that as asynchronous code. It appears I'm using async as a term interchangeably with non-blocking... which may not be correct. So it may be the case that my nomenclature is off, but I'm sure I got that from somewhere. Perhaps a lot of people were referring to node as async in the early days, I'm re-watching this: https://www.youtube.com/watch?v=ztspvPYybIY now, but it doesn't look like Ryan Dahl uses the term async.

Anyways, looks like I'll have to train myself to use the right word for it. Thanks for pointing that out without making me feel dumb or being all insulting and internet-y. :) I really appreciate that.

EDIT: Hmmm... additionally, to be fair: it appears that some agree that it is OK to refer to parts of javascript as async http://stackoverflow.com/a/16524240/398055 so it might not be perfectly accurate, but it isn't wildly inaccurate either.

Re:A love letter to jQuery by spoiler on Saturday February 27, 2016 @04:17PM (#11188550)
I am 22, and I have used jQuery. I loved jQuery, and it was a fascinating library that solved a lot of problems. It is still a great library, if one needs to support legacy browsers.I also think that jQuery influenced the DOM API to some extent; good things were adopted, bad ones were improved.

However today, I don't think it's as useful—I am not saying it isn't useful—as it once was. The overhead to support multiple modern browsers is usually very low, and often it's even none.

I also believe most of the problems people point about jQuery is that at some point a lot of confident, but bad developers, started using it and somehow jQurey unjustly gained that bad reputation.

Re:A love letter to jQuery by DonHopkins on Saturday February 27, 2016 @04:46PM (#11188669)
It's the people who "program" in jQuery as a way to avoid learning JavaScript who mess up its reputation.
Re:A love letter to jQuery by danielsamuels on Saturday February 27, 2016 @03:34PM (#11188363)
I'm 24, but I grew up supporting IE6 and remember trying to get cross compatibility working for the mess that we called 'browsers' back then. It's been great to see the evolution of Javascript over the last 10 or so years, it's fairly obvious how many of the new features we take for granted came from jQuery originally.

I do avoid jQuery now though, I can't remember the last time I used it.

Re:A love letter to jQuery by FnuGk on Saturday February 27, 2016 @02:41PM (#11188133)
i am confused. What do you expected them to be? and why is it relevant?
Re:A love letter to jQuery by simonw on Saturday February 27, 2016 @02:55PM (#11188194)
If you were writing JavaScript 8 years ago, a library like jQuery was pretty much essential to help patch over the enormous numbers of browser bugs and differences between the various IEs, Firefox, Safari and Opera.

My experience is definitely that developers under 25 are much less likely to understand the historic context that jQuery came from, and hence have less respect for what it achieved (and continues to achieve).

Re:A love letter to jQuery by blowski on Saturday February 27, 2016 @03:14PM (#11188268)
I've had exactly this type of conversation with a young junior dev. "AJAX requests are easy - just use the Forms API." They have no idea that in 2005 I read a whole book on 'how to make an AJAX request'.
Re:A love letter to jQuery by icebraining on Saturday February 27, 2016 @05:34PM (#11188814)
Just getting a reference to the XMLHttpRequest object required twelve lines of code :|
Re:A love letter to jQuery by tlrobinson on Saturday February 27, 2016 @04:03PM (#11188479)
This seems to suggest that we really don't need jQuery any more.
Re:A love letter to jQuery by coldtea on Sunday February 28, 2016 @10:09AM (#11191056)
Or that, you know, the younger generation rediscovers the square wheel.