Forget Bad Code, Focus on the System

Rate this content
Bookmark

Prop drilling is fine. Duplication is great. Long functions are love.

We talk a lot about bad complicated code because it’s easy to see the problem. But research shows engineers can work around self-contained bad code just fine. What really trips them up is something else entirely – architectural complexity.

Architectural complexity makes your code hard to work with, causes 3x more bugs, halves productivity, and may even cause devs to ragequit. In this talk we explore what you can do.

FAQ

The main focus of the talk is to emphasize that instead of obsessing over 'good' or 'bad' code, what's more critical is how you set up your entire system or architecture, particularly separating concerns by business domain rather than by technology.

The speaker suggests rethinking separation of concerns by organizing them according to business domains rather than technological layers, implying a strategic modular setup that aligns more closely with business functionality.

The speaker uses the analogy of building LEGO sets, comparing older sets where pieces are sorted into different boxes, to newer sets like the Saturn V rocket, which are organized stage-by-stage, each bag containing exactly the pieces needed for that phase.

High architectural complexity can lead to a 50% drop in productivity, a three-time increase in defect density, and potentially higher staff turnover, as complex systems are harder to manage and maintain.

The speaker describes using a dependency graph to visualize how elements of the code interact and then identifying natural modules based on tight internal connections and loose external connections.

The speaker relates coding modularity to physical objects through the examples of modular construction in buildings and the assembly of a car engine, emphasizing the benefits of pre-defined, self-contained units that simplify overall assembly and maintenance.

The speaker appreciates the direction of server components and server actions in React, noting that while the current implementations might be 'leaky', they represent a move towards self-contained components that handle everything in one file.

Swizec Teller
Swizec Teller
27 min
13 Nov, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Setting up the system and separating concerns are important in software development. Modular construction and prefab units are a new trend that makes construction quicker and easier. Architectural complexity can lead to a drop in productivity and an increase in defects. Measuring architectural complexity can help identify natural modules in the code. Best practices for avoiding architectural complexity include organizing code by business domain and using prop drilling. Atomic design and organizing a monorepo are recommended approaches for managing architectural complexity.

1. Setting Up System and Separating Concerns

Short description:

You should focus on how you set up your entire system, your architecture. React's JSX and CSS in JS caused similar concerns in the past. Separating concerns by business domain is a different approach.

We hope you enjoy the rest of the talk. Thank you, and I'll see you next time. Bye-bye.

So I'm going to try to convince you today that you're focusing on the wrong thing. You're talking too much about good or bad code, and what you should actually be focused on is how you set up your entire system, your architecture.

Now, has anyone seen this slide from NextJS Conf that kind of made the rounds on Twitter? This is a server action, and what's going on is that you have a React component with SQL right there in the React component, which is a bit weird. And earlier today, David from Redwood also announced that they can now do the same thing, where you have SQL stuff mixed together with JSX stuff. Now how does this make you feel when you see this? How does it feel? Does anyone feel angry? Yes, all right. Does anyone feel upset, like kind of weird, like this is a weird, bad thing to do? All right. Now, what if I told you that's exactly how we felt about JSX 10 years ago. React launched, they came up with JSX, and all of the greybeards on the internet were like, oh my God, you're mixing HTML and JavaScript? What the hell is wrong with you? Why would you ever do that? It's separation of concerns, all of that. And then CSS, CSS in JS came along and the internet went wild again. Why are you mixing all of this together? And what if I told you that the whole point of all of this is, in fact, separation of concerns.

Now, it feels, you know, I say separation of concerns, and you might be thinking, wait, but you're mixing all of the concerns together. You have styling mixed in with database logic, you have fetching mixed in with all of the ‑‑ can I actually see my notes? All right. So you're mixing everything together. That doesn't feel like separation of concerns. But there's a different ‑‑ there's another way of thinking about the separation of concerns. What if you separated your concerns by business domain, not by the technology that you're using? The word business is doing a lot of work here. We like to ‑‑ I don't know, who here has worked with like fancy pants architects and people who have like really high sounding titles like principal engineer and stuff like that? Just give a scream. Okay. A few of you. Okay. Who here has heard them talk about domain modeling or business this, business that, that sort of thing? All right. Perfect. So this is a lot of work and ‑‑ oh, damn, I'm missing ‑‑ there was supposed to be another slide there. Okay. So the word business domain is doing a lot of work there. What the business ‑‑ what I mean by that is a good example of that is Lego. So these are two Lego sets.

2. Lego Sets and Building Process

Short description:

The Lego super car from the 90s came in a big box with 1,300 pieces. You would sort the pieces into different boxes. The Saturn 5, my second Lego set, had 1,969 pieces and came in baggies. Building the Saturn 5 rocket was easier and more fun because the pieces were separated by stage, making it easier to find and build.

They both happen to be my first big Lego sets. So on the right you have what large Lego sets used to look like in the 90s. Here's the Lego super car. It comes in a really big box. I loved it. As a kid this was like oh, my God, you get 1,300 pieces and the first thing you do, you open it up and you sort every little piece into its own little box. It takes a while. And then eventually you can start building your Lego and you have ‑‑ you can find all the pieces. If you need a gear, it's in the gear box. If you need a wheel, it's in the wheel box.

