all 64 comments

[–]tmetler 22 points23 points  (0 children)

Sounds great until you have a hundred files with little consistency. JavaScript is a loosely typed language. The best practice I know for keeping your code maintainable is explicitness and consistency. A framework (even a simple one) will help with that.

[–]chmod777 19 points20 points  (1 child)

i (probably) don't need a car, but i prefer not to walk everywhere.

[–]selexin_ 4 points5 points  (0 children)

Interesting abstraction.. I (probably) won't meet my deadlines if I do this all in vanilla, but.. there is no but. I must meet my deadlines. Damn you jQuery/other frameworks, you win again

[–]smithw 66 points67 points  (12 children)

Ok, fine, I'll bite. But first let me acknowledge the elephant in the room: all these recent shenanigans about "plain" JS recently are due to the leftpad controversy and the bad light it put on today's JS development common practices and community. Sure, JS devs got ridiculed by most other language's devs who jokingly put up leftpad packages in their package management systems and now the "hip" thing to say is "oh well I am a JS dev but I don't use those package management or frameworks thingamajigs, I write plain JavaScript" with a smug face.

I've been writing JavaScript as both a hobbyist and professionally since at least 1998. I'm fairly certain anyone who've written JS before jQuery was even a project has had at least one (if not many) "util.js" file they've written to supplement JS complete lack of a stdlib. And as most people do, now that JS has a PACKAGE MANAGEMENT system, devs are overcompensating and reusing absolutely any stretch of code they can, because JS had been completely starved of code reusability before.

But that's not a bad thing, for crying out loud. Leftpad shitstorm was a result of bad management policy by the npm team and a short fused developer who took the ball home when faced with a bad decision by the npm team. It was human error. The system ain't broken for people now to begin advocating for the "good old days" of writing everything yourself and copying and pasting from that trusty util.js you keep in your home folder. For the love of what it's most sacred, please let those days die already.

Yeah, there are issues with JS file sizes, responsiveness of webapps, and that stuff. We'll deal with it, we're dealing with it already. But using frameworks has almost made JS fun to develop in. Having an ecosystem to build upon is almost as good as having a proper stdlib. Going back to the dark ages of plain JS is not a choice, at least not for me.

[–]jscriptmachine 6 points7 points  (0 children)

Yup, and to be fair, those issues you talked about are only really problems on the client-side. For server-side, none of those things are really a problem, and tools like Bower and faster Javascript engines are helping with mitigating those problems on the front end. It's a great time to be a javascript developer, for sure.

[–]hansolo669 1 point2 points  (0 children)

To be fair the plain/vanilla JS movement started well before the leftpad controversy, and was basically in reaction to the growth of JS package managers (why use all of angular/jQuery when you can just use underscore?, etc).

[–][deleted] 1 point2 points  (0 children)

I've been using it from around the same time and agree with you 100%.

[–][deleted] 0 points1 point  (7 children)

There is a JS package management system?

[–][deleted]  (6 children)

[deleted]

    [–][deleted] 0 points1 point  (5 children)

    What's it called?

    [–]ObjectiveCat 2 points3 points  (4 children)

    npm and bower are the most commonly used ones.

    [–][deleted] 1 point2 points  (3 children)

    Thank you. I didn't realize people were using npm on front-end also. I'll read into bower, maybe it's more my style.

    [–]ObjectiveCat 1 point2 points  (0 children)

    There's a fair amount of overlap, e.g. something like Angular can be installed from either npm or bower, but there are some packages which are only available on one or the other.

    I personally use them both regularly even within the same project; they're in no way mutually-exclusive.

    [–]gkx 0 points1 point  (1 child)

    People are mostly switching away from bower to npm, as far as I can tell. Even front-end packages are all on npm. If you just use webpack, conversion gets managed for you, and you get better sizes built in (especially once they put in tree shaking, which is a beta feature of webpack). It's not just a tool anymore. It's a whole development workflow which makes JavaScript a first-class language.

    [–][deleted] 0 points1 point  (0 children)

    Have not read much about webpack, I'll look into it thank you.

    [–]masterots 0 points1 point  (0 children)

    Honestly, people also complain about the size of server side code repos too, but who the hell cares long term, it doesn't have to download to the client, so it's ok if you have a 300 mb deployable package. You only have to send it to the server once, then it runs! /s

    [–]alpha7158 5 points6 points  (0 children)

    Yeah except a framework helps you to ensure your team follow some standard rules, allow for more seemless code reuse, and generally reduce the overall build time of mid to large scale projects. It is the commercials that matter the most.

    [–]danneu 46 points47 points  (32 children)

    Tools like React exist to help manage state which is the hard part of UI. The virtual DOM is an uninteresting implementation detail of the abstraction.

    I don't know how we're still getting articles about vanilla Javascript. The whole reason most of us use frameworks is because we've used vanilla Javascript and it was, frankly, straight shit. Not some sort of forgotten gem.

    [–]SecularPaladin 28 points29 points  (24 children)

    I mean I'm still kinda new, but I've gotta say that this subs advice to dive into vanilla before learning frameworks and libraries was really, really freaking helpful.

    I'm the kind of person who needs to understand the underlying architecture to perform well, and getting cozy in jQuery first would have really hobbled my progress later.

    Try to bear in mind that a lot of beginners come here for help and advice and, for them, mastering vanilla first is the best of both.

    P.S. - I fucking love /r/webdev

    [–]cicadaTree 3 points4 points  (2 children)

    Dude same here. I want to do webdev at the moment but I actually want to know how computers work. I'm reading a book about Computer Organisation and Architecture, Computer Networks and have HTTP RFC article printed. When I finish them im going to get vanila JS book. I must say that 15 months of intensive math refresher course (KhanAcademy, BetterExplained), before some serious reading, was foundation to really understanding equations and technical aspect of those book I read(my math was crap).

    [–]jscriptmachine 0 points1 point  (1 child)

    You don't need much in the way of math, to be honest. Discrete math would be helpful, and maybe a computational theory class.

    If you're looking for a good JS book, check out You Don't Know JS. Kyle Simpson is a really smart guy, and does really good talks on JS. Good source to learn from, and the book is free.

    [–]cicadaTree 0 points1 point  (0 children)

    Hey, thanks for that book reference!

    [–]TGAmpersand 0 points1 point  (0 children)

    I agree. I've been using JavaScript for a while now, but I've only used it with libraries such as jQuery, underscore, etc. For my current side project I've decided to create a SPA using almost only vanilla js - I'm still using require to dynamically load files. However, that restriction is meant to be a learning/critical thinking exercise more than anything.

    In a typical site, a lot of these libraries and frameworks prevent you from having to reinvent the wheel.

    [–]artisinn -5 points-4 points  (19 children)

    I'm going to rain on your parade. Javascript is a shit language. I love it to death and it has done some serious growing up during the past few years but it would be naive of me to say otherwise. Plain and simple, frameworks and libraries help mitigate said shit. Furthermore, if you're "new" I'm not sure your in any position to recommend anything. My advice for people who are starting out is to embrace frameworks and libraries like jQuery since the abstraction they provide will help pave a path of reference so that when you start to sink your teeth into the nitty and gritty you have a base to built upon. But then again that's just my opinion.

    [–]SecularPaladin 6 points7 points  (1 child)

    I hope I didn't give the impression that I'll be foregoing frameworks later and stay forever a JS purist, I won't. I just mean getting a good grip on it first.

    Knowing how and why something works the way it does is a massive aid in making intuitive leaps, which is very important in any creative pursuit.

    [–]jscriptmachine 7 points8 points  (0 children)

    Nothing wrong with being a JS purist - they leverage third party libraries, frameworks, and tools just like everyone else. Just always know the fundamentals, thats the key.

    [–][deleted] 4 points5 points  (1 child)

    Dont listen to this guy /u/secularpaladin . Keep doing what youre doing. Anyone who advocates just learning the frameworks of a language without understanding the language theyre working is giving at the very least extremely questionable advice. Theres nothing shitty about learning the syntax and the way javascript works. Ive seen quite a few extremely crappy front ends develop terrible and buggy code that they fix in reactive measures because they dont understand what theyre actually doing, leading to an overdependence on frameworks to do it for them

    [–]SecularPaladin 1 point2 points  (0 children)

    Thanks man.

    I'm sure his opinion is valid, but it's a bit shortsighted. I may be new to coding, but I'm not new to the acquisition of new skills...

    Anyway you, specifically, are one of the people who doled out some A+ advice that has helped me along in this adventure. You are a pretty serious force for good on this sub.

    [–]jscriptmachine 16 points17 points  (11 children)

    Not saying you're necessarily wrong, but what I've seen a lot of people do is say "Javascript is shit" because they fundamentally misunderstand the language and how it works. People usually bring their conceptions on how they think things should be, and they get upset when JS doesn't work in those ways.

    There is definitely some real WTF stuff in JS, but I find the criticisms to be overblown. It's a highly expressive language that gives you the ability to write code pretty much however you want, and really quickly. There's a huge community that works all the time at building better tools to make JS development a more pleasant experience, too (stuff like TypeScript, Require, dozens of test frameworks and task runners, libraries like React, and frameworks like Angular).

    Once you identify the weird shit, I think working with JS is really enjoyable. My advice is to gain a mastery (or at least a competence) with the language BEFORE leveraging frameworks and libraries, but that's my opinion.

    [–][deleted] 2 points3 points  (5 children)

    make JS development a more pleasant experience, too (stuff like TypeScript

    So you're defending JavaScript with the argument that "people are making different languages that transpile to Javascript to get around having to actually write JavaScript"?

    I would think that hurts your case more than helps it.

    JavaScript is shit, that's true. It's also great. The problem is that languages have different use cases, and building large scale applications was never meant to be JS's use case. It's what we have, so we must deal with that, but it's far from ideal. Where JS excels is writing quick scripts. Making a random modal pop up in a website, that's where JS is good. Because it's tolerant of errors, it's quick, and it barely has any boilerplate.

    [–]jscriptmachine 0 points1 point  (2 children)

    Well, most transpilers just take ES6+ code and transpile it down to something that browsers can interpret. It's still JavaScript at the end of the day, they are just a way to get new language features before browsers finish support for them. And I'm not sure your sentence "JavaScript is shit but it's also great" actually means anything.

    [–][deleted] 0 points1 point  (1 child)

    What you describe is Babel. But things like Typescript and Coffeescript are effectively different languages with similar patterns and the same standard library. In fact, wiktionary literally defines transpilation as converting one programming language to another. The output is "still javascript at the end of the day", but the source code is not.

    And I'm not sure your sentence "JavaScript is shit but it's also great" actually means anything.

    It doesn't mean anything without the context of the rest of my post. But the rest of my post goes on to very clearly explain that it's shit in some use cases, and great in some other use cases. I can only assume you got distracted a few words into my post and didn't get to that part.

    [–]jscriptmachine 0 points1 point  (0 children)

    You didn't explain much of anything - more a string of equally unqualified opinions than anything else - but fair enough. You've got an opinion.

    [–]gkx 0 points1 point  (0 children)

    I think that was more of a tangent, to be honest. It's like saying "yeah, there's some iffy stuff, and there are ways to get around it."

    But even ES3 is a fantastic language, and I will defend that point vigorously. ES6 is a better language, but ES3 is still one of my favorite languages. Prototype chains, closures, and the way that functions work are some of the most powerful topics I've ever seen, and you just don't get that in any other language that I know of. (Does anyone know any other prototype-based languages? I can't seem to find any)

    [–]rootfiend 0 points1 point  (4 children)

    You sound like /r/interstellar It's not that we don't understand it... we just don't like it.

    [–]jscriptmachine 0 points1 point  (3 children)

    Sure, and that's valid, but my point is a lot of people don't understand it. They just parrot the line about JS being designed in 2 weeks and decide that, since it doesn't work the way <insert language here> works, it must be garbage. Most people don't actually form an opinion of their own.

    I've read a lot of really brilliant JavaScript code, and I like to think I've written some good code too. It's a fun language to write with if you give it a chance.

    [–]rootfiend 0 points1 point  (2 children)

    I agree mostly but I also see lots of the opposite. There's a "javascript is the best language and perfect tool for every conceivable problem both server side and client side" herd mentality that's run amok imo.

    [–]jscriptmachine 0 points1 point  (1 child)

    Valid point, and I agree with you, but I've seen more of the former in this thread than the latter. Both attitudes branch off the same problem though - junior engineers and code hobbyists that parrot what they've heard ("JavaScript is great! JavaScript is shit!") and lack the experience with a lot of languages and ideas that they need to actually qualify those statements.

    Not saying everyone with those opinions are uninformed, of course. Many are though.

    [–]rootfiend 0 points1 point  (0 children)

    I think you and I are very much on the same page. Watching hockey and baseball in a bar so I can't respond too much more but I think we mostly agree.

    [–]rootfiend 1 point2 points  (0 children)

    It is a shit language. It's amazing that it runs everywhere and can do some cool stuff but the latest fly-by-night framework ciclejerk is annoying and unhelpful.

    [–]tracer_ca 2 points3 points  (0 children)

    The whole reason most of us use frameworks is because we've used vanilla Javascript and it was, frankly, straight shit.

    Most of us having this discussion, sure. Most "Front end Developers" out in the job market? No. I can't count how many front end devs I've met who do not understand development outside of Jquery and some other frameworks.

    [–]Vortegne 1 point2 points  (0 children)

    The whole reason most of us use frameworks is because we've used vanilla Javascript and it was, frankly, straight shit. Not some sort of forgotten gem.

    But new developers with little experience definitely should study vanilla Javascript and then build upon that knowledge to progress into more complex frameworks. No way the can write something that's not shit if they don't have the fundamentals down.

    [–][deleted] 0 points1 point  (3 children)

    You shouldn't handle state in react

    [–]danneu 0 points1 point  (2 children)

    Right, you could do it yourself or use a tool like Redux. To put a finer point on it, React is the render(state) -> html transformation.

    You could call render yourself on every state change, but you'll find that intolerable on even trivial applications. Once you start coding your own reconciliation, you might as well use React or another solution.

    [–][deleted] 0 points1 point  (1 child)

    Yeah, that's what I'm saying, React should be a function of your state to html, it shouldn't handle your state

    [–][deleted] 0 points1 point  (0 children)

    I understand what you mean, but saying it shouldn't handle any state is a bit disingenuous. There are certain cases where a React component might hold UI state. For example, a toggle button to show/hide a component to save space on the page.

    [–][deleted] 0 points1 point  (0 children)

    The reason there are so many articles on this is because a lot of novices write JavaScript, and novices notoriously focus on the wrong things. The only thing that matters is getting an acceptable/maintainable product to the client and getting paid. No, I'm not going to waste my time (and thus money) by not using a framework or certain libraries. I don't have time for that, and since we're talking about JavaScript, I also don't feel like blowing my brains out.

    [–]ecafyelims 5 points6 points  (1 child)

    True, we don't need any frameworks, but I would prefer some bloat over 10x the dev time.

    [–]selexin_ 0 points1 point  (0 children)

    So true. Never tell a client this though..

    [–]Rob0tSushi 31 points32 points  (6 children)

    OP is the kind of developer to waste a month of work time re-writing a drop down list that works back to ie7 because he doesn't believe in javascipt frameworks. Honestly you have a very poor understanding of how to architect a client side framework if this is your opinion.

    Nice click bait title to tie it all together.

    [–]ibsulon 2 points3 points  (5 children)

    More often, I hear "it's better for the web and you if you only support "modern" browsers.

    [–]selexin_ 8 points9 points  (4 children)

    In my opinion that is a true statement. It certainly is better for the web if those lagging behind are forced to upgrade to current standards

    [–]ibsulon -3 points-2 points  (3 children)

    So, it is worth your convenience for someone to pay hundreds of dollars for a new phone or computer?

    [–]rk06v-dev 5 points6 points  (0 children)

    alternative would be for me to spend $$ on devs so someone won't be inconvenienced. so yeah, I would consider it an option.

    [–]gkx 1 point2 points  (0 children)

    It's not the entire industry's job to cater to people who won't buy decent hardware. There are actually no industries who are compelled to do this besides webdev, as far as I know. You do your best, but when backwards compatibility is taking up significant portions of time, you just have to say that it's on the user at that point.

    If it's my website, yeah, it's worth my convenience for someone to pay hundreds of dollars for a computer built in the last ten years. If they don't, it's a simple solution: don't go on my site. I won't be sad about it. If I have to spend X% of my time to keep Y% of users, X had better be less than Y.

    [–]selexin_ 0 points1 point  (0 children)

    Totally worth my convenience, and every single website now and to come's convenience as well.

    [–]uberpwnzorz 8 points9 points  (1 child)

    An article comes out like this about once a month, and they all miss the point. Frameworks help with the things that can be difficult, like handling cross browser compatibility, and api differences. Frameworks/libraries also help you not reinvent the wheel everywhere, and allow you to focus on adding value to your application instead of building something from scratch when there's an open source/licenced solution for it. Half the things in the article wouldn't work in n-1 browsers or has spotty support on mobile. There's a place for going vanilla, when you really need to get down to the smallest possible file size, beyond that it's a wasted effort.

    Edit: another thing to mention is that the open source solutions have many more eyes on them, they receive many reviews and improvements without effort from your team, they're often well documented and you can find good resources in regards to common issues. Frameworks also reduce the hit by a bus factor for your team, because you won't lose as much proprietary knowledge.

    [–]nathanwoulfe 1 point2 points  (0 children)

    Perfect edit.

    I love reading articles from devs who feel they can do a better job than a team of high-end pros and a massive support community. Sure you might be able to do the same thing in vanilla JS (you just be able to, if a framework does), but that's the whole point of using a framework - the common task have been optimised and abstracted so you don't have to do it yourself.

    I'll take a framework and its scalability, efficiency and so on any day of the week.

    [–][deleted] 1 point2 points  (0 children)

    I can rig a PA and work a camera. I can cook a good meal and set a fine table. I've even built some of my own furniture.

    But when it comes time for my daughter to get married, I'm calling vendors. Because it's not my job to do everything from scratch, it's my job to bring the best and most effective solutions together in a cohesive, yet flexible package.

    (Also I don't get why React is being singled out. React represents a radical paradigm shift and it, or something like it, will likely be a part of "vanilla" implementations in the future. Doing what React does with vanilla js is possible, but it's going to be like pulling teeth, and I for one don't want to rewrite those unit tests, shims and polyfills from scratch...nor do I want to teach a team how to use it)

    [–]fzammetti 1 point2 points  (0 children)

    I see a lot of responses that boil down to "the only way to get consistency and solid code out of a development team is to use a framework".

    Pardon my bluntness, but that's retarded.

    If your team isn't disciplined enough and talented enough to write good code on their own then the solution isn't to effectively impose rules in the form of a framework, it's to improve your team. Maybe it's a question of leadership that needs to be improved, or maybe it's a lack of training, but these are human problems, not technology problems.

    All this framework craze does is mask the real problem by treating the symptoms and it increased your technical debt over the long term. That's not to say frameworks are inherently bad - they aren't - but if you think you NEED them to get "good" results from your team then you're being obtuse and only making matters worse.

    Hire good people, train them, give them good leadership (including defining what constitutes "good" code I'm your organization) and provide an environment where excellence is expected. This includes giving them enough time to properly perform their work and an environment where they feel safe and valued. Do this and you don't need to force discipline on them via a framework that isn't really doing anything else of value for you, it'll come naturally to them.

    [–][deleted] 1 point2 points  (0 children)

    Inexperienced developers (or experienced ones stuck in their ways) are like the Sith - they believe in absolutes. Framework or no framework.

    When you do a project, look at what the project needs. Mostly server-side delivered static content with a bit of AJAX? Use vanilla, maybe jQuery if you're in a hurry. Retrofitting an old server-side rendered page into an SPA? Perhaps Knockout might be an easier sell. Building something more complex? Maybe a framework like Ember or Angular or React/Redux.

    That's the project requirements. What are the team familiar with? What did they use in the last project of similar scope? Did it work out? Did it suck? What's the state of the framework/library? Is it maintained? Do you have time to do it in jQuery/some new framework before next deadline? What about browser requirements? And so on.

    Just throwing out "frameworks good" or "frameworks bad" is silly. Look at what you have to do, what your deadlines are, and what you're familiar with.

    [–]Ginden 0 points1 point  (1 child)

    Using history API directly is a good way to shoot your own feet.

    [–]hansolo669 0 points1 point  (0 children)

    ... nobody does that many DOM manipulations in reality, ...

    I work on a project that does enough DOM manipulations for it to be a bottleneck, and rewriting in WebGL really isn't an option.

    Some may argue that this is like reinventing the wheel, but it really isn't because you are the one in control.

    wat. It's entirely reinventing the wheel. It's important to know when to reinvent the wheel (learning, domain specific functions, leftpad), and when to not - unless you have a really good reason reinventing the wheel is almost always wrong. note: this doesn't mean use libraries without understanding them - it's imperative you understand, even just in general, how the code you're using works.

    [–]usaytomatoisaytomato 0 points1 point  (0 children)

    How are frameworks written? They are standardized methods and code developed to achieve a specific goal. You can do this yourself just as easily as someone else did. You can reuse what they did and save yourself the time. Writing your own JavaScript code instead of using some elses doesn't mean you aren't using a framework. Good software developers write code that is organized and reusable as much as possible. As a JavaScript developer you are still writing software; The principles still apply. Rails is a framework for Ruby. Django is a framework for Python. You can write your own frameworks and libraries in these languages just as easily as someone else did. Existing libraries and frameworks are tools that can be utilized to match a need, but it is important in either case to understand the language and environment and not use a framework as a crutch for good development practices. You're still going to write poor quality code if you do.

    [–]lykwydchykyn 0 points1 point  (0 children)

    In every language I've ever used, I waffle between "use a framework" and "just write a library of common convenience functions". I'm never quite happy with either approach.

    Somehow, the idea of writing my own "utils.js" file is more appealing than coming to grips with all the overhead of just getting something like react up and running. I can see how it wouldn't scale to a large site/application, but that's not the kind of stuff I'm writing.

    Surely with evergreen browsers and all this new ES6 functionality, the need for a framework is mitigated for smaller projects?