9 ms·
I appreciate the clearer naming of the built in methods. - `document.querySelector` vs `$`. - `element.addEventListener` vs `$element.on` JQuery really has so
by charrondev 7y ago
I appreciate the clearer naming of the built in methods.
- `document.querySelector` vs `$`.
- `element.addEventListener` vs `$element.on`
JQuery really has some confusing behaviour too. JQuery sets the target of the event as `this` inside of the method. Native makes it an event property.
- tambourine_man 7y agoI hate the verbosity of it. The “fun” part of jQuery is important to its success.
- greggman2 7y agoYou can repo the shortness with a few tiny functions you put in your own library. Probably less than 1k vs all of query. Also some programmers opt for readabiltiy over terseness.
- wolco 7y agoMaybe it's just me but the terseness is beautiful. I've been changing my style to be more terse but that makes it more readable or easier to see the abstraction concept rather than the details.
- greggman2 7y ago> terseness is beautiful. I'd much rather read rect = element.getBoundingClientRect() area = rect.width * rect.height velocity += acceleration * deltaTime position += velocity * deltaTime than r = e.g() a = r.w * r.h v += a * d p += v * d but to each their own. Google, Apple, Microsoft, Facebook etc all specifically say terseness is not a goal and say to use whole words so naming a function '$' would be explicity against their guidelines. I suspect there's a reason for that. The most obvious is I don't know what 'a' or 'd' or '$' mean without digging through the code but I do know what 'area' or 'detlaTime' or 'getElementById' mean
- krispbyte 7y agoI hate the "fun" of debugging jQuery. I'd rather have a plain boring easy api.
- dsego 7y agoWhat's there to debug?
- partialrecall 7y agoPersonally I don't see the problem with code that's verbose in this manner. If the right names for things are chosen then the code written with those names will read like prose, which makes it pleasant for a programmer and approachable for a self-styled non-programmer. And it's not like it's much more typing, what with modern completion systems in modern text editors... One of the reasons I like lisp-like languages more than the rest is because hyphen-separated-symbols are a lot easier to read than camelCase, which feels cramped by comparison. (underscore_separated_words is an improvement over camelCase, but for some reason people seem to shy away from it. In any event I think hyphen-separated is superior, since hyphens are used to conjoin words in English prose, while underlines typically aren't.)
- Carpetsmoker 7y agoI find long names like this much harder to read because the entire text/code is so much more dense, and it really adds up quite fast if all function/variables are dense. It gives a "wall of text" effect. It reminds me of reading 17th century dense English. I don't see how query or select is any less descriptive than querySelector. I find that names are rarely all that useful anyway, since you can't capture the full effect of a function in a name in most cases. I once named a method mkdir() and then someone commented that it was "obscure", so it got renamed createDirectory(), then someone commented that it was actually creating all intermediate directories, so it became createDirectoryTree(). This still doesn't really communicate that it won't error if the directory already exists, so I commented it should really be createDirectoryTreeOrDoNothing().
- partialrecall 7y agoI'm not sure what you mean by dense. If two symbols mean the same thing (both reference the same procedure) but one is longer than the other, then surely the longer one is less dense, no? In physics, density is a measure of mass / volume, so in programming density would be a measure of meaning / code length `mkdir` is immediately obvious to someone like you or me that has a background in dealing with legacy system design (namely, any Linux/Unix/BSD/GNU system that all derives from early 70s design ethos (or hardware limitations..)) but to somebody who's not already steeped in this tradition, it's basically a bizarre incantation. And mkdir is far from the worse of it; once you learn what it means it's easy to create a mnemonic mapping between `mkdir` and "m[a]k[e] dir[ectory]". But what about something like `ln`? Obviously that's "natural logorithm", everybody learns that in highschool. Wait no, it's not that at all. It's "[make] l[i]n[k]" Frankly, that's crap. Contrast with `make-file-or-directory-link` from racket. It means the same thing but it's more than 10x as long (less dense) and there is simply no way you could mistake that for a natural log function.
- earthboundkid 7y agoThis is the dumbest argument. `$ = qs => document.querySelector(qs);` Done.
- teh_klev 7y agoNo need to be rude. A simple, "I disagree, how about..." would have been more civil.
- earthboundkid 7y agoYou’re correct. I just don’t see any argument for jQuery that doesn’t boil down to “I don’t want to take the time to learn how the DOM works” at some level, and it makes me mad on the internet.
- dsego 7y agoWhy spend time on learning a bad API when there is a nicer one? Ergonomics matter, but hey if you are masochistically inclined, go ahead.
- earthboundkid 7y agoBecause there is no other API. The DOM is the API. If you only know jQuery, you're shooting yourself in the foot because you can't do anything more advanced than class swizzling. You have to learn the DOM to use the web well, might as well use it directly instead of through a pair of boxing gloves. Also, I don't actually find jQuery to be nicer. It wraps its nodes in its own objects, but then you end up getting native DOM elements passed to you up anyway. It's an extremely leaky abstraction to the point that it is not nicer. As I said, if you think "document.querySelector" is a mouthful, just alias it and be done.
- tambourine_man 7y agoNot every code you deal with is your own. Besides, terseness is one issue, but far from the only one: https://news.ycombinator.com/item?id=20978608 https://news.ycombinator.com/item?id=20978608
- greggman2 7y ago"this" is also set by native listeners. IIRC it's the elem the event was added to where as event.target is the element that the event was cause from (often not the same). Example: https://jsfiddle.net/greggman/qpb7ct15/ https://jsfiddle.net/greggman/qpb7ct15/
- libria 7y agoThe biggest irritations for me: * Variable argument types determine different kind of behavior, like ajax taking a string or object as 1st argument. Other functions take a function or string as a parameter. I'd much prefer it enforce a single style or define a new method, ajaxurl() and ajaxobj(). * naming of `off()`. In this context, off is not the opposite of on. On here means 'in event of'. A better word would be 'cancel' or 'mute' or 'ignore'. element.on('click', dostuff); element.ignore('click'); off('click')/off('mouseover') sounds like if you click/hover off the dialog box which is incorrect.