Now, later, when I realized that, hey, I'm now an adult, I can just buy Lego whenever I want. I know, like crazy idea. I bought the Saturn 5, which was my second Lego set. That one has 1,969 pieces, which I think is carefully calibrated to coincide with when Apollo 1 landed on the moon and all of that, because it went up in the Saturn 5. That one didn't come with a box that you sort Legos in. It came in a bunch of baggies. You build the Saturn 5 rocket by going stage by stage. For those of you who don't know, rockets are multi-stage. It launches. The first stage burns up its fuel. It drops the first stage, and the rest of the rocket keeps going. That's how you build the Saturn 5. In each baggie, you get exactly the pieces for one stage of the rocket. You build it up from the ground, and all the pieces are mixed in. You have pieces that are from the outside panelling. You have pieces that go for the inside structure and all of that. It's all jumbled together. What's really cool is that it's much easier and much more fun to build than the supercar was because you never have to search through more than like 200 or 300 pieces, which is much easier to do. You can spread them out on a table and you're like, oh yeah, that one, that one, that one, and you just build it and you're enjoying the building process rather than spending a lot of time searching for the right LEGO. Now I know some people say that's the fun part.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

AI and Web Development: Hype or Reality
JSNation 2023JSNation 2023
24 min
AI and Web Development: Hype or Reality
In this talk, we'll take a look at the growing intersection of AI and web development. There's a lot of buzz around the potential uses of AI in writing, understanding, and debugging code, and integrating it into our applications is becoming easier and more affordable. But there are also questions about the future of AI in app development, and whether it will make us more productive or take our jobs.
There's a lot of excitement, skepticism, and concern about the rise of AI in web development. We'll explore the real potential for AI in creating new web development frameworks, and separate fact from fiction.
So if you're interested in the future of web development and the role of AI in it, this talk is for you. Oh, and this talk abstract was written by AI after I gave it several of my unstructured thoughts.
Confessions from an Impostor
JSNation 2022JSNation 2022
46 min
Confessions from an Impostor
Top Content
You know what impostor syndrome is, right!? Most all of us have felt that nagging feeling that we're faking it and that we're sure to be found out by all the experts around us at any moment.But before you go assuming this talk is the same ol' song and dance full of platitudes that encourage you to ignore that syndrome, let me clue you in on a little secret: there's no experts around you. Impostorism is not a syndrome at all, it's a pragmatic mindset and perspective, one we should all embrace and be proud of. In fact, it's vital to us getting our jobs done.
Improving Developer Happiness with AI
React Summit 2023React Summit 2023
29 min
Improving Developer Happiness with AI
GitHub Copilot is an AI pair programmer that can help you write code faster and spend less time writing repetitive code.This session will cover some interesting use cases for Copilot that could shine a light on its possibilities. This ranges from prompting Copilot to suggest a function based on a comment, learning how to use a new framework, tackling a security or accessibility bug, better documenting your code, translating  code from one language to another, etc.Agenda:
Introduction to CoPilot
- What is Copilot
- How can you use it
- How it can help you write code faster
- Copilot Labs experimental features I will pick examples from the React ecosystem and show how we can fix Security Vulnerabilities and Accessibility issues in some components.
VS Code Can Do That!
JSNation Live 2021JSNation Live 2021
28 min
VS Code Can Do That!
How do you debug so easily in VS Code? How do codespaces work? What are those key combinations to edit code so quickly? What extensions are the ones I shouldn't code without? Get ready to hit the ground running in this fast-paced, demo-heavy talk that takes you through some of the best and most effective tips and tricks in VS Code. Learn how to setup your environment and customize it the way you like it. You'll walk out with several tips on how to be more efficient with one of the hottest tools on the Web today!
A Quick and Complete Guide to Measuring Your Tech Debt and Using the Results
TechLead Conference 2023TechLead Conference 2023
27 min
A Quick and Complete Guide to Measuring Your Tech Debt and Using the Results
Hardly any people in Tech like when there's a lot of tech debt. And most of us would like when there's not too much of it. But how do we understand how much exactly we have of it? Where exactly does it sit? Which part of it is actually the most annoying? What would be the benefit for us if we spend time getting rid of it? When it comes to planning how you tackle your tech debt, all these questions deserve answers. Especially when we're asked about the ROI on our efforts to eliminate some annoying legacy stuff and build a new shiny module or service. Also, when we work on tech debt, we do want to tackle the most impactful parts of it first, don't we? This talk is about all of that: how we measure our tech debt, how we interpret the results of these measurements so that they give us the answers to the right questions, and how we guide our decision making with those answers.
Webdevelopment Tailored for 2024
React Summit 2024React Summit 2024
7 min
Webdevelopment Tailored for 2024
Most developers closely follow the framework wars. So busy with these games, that we forget to check what new features HTML, CSS, and JavaScript offer us. Native modals, dynamic viewport units, and optional chaining are just some of the features you should use already! If you stopped following Web Platform development in 2015, it's time to refresh your knowledge. I will teach you to build applications tailored to 2024 and prepare you for the new Web Platform features that will appear in the coming years.