The Hardest
Problem in Frontend
I’ve worked at a few tech companies you’ve heard of. I’ve been doing this frontend stuff since before the jQuery days. And allllllllll through them. And into Backbone, Angular 1, Meteor, React, and so many more (anyone remember Riot?).
So what's the hardest problem to solve in frontend?
The hardest problem
No... The hardest problem to solve in frontend is easily organization. You think naming things is hard? Try keeping organized a large complex system that evolves over time with different team members coming and going, all with different ideas of how stuff should be written and organized and favoring different patterns. Good fucking luck. It's a ticket straight to spaghetti code junction.
This leads us into…
What the React
community has to say
about React Hooks
egghead.io
Frontend Masters
javascript
testing.com
Google Developer Expert (GDE)
TC39 Paypal Representative
egghead.io
Frontend Masters
javascript
testing.com
Google Developer Expert (GDE)
TC39 Paypal Representative
egghead.io
Frontend Masters
javascript
testing.com
Google Developer Expert (GDE)
TC39 Paypal Representative
TC39
Official React Developer
TC39
Official React Developer
Creator of EmberJS
Framework
Retired core team member of
Ruby on Rails and jQuery
Co-author of The Extensible Web
Co-Founder of Tilde
Creator of EmberJS
Framework
Retired core team member of
Ruby on Rails and jQuery
Co-author of The Extensible Web
Co-Founder of Tilde
Reach UI
ReactTraining.com
react-router
Reach UI
ReactTraining.com
react-router
Chrome Team
Creator of Preact
Chrome Team
Creator of Preact
Chrome Team
Creator of Preact
Facebook Software Engineer
Creator of MobX
Facebook Software Engineer
Creator of MobX
Facebook Software Engineer
Creator of MobX
Facebook Software Engineer
Creator of MobX
Facebook Software Engineer
Creator of MobX
“I’ve seen some version of this conversation happen more times than I can remember. And someone will always say ‘it’s because you’re too used to thinking in the old way, you just need to start thinking in hooks’. But after seeing a lot of really bad hooks code, I’m starting to think it’s not that simple — that there’s something deeper going on.”
— Rich Harris (Svelte, Rollup)
—Dan Abramov, overreacted.io
—Dan Abramov, overreacted.io
—Dan Abramov, overreacted.io
“In a well designed system,
the right thing to do is easy,
while the wrong thing is difficult,
but possible”
“In a well designed system,
the right thing to do is easy,
while the wrong thing is difficult,
but possible”
Vue’s Composition API
Vue’s Composition API
<script>
import { computed, reactive } from 'vue';
export default {
setup: function () {
const state = reactive({
count: 2,
double: computed(() => state.count * 2)
});
function increment () {
state.count++;
}
return { state, increment };
}
});
</script>
<template>
<button @click="increment">
Count is: {{ state.count }},
Double is: {{ state.double }}
</button>
</template>
Vue’s Composition API
<script setup>
import {
computed,
ref
} from 'vue';
const count = ref(2);
const double = computed(() => count.value * 2);
function increment () {
count.value++;
}
</script>
<template>
<button @click="increment">
Count is: {{ count.value }},
Double is: {{ double }}
</button>
</template>
Vue’s Composition API
<script setup>
import {
computed,
onMounted,
ref
} from 'vue';
const count = ref(2);
const double = computed(() => count.value * 2);
function increment () {
count.value++;
}
onMounted(() => {
count.value = 10;
});
</script>
<template>
<button @click="increment">
Count is: {{ count.value }},
Double is: {{ double }}
</button>
</template>
Common life cycle hooks:
Vue’s Composition API
<script setup>
import {
computed,
onMounted,
ref
} from 'vue';
const count = ref(2);
const double = computed(() => count.value * 2);
function increment () {
count.value++;
}
onMounted(() => {
count.value = 10;
});
</script>
<template>
<button @click="increment">
Count is: {{ count.value }},
Double is: {{ double }}
</button>
</template>
Vue’s Options API
<script>
export default {
data: function () {
return {
count: 0
};
},
computed: {
double: function () {
return this.count * 2;
}
},
methods: {
increment: function () {
this.count++;
}
}
});
</script>
<template>
<button @click="increment">
Count is: {{ count }},
Double is: {{ double }}
</button>
</template>
Vue’s Options API
<script>
export default {
data: function () {
return {
count: 0
};
},
methods: {
increment: function () {
this.count++;
}
},
created: function () {
this.count = 10;
this.increment();
}
});
</script>
<template>
<button @click="increment">
Count is: {{ count }}
</button>
</template>
Common life cycle hooks:
This talk is not about…
Vue’s Options API actually has a place for everything out of the box.
Anyone claiming that the composition API aids in organization has fallen for the hype and doesn't know the hurt they're in for. It deeply, deeply, saddens me that Vue 3's docs will be recommending people use <script setup> + Composition API over the Options API. I get that it's "the one big new feature" for this version, but it's such a back step.
The Options API solves hundreds of problems, most of which are "people problems" (the hardest to solve), and only really creates one new problem (code reuse through mixins is like a 4/10).
Composition API solves the mixin problem (hurray!).... but, only solves a few dozen of the same problems that Options API already solves, and misses most of the rest. This is easier to visualize than to explain, here I just made a quick graphic to illustrate the bigger picture.
Anyone claiming that the Composition API aids in organization has fallen for the hype and doesn't know the hurt they're in for. It deeply, deeply, saddens me that, despite Vue 3's docs not recommending one API over the other, the community is still filled with people thinking “newer = better”. Yes, it's "the one big new feature" for this version, but it's such a back step.
The Options API solves hundreds of problems, most of which are "people problems" (the hardest to solve), and only really creates one new problem (code reuse through mixins is like a 4/10).
Composition API solves the mixin problem (hurray!).... but, only solves a few dozen of the same problems that Options API already solves, and misses most of the rest. This is easier to visualize than to explain.
People Problems
Problems
solved by
Options API
Problems
solved by
Composition
API
The Options API is focused on organization, consistency, and a well documented “Convention over configuration”. From this, it solves so many problems, including some of the hardest problems, particularly “people problems”. Though it has code reuse solutions, they are lacking in polish.
The Composition API is focused on extending reactivity to outside the component. It solves some new problems from this approach, especially improving code reuse, but overall, is far inferior in comparison to the amount of problems it solves and particularly the hardest problems (people problems, and organization). Though often praised for allowing you to “invent your own way of organizing things”, this is more a curse than a gift and should be seen as such.
Code reuse
problems