It says they tried not to be biased, but it doesn't look like they tried at all. Apparently every design decision made in Vue is superior. This isn't a fair comparison and shouldn't try to masquerade as such, it would be fine if it was positioned as an opinion piece on why we think Vue's approach is better instead of a "perfect framework" ad it is.
But after using JSX I'm never going back to a templating system. JSX has an intuitive direct mapping to JS that lets you use the full power of a programming language without needing to learn another crippled DSL syntax.
If you've never used React before after reading this you could be forgiven for thinking it's a complex monstrosity needing a week of prep to build a HelloWorld app which is a biased gross over exaggeration. React has one core concept, Components, which is easier to create, encapsulate and reuse better than anything else I've seen. I also believe in React's being able to use JS for Views, Style and Behavior making it easier to encapsulate cohesive Components.
I consider Ecosystem, community, dev resources / backing, encapsulation and reuse integral for adopting a framework which React wins easily on but is quickly disregarded here.
Whislt this is a biased guide Vue has convinced me enough to evaluate it, I'm especially interested in its performance and being able to reference it like a jQuery script tag which I believe is the biggest shortcoming of modern JS fxs which has succumbed to npm micro module madness inflicting complexity and friction on all developers which is IMO the major source of complexity when adopting a modern fx.
I like that Vue seems to be carrying Angular1's torch of "make it easy for non-programmers to write templates" but I feel like that has been an illusory strawman from the start.
Not only does it mask the fact that the supposed non-programmer template designer would still have to understand HTML and CSS yet somehow not have even the most basic knowledge of JS, but they would still have to be able to use whatever build tools are necessary to actually render those templates, including version control and node.js (which is the de facto platform for client-side build tools these days). The target audience seem to be old-school "webmasters" who FTP their PHP templates to the live server yet we're talking about technologies requiring a workflow that already precludes them.
So we're talking about a scenario that only benefits people who already tick all the boxes for "front-end developer" except they apparently suffer from a nervous breakdown if they have to look at an if-block or understand a for-loop yet they'll be fine learning another template language that is typically based on JS expressions anyway (though Angular was guiltier of this than Vue).
Maybe these people exist. Maybe there are teams where optimizing technical decisions for these people results in a net benefit. But I strongly doubt that this scenario is so widely applicable that this design decision makes a framework inherently superior when the cost of JSX to a team of JS devs is practically nil.
I am that person. Coming from an electrical engineering/Low Level programming background
HTML is a Markup language. I get those.
CSS is stylesheets and in my opinion very straightforward. The hard part is making designs that are functional and beautiful and making it cross browser compatible, but CSS has very few warts if the "wtf" variety
JavaScript and it's ecosystem is disgusting for me. It's not hard, I can write stuff in it, it's ugly. I just don't want to touch it if I can avoid it. Pure personal preference. Typescript and elm help me to minimise the work I have to do in that mindspace. Maybe vue aims at similar clientele with less taste for statically typed/functional programming
You admit you understand it and it's just a personal preference. Therefore you're not that person.
The stated goal of making templating accessible to programmers isn't to shield people who don't like JS, it's to shield non-programmers who don't understand programming languages. This is the absurdity I'm arguing against.
If it was just about making JS look different, there would be no need to use Vue in the first place.
I thought the point also was not to mix the programming language in with the display logic, which was done a lot with PHP in the past, resulting in messy applications.
Yeah, and that idea was always pretty stupid. They'd create some some new, terribly ugly, syntax. Maybe at first functions were limited, nut inevitably, they'd add connectors for every function in the "host" language (php/js/...). Or just something generic, allowing you to do something like <this-is-definately-not-a-programming-language native="Kernel.exec('sudo rm -rf /'"/>.
OF course it meant you had to learn a new language, even though you were perfectly capable of perfectly suitable language already. But at least designers didn't have to learn "programming".
There's no way around this. Templates need logic, mostly for loops (or maps, same difference), or dynamic formatting.
Templates need some level of logic, yes. Putting the entirety of the business logic in your templates is not only bad, but dangerous. Because unless you're replicating your business logic in your non-template code, I can change things in the DOM, and potentially corrupt the system.
Unless I completely miss the boat about how Angular/React/Vue/etc are supposed to be used. I only know from my previous years of seeing it done in the way I mentioned above, and every time, the work always ended up duplicated in the non-template code.
> "make it easy for non-programmers to write templates"
> I feel like that has been an illusory strawman from the start.
You're right, the nonprogramming web designer may be a rare bird. Even if they exist, they don't exist long. I have always believed that someone can pick up the rudiments of programming in a couple of weeks. Someone who starts out writing HTML and CSS will eventually rub up against JavaScript. In time they will incorporate a snippet of JavaScript here and there. First it will be mindlessly pasted from the Internet. But after reading enough blogs, they will be bundling React and adhering to the functional programming paradigm to load their own blogs. Come to think of it, I wish there were more people who knew just HTML and CSS.
More seriously, I myself know HTML, CSS, and a few programming languages, but unless the page is very simple I still like to separate things into template files. I prefer Handlebars, but often I just use PHP's alternative syntax.
> apparently suffer from a nervous breakdown if they have to look at
> an if-block or understand a for-loop
Well, if-blocks and for-loops are the two main pieces of logic I think every template syntax must have. Mustache said it wrong. Templates should not be "logicless." Templates should be "processingless": they should not have side effects or further manipulate the data. This is okay:
<p>Any items you have will be listed below:</p>
<? $q = pg_query('select * from items') ?>
<? if (0 !== pg_num_rows($q): ?>
<ul>
<? while ($item = pg_fetch_assoc($q)): ?>
<? if (userCanSeeItem($_SESSION['username'], $item['id'])): ?>
<li>
<a href="<?= h($item['url']) ?>"><?= h($item['name']) ?></a>:
<?= h(ucfirst($item['description'])) ?>
</li>
<? endif ?>
<? endwhile ?>
</ul>
<? else: ?>
<p>none</p>
<? endif ?>
The problem is not ifs and loops nor the use of raw PHP, with its alternative syntax. The problem is the database calls (pg_query), controller-esque function calls (userCanSeeItem) and text clean-up (ucfirst). This kind of stuff should be hidden inside a model-esque function (getItemsOfUser($username)) which returns a ready-to-print associative array.
I use templates not because I'm scared of all that. Instead it's sort of like the recently re-loved functional programming paradigm. Template files should have no side effects. I know that once I stuff the data into a template, then nothing else will happen besides output to the user's screen.
Vue's single-file components (html, js, and scoped css) are super-appealing to me.
The message is something like: "These concepts you understand and use all the time? We aren't going to make you abstract them away. We're going to use them as the foundation for a new way to build apps."
> Maybe these people exist. Maybe there are teams where optimizing technical decisions for these people results in a net benefit.
I've seen this reflected strongly in large companies on the east coast. Design staff is expected to know HTML/CSS, but aren't exepected to have more than a cursory understanding of javascript.
Design will often start with HTMl prototypes, then do a handoff to engineering who will using a JS framework to wire it into the real app.
Lately, though companies are swithcing to React, because JSX seems similar enough to HTML that people presume that design staff will be able to understand it.
I'm in a startup using Angular for some of our stuff and we get the same benefit. Our primary design guy is able to create pages before devs wire them up, and make a lot of the UI changes directly himself without our help.
I hear you. JSX sounds like the wrong thing to me, as well.
(but I'm also working on a long Angular 1 project at my job, so I "may" be biased)
I REALLY like that Angular 1 allows you to simply make a mockup, then add the "programming stuff" behind the scenes. WITHOUT an enormous build chain (I have enough of that on the server side already, and the server is not Node for historical reasons - I'm not sure about node yet, and even if I wanted it, that just won't fly in my group)
I've had the misfortune to work with a Java developer who insisted he didn't know JavaScript and therefore wouldn't ever touch JavaScript code even if it would have saved everyone a ton of time. Yet at the same time the Java code would often generate HTML or even JS code directly.
There are companies with stupid silos like this, but for the reasons I laid out I doubt they actually benefit from the "toy-language templates" approach -- even in the aforementioned company the non-developer designers would implement the entire layout as a mockup in HTML and then toss it over to a frontend dev who would cut it up and add the actual template logic (because although the template language was "easy" non-programmers couldn't be "trusted" to get the logic right).
I see Angular's directives as a pure convenience compared to most every templating engine I've used across languages, never considered it something that makes it accessible to non-programmers. I'd actually think someone who only knows html/css would be more thrown off from a page with random, unsanctioned (by W3C), tags and attributes that may or may not reveal what they actually do.
As a programmer I don't want to write long templates, I seriously prefer Jade/Pug for that reason. When I can't use them for a client I typically use them to do all initial work, compile them to HTML, then make whatever minor changes from there.
Consider ng-for:
<div data-ng-for="y in x">
<h1>{{y.title}}</h1>
</div>
The ASP.Net solution is a pain, a function with HTML string template to dynamically add elements to a "runat" div.
This PHP example seems more idiomatic, at least to me, yet takes more to write
The jQuery/plain JS solution, especially before ES6 is not preferable by any means, especially beyond this simple example.
var body = document.getElementsByTagName("body")[0];
[...].map(function(y){
body.innerHTML +=
"<div>"+
"<h1>"+y.title+"</h1>"+
"</div>";
});
Unlike all the other solutions, angular has 2 way data binding so when you programmatically add elements to the array in ng-for, they are added to the DOM without a reload.
So, is the goal of a programmer to simply write more code? If so, then Angular is definitely not for programmers.
Is the goal of a programmer to solve problems? If so, Angular is definitely a tool for programmers.
Aside from the HTML-like syntax this is vanilla JS. And "y.title" is already auto-sanitized so you don't have the XSS vulnerability as in your jQuery solution.
Yes, that's intentionally verbose, making you aware that this is a potentially dangerous. But to paraphrase the old saying: make the safe things easy and the unsafe things possible.
Angular and friends require context switching. Good luck if you're using non-standard data structures or need slightly more complex filter or iteration logic. And especially in Angular (1 more than 2) you also need to keep in mind the variable scope within the DOM tree and which variables, directives and components you can use where.
With JSX it's just JavaScript and the scope is just your local JavaScript scope. Instead of having to remember all the idiosyncracies of the framework's own implementation of a for-loop[0] you just have to know JS.
I'm not saying Angular is not for programmers. I'm saying the design goal of Angular1 was to make it easier for non-programmers to write views/templates. It's even in the name: as much fun as controllers, components, directives and two-way bindings may be, the raison d'etre of AngularJS resides between the angle brackets.
Yes, that's what I do. I also think it's fine to use omit trailing semicolons and to use short-open tags (I already labelled the file .php --- why do I have to keep saying "php" all over it? And I'm not usually outputting XML.)
Unrelated question: was there a reason you swapped the iterator and container (x and y) in your angular example compared to the others? Just to keep 'x' before 'y'? It confused me a bit.
But you are right, i am not sure to use a template system again. But the advantage is cleaner code, many people change quickly to spaghetti code in jsx (mix all together, ifs, loops, ...).
Spaghetti code refers to poor coupling not cohesive encapsulation or being able to build complex smart views which can easily be refactored using native programming language constructs. I'd much prefer having a single powerful language for everything instead of forced artificial friction on having to spread your component over multiple DSLs.
> being able to build complex smart views which can easily be refactored using native programming language constructs
For the record, JavaScript can not be easily refactored, since it's a scripting language with no strong types and no compilation phase, so to conduct a complex refactoring you will have to load all code base in you head and that's far from being easily. TypeScript for example is another matter.
Don't loose the point, I was written about another thing, not about tests. Every time when fanboys of functional programming (and scripting) are trying to argue that functional programming is a silver bullet they do write about tests, it's not an argument, tests are exists for any kind code no matter the code nature. Tests won't help you a lot with code analyzing, automatic refactoring and tracking down from where things came (coupling). In case of scripting (and functional programming) you will have to load all the code base in you head and only then you will be able to make some architectural decisions or perform a complex refactoring. Tests just help you to not break the system logic doing refactoring, that's it.
> Also, no amount of compiling or strong typing is a sufficient alternative to regression testing when it comes to refactoring.
No one was saying that compiling or strong typing is alternative to regression testing, don't know where you have got that idea.
> I consider Ecosystem, community, dev resources / backing, encapsulation and reuse integral
Yes. No doubt.
> which React wins easily
I disagree. The old react docs were shite compared to Vue's. Not once did I feel the need to ask google. (Have yet to go through the ones released yesterday)
The tools that the team provides (router, vuex, resource, cli, ..) work perfectly.
Where react clearly wins is with 3rd party libraries and learning resources. Egghead is a perfect example.
Depending on what you prefer one might win over the other, but it's not _clear_ by any means.
It's totally fine to pick one, learn it, and never think about the other. One way is the old way, one way is new. Simple as that. There's never a case where you should use both.
Of course they think the design decisions are superior, since they made them after looking at all the existing options. It seems reasonably balanced to me.
But after using JSX I'm never going back to a templating system. JSX has an intuitive direct mapping to JS that lets you use the full power of a programming language without needing to learn another crippled DSL syntax.
If you've never used React before after reading this you could be forgiven for thinking it's a complex monstrosity needing a week of prep to build a HelloWorld app which is a biased gross over exaggeration. React has one core concept, Components, which is easier to create, encapsulate and reuse better than anything else I've seen. I also believe in React's being able to use JS for Views, Style and Behavior making it easier to encapsulate cohesive Components.
I consider Ecosystem, community, dev resources / backing, encapsulation and reuse integral for adopting a framework which React wins easily on but is quickly disregarded here.
Whislt this is a biased guide Vue has convinced me enough to evaluate it, I'm especially interested in its performance and being able to reference it like a jQuery script tag which I believe is the biggest shortcoming of modern JS fxs which has succumbed to npm micro module madness inflicting complexity and friction on all developers which is IMO the major source of complexity when adopting a modern fx.