Jokes aside, I'm not sure "afraid" is entirely right; though it does reek of that same paranoid fear of objects we see with long-time PHP developers who still refuse to use PDO or choose the pointless mysqli_ function wrappers. Perhaps just outright ignorance is more appropriate? I'm really asking because with a certain client I just dealt with a major XSS hole that was screwing them entirely because they were using jQuery's html() to slop markup -- including user defined values -- into the page.
As such whilst this is a legitimate question on my part, there's a good deal of venting thrown in.
Either way, I see very few developers out there who ACTUALLY use the DOM. When people talk about things like jQuery providing DOM manipulation tools I genuinely have ZERO HUFFING CLUE what they're talking about! Using a bloated wrapper for Element.queryAll to grab nodes or nodelists and then screwing around using (the outdated outmoded possibly insecure) innerHTML methodology to slop stuff into the page is NOT working with the DOM, and it sure as shine-ola isn't good practice. Same goes for the idiocy that is React when used client-side you see the same half-witted methodology only further pissing on the page by using string processed templates and exchanging full markup from server-side for AJAX style operations -- either passing more data over the connection than needed or making the client-side scripting five times larger and ten times slower than necessary.
... and it's not like jQuery doesn't provide append(), prepend(), before(), after() -- even text() -- but it seems like nobody ever uses them and instead insists on writing markup as strings and shoving them in with html() regardless of the middle finger to performance, battery life, or security!
What is it about document.createElement, Document.createTextNode , and walking the DOM that people find so intimidating? Is it "wah wah, eyes dun wants two haz two typez alls tat oot" laziness? Just plain ignorance?
Going directly to the DOM avoids so many headaches, is faster and uses less memory since it bypasses the parser, and is inherently more secure since if you are plugging in user data with createTextNode it is impossible to create a XSS exploit... so why don't people do that and instead insist on screwing around making massive nodelists for EVERYTHING, slop content in with innerHTML (or innerHTML-style 'markup in the scripting').
It's even more confusing when that approach just means shoving as much if not more data around than a bloody page-load would have if their markup wasn't bloated crap. I mean I know a lot of people have bought into the "pageloads are evil" LIE brought about by using 60-100k of markup to do 8-16k's job, 256-512k of CSS to do 12-32k of CSS' job, and the mind-numbingly idiotic megabytes of scripting where 90% of it likely doesn't even belong on a website in the first damned place and the rest has no business breaking 64k before minification... but really folks what the blazes is going on?!? Blind copypasta from bad books or worse online tutorials? "Wah wah, I dunz wanna learns?" Is there some mental block involved in how/what the DOM is much less how to use it PROPERLY?
I mean I know most people dive for jQuery or React (or vue or any of these other halfwitted frameworks) before they know enough about HTML/CSS or even JavaScript to have any clue what utter shit those systems are, but whiskey tango foxtrot people?!? Walking the DOM instead of nodelists isn't rocket science and is just so much faster in most usage scenarios than trying to treat a nodelist like an array.
... and remember, in Soviet Russia, the DOM walks you.
Notice I was specifically pointing at the functional "wrappers" of mysqli, not mysqli itself. myslqi_prepare($db, '') instead of new $db->prepare('') feels like a pointless code-wasting crutch in PHP that's in there JUST for the people who are deathly afraid of objects. (and in PHP that actually seems to be a thing, people LITERALLY afraid of objects!) I often think those wrappers make it TOO easy for people coming from the old mysql functions to just slop their existing code -- variables in the query strings and everything -- over to mysqli whilst dodging the ENTIRE reason for the change! It's not different enough to force the required change in mindset.
That said, one of your arguments?
$conn->setAttribute( PDO::ATTR_EMULATE_PREPARES, false );
NEVER understood why that's not the default state, particularly given how the garbage emulation screws with LIMIT. I actually set it in my php.ini file because I've yet to hear one legitimate reason why it's not smart enough to go "hey you're using mysql or mariadb? Well then skip the emulate"
... and I think you meant DB engines not JS. :D (easy typo)
Being able to hit multiple DB's was the tipping point for my favoring PDO, but there are things in mysqli that just piss me off -- like how AWKWARD getting results out of a prepared query are -- let's face it ->bind_result sucks -- or that mysqli::execute and mysqli::query return an entirely different object from ::prepare so if you want to switch between them you basically have to rewrite the entire codebase. THAT'S STUPID! ... and I know some developers who are using mysqli but refuse to use prepare because of it and just vomit their variables into the query string -- AGAIN missing the entire reason for the change!
You can blame the people for not learning it, but you have to ask WHY they are not learning it. That's why I'm often pointing at the frameworks as one of the causes on the JavaScript side. People diving for it before they know enough to realize the methodology is wrong, but blindly parroting how great it is because everyone else is.
At least with PDO anything that might have a result set returns PDOStatement so if you want to add variables to the query after the fact or stop passing variables you don't end up rewriting the whole blasted thing.
That you can have labels as placeholders is also win the moment you have any significant number of variables to pass. You can only have so many question marks in the query before it becomes an impossible to follow mess... though conversely all those separarate PDOStatement::bindParam() do get tired when building a POEM (prepare once, execute mostly) statement. Praise be in PDO you can also pass an indexed array to PDOStatement::exec when you are only going to execute once.
I'm proud of you Jason, you only used the term "scripttardery" once through this entire discussion, good job in eliminating this highly offensive term from your vocabulary! (this is not a sarcastic post, we've discussed this in the past and I'm happy in fooling myself something I may have said got through :) )
As for the question at hand, I'm going to take a different approach in my answer. While I agree that using pure JS is more efficient from a loading point of view, I see the use of frameworks and libraries as using different tools for what you need to get accomplished. Would you only use a hammer to build a house? Well, technically, you could get a lot done with a hammer, but it would take a lot longer. Libraries and frameworks are similar. They allow developers to get a lot done, and considering how difficult and complex web dev can be, these tools allow folks who may not have the time to learn all aspects of web dev to be able to get a lot done.
As for your accessibility claims, I don't see how that's relevant to using libs and frameworks. You either know about accessibility and plan on addressing it, or you don't. The tools you use won't save you one way or another.
Interesting conversation !! I think its hella war between pro-devs here... hahaha
/grab popcorn
P.S. I can understand aliases window.$ = (selector, node = document) => node.querySelector(selector);
What?? :-\ It sounds lot like you know a lot, but then it also sounds like you haven't touched a new framework in years.
There certainly are disadvantages to manipulating the DOM directly with native methods, namely tight coupling of application logic to the presentation/rendering system. JavaScript logic is not easily unit-testable when it directly manipulates the DOM. You also cannot swap out DOM rendering for another rendering system, such as how a framework like NativeScript does so that it can render native GUIs on Android and iOS. You can't do server-side pre-rendering such as how Angular Universal does.
I honestly don't understand what your gripe is about. Do you really need to squeeze a small, negligible amount of performance out of your JavaScript code? Forgive me if I'm mistaken, but if you've maintained a JavaScript codebase with 10,000 LOCs, the cognitive overhead (and time!) that another layer of abstraction saves me is well worth it. Besides a framework like Angular with its ahead-of-time (AOT) compilation can preprocess the HTML for your components at build time to generate optimized JavaScript that will do direct DOM manipulation under the hood.
I have to ask Jason! What are the drawbacks of your suggestion? Seriously. Can you explain the negative side too?
What is the problem with the DOM? One of the most reasonable thing's I've heard is that the DOM does have side-effects. That's not really relevant outside of a functional approach but react insist on being functional so
A to A' obviously seams important the idea was to have no sideffects and a predictable mutation pattern. There is ofc some BS involved but luckily most devs are "users".
So in most cases I personally would stay declarative (HTML) with minimalistic CSS. because I don't need a rocket engine behind everything.
But as soon as my layout uses non synchronous update cycles so for example I have a component in the layout that should update on a dropdown change. The app-state to render-state issue is slowly starting to arise.
This is where react for example could come handy. I personally think it's still to bloated for such a simple task but the reasoning is more sensible. As soon as the page is not contained into 1 single Request and Response people tend to get confused.
The question of when a framework makes sense is like everywhere 1st usecase. It's always the question what we're trading. Do we need to know all cycles of updates? do we need to understand how an event really bubbles?
In my opinion based on my observations a lot of the modern JS-devs are framework users, they have to deliver and deliver and deliver so they try to push the thinking to their tools. that's what Gabor for example said "focus on the business-logic".
In my opinion, if you don't have a page that needs to be highly interactive .... you have to be an unexperienced programmer or you have way to much time, to add anything complex to your frontend as a complete framework.
But as soon as interactive asynchronous state changes / reactive state changes are necessary you probably have to much time or you are a classic old dog to not at least consider using a modern frontend solution for that.
I hope I am not to much off topic with my answer :)
I definitely work with the DOM, but even still I'm not sure if the ways I work with it would set off your alarms or not :D
(Luckily) I don't think jQuery has a lot of traction anymore—even the creator of jQuery has put it down in favor of using React for a few years now—so if anything, I think a more relevant question might be something like:
"Why do developers insist on trying to innovate on top of the DOM we already have with things like virtual DOM?"
Surely some of these frameworks and libraries are reimplementing things we already have, (and sometimes much more poorly), but at the same time I think some of the ways people are experimenting with building can lead to new ideas that will someday get built into the DOM like how some of the handiest helpers from jQuery, and syntax ideas from CoffeeScript have inspired JavaScript features that came later.
While I definitely don't go out of my way to use jQuery or CoffeeScript, I can't deny their influence on the native JS features I learn and use today.
While you definitely won't go out of your way to use things like Vue or React today, I hope you won't deny the impact they will have on the native DOM features of the future!
Because I don't want to spend lot of time at low level instead of implementing the actual business logic. If I would go deep and start playing with the DOM itself I'm really sure I would create my own 'framework' after a while.
Because I always tend to create reusable code blocks. At the beginning I would encapsulate couple of code lines into reusable functions. After I have lot of functions I would try to organize them somehow into larger blocks. At this point I would just reach the package/module step of the progress. Later on I would have many modules so finally I would look for a fancy name and finally have my own framework.
Because I want to work on my real projects instead of my own framework I pick one from outside.
Daniel Lo Nigro
Front End Developer at Facebook
As a side note, there's several features that MySQLi supports that PDO doesn't, so in some cases there's a reasonable reason to avoid using PDO. One difference that I can think of is that MySQLi uses real prepared statements, whereas PDO emulates it by replacing the variables in PHP (as opposed to doing it in the database engine). PDO is designed to support multiple different DB engines, so by definition it doesn't support many MySQL-specific features. Having said that, PDO is usually the better choice.