Skip to content
PodSubs
ShowsPeopleGuestsJobsNewsEvents
More
BlogPodCred
Menu
ShowsPeopleGuestsJobsNewsEventsBlogPodCredNetworksSign in
Join nowSign in
  • Shows
  • People
  • Jobs
  • News
  • More
    • Guests
    • Events
    • Blog
    • PodCred
    • Networks
    Join nowSign in

Code & Curiosity by Maximilian Schwarzmüller

Code & Curiosity by Maximilian Schwarzmüller artwork

Smart Developers Write Simple Code

Apr 7, 202413 minAudio

As you're growing as a developer, it's easy to introduce unnecessary complexities and abstractions into your code. But you might not always need the most modular and flexible code. Most of the time, simpler is better.

Audio and video play straight from the show's own hosting. PodSubs stores and serves no media.

Transcript

From the show. Tap a time to play from there.

When working as a developer, when writing code, there are certain principles you might want to keep in mind and follow. Something like the DRY principle, the don't repeat yourself principle, but also, for example, the KISS principle, the "Keep it simple, stupid!" principle. That's a principle I want to take a closer look at today, because it's fairly easy,

especially if you're maybe a less experienced developer, to write unnecessarily complex code. And it's not just the code complexity, but I'll get back to other forms of unnecessary complexity later. Let's start with the code complexity. Especially if you're not that experienced, maybe, it can be quite tempting to introduce a lot of unnecessary abstractions in your code.

It can be quite tempting to think, well, what if I also maybe need to use a certain function or a certain piece of the code base in a slightly different way in the future? And all of a sudden, you start making a function that did one specific thing in the past more generic so that it can do more things or accept more types of input and so on. So it can be quite tempting to make

your code more flexible so that it can handle more use cases and your code base gets more modular and more generic. And that's a good thing, right? We want a modular and generic code base. Well, not necessarily. If you're writing some code for a package that you plan to distribute as a third party package to developers all over the world, then you might need some generic code or modular code.

You might need to support a lot of different use cases. But even then, you might not need to support all the use cases you think you need to support. And especially if you're working on your own application. So if you're writing code for an app you built where you know what it should do, it really doesn't make a lot of sense to already think of all kinds of possible variations at the point of time where

you're getting started. Sure, there always is a trade-off and if your code is too specific, you might spend a lot of time refactoring that code if you eventually need to support different use cases or if parts of that code need to get more flexible in the future. But on the other hand, if you write everything as generic and flexible and modular as possible right from the start, you spend a lot of time making your

code base quite complex and that then can actually also lead to problems in the future because it's now maybe not so easy to use it in the way you want to use it because you made it very flexible and modular so you need to pass a lot of configuration parameters or stuff like that. So there actually is a trade-off here. Modularity and flexibility can make sense but it's not always what you should go for.

And I guess you can kind of like draw a bell-shaped curve where on the left side of the bell where the curve is very flat, we have beginners who write very simple code that's not very flexible and modular because they don't know that they might need more modular code or they're not able to write more generic and flexible code. But then we go on top of that bell so we go up that curve if that curve depicts the

complexity of the code base and we suddenly start writing pretty complex code because we feel smart about it because we write code that supports a lot of different use cases and input parameters and we suddenly end up with that very complex code base which we don't need for the project or which we might not need for the project we're working on and we introduce new problems along the way and of course if we write very complex code we also

spend more time solving a specific problem because we don't just solve the problem but we also think of future problems which we also try to solve already. So it takes us more time to write the code to get a certain job done because we try to make that code as flexible and modular as possible. Well and then we go down that curve again as we get more experienced because as you get more experienced as a developer you learn that you might not

need the most generic and flexible code base in all situations. That in a lot of situations and scenarios it's fine if you just write good code that solves a specific problem and doesn't try to solve all kinds of problems you might be facing in the future. If you then evolve your code base so that you need to solve another problem you can still make parts of your code more flexible and modular but even then you

might just make it as modular and flexible as needed to solve the original problem and maybe now another new problem you need to solve. So even then you might not go down that route to make it as modular and as flexible as possible and that is a really important lesson to learn that you don't need to look smart when writing your code that you don't need to try to solve all possible kinds of problems with your

code base and that instead it's often better to keep the code simple to keep the code base simple and by the way simple code does not mean bad code not in any way instead simple code means that your code solves a certain problem and it does that well and of course it also does that in a way that handles potential errors that might arise and so on but it's not getting unnecessarily complex and that is a skill

that simply comes with experience. It is something you can learn by always questioning your code by always being critical and asking yourself do I need to make this code more generic more flexible or should I keep it simple is it simple enough does it do what it should do and does it do that well or am I trying to do more than I originally planned or is the code maybe not doing enough are

there potential errors that might occur that I'm not handling you always have to question your code and of course it also helps if you're not working alone but in a team if you got a colleague or a friend who reviews your code and who gives you input on your code because there is the danger of writing bad code because it's too simple too focused on one specific problem maybe but in my opinion there is an even bigger danger

of writing bad code because it becomes too complex because it tries to do too much now as I mentioned originally at the beginning here it's not just the complexity of the code base that matters and that you should keep an eye on it's also a complexity regarding the technologies you might use because for example if you're building a blog website your own personal website which should

contain a blog where you plan on sharing some posts about your life or some tutorial posts whatever you could just create that blog with a content management system like wordpress you could also build it on your own of course with some static site generator with something like astro.js for example but you could also just build it as a node.js or php based website where you store your

blog post data in a database and you render that as html documents then you could do all that and that would all be fine but you could also start building a complex application where you have a standalone react or angular or whatever single page application front end and then a rest api backend or a graph ql api doesn't matter you have some caching in between a caching layer you set up an extra database to which the backend

communicates you start bringing in a ton of extra third-party libraries into both ends also in the front end to add lots of extra features that might not be too important for a blog but that you feel like you need to have then you start hosting that blog on aws and you want to do it with docker and containers and also in some kind of serverless way so you look into all the services you need to

do to do that and so on you see what i mean you can build a simple blog in a pretty complex way and don't get me wrong you can do that it can be a great exercise if you want to get better at working with docker or with aws or react or whatever definitely start building demo projects build your blog that way but only do it if you do want to practice certain technologies or services don't

start building your blog like this if you just want a blog if that's the main thing you want if you don't care about the exercise because you don't need that super complex text deck you don't need a super complex web application that consists of dozens of technologies and libraries and frameworks and so on just to render some blog posts onto the screen of your website visitors you don't need that so here again keep it simple

don't introduce all those libraries and packages because you read somewhere that you need to use them instead keep it simple use the simplest possible solution for achieving the goal you want to achieve unless as mentioned you want to practice working with those technologies because then of course your goal also isn't to render blog posts onto the screens of your visitors or at least that's not the primary goal then

but the goal then is to learn and grow and then it's of course absolutely fine and the right thing to do to work with all those packages and services and technologies and so on so then definitely do it but if your goal is something else if your goal is the end product the blog or whatever it is then you should keep your tech stack simple because in that case if you would make it unnecessarily complex you would just spend more time unnecessarily on

working on that project and you would also make it harder to maintain because if you come back to a super complex project in the future it simply takes you longer to get back into it and that's the case no matter if we are talking about a complex tech stack or if we're talking about a complex code base so therefore in a nutshell keep it simple and don't think that it's smart or a sign of intelligence to use complex technologies

or to write complex code it's actually the opposite a good developer uses the best and simplest code or tool to get a job done without doing that job in a bad way so without ignoring important features the code should have or something like that but adding unnecessary complexity it's not something you want to do

Open the transcript file

Hosts and Guests

Nobody is credited on this episode yet.

Credit the people on this episode

Be the first to rate this episode

More episodes

All episodes
  1. We will have to accept AI-generated content

    Oct 15, 202612 minAudio

    I think we'll have to get used to (and accept) AI generated content. Not to slop though.

    • Apple Podcasts

    Credit the people on this episode

  2. Is software dead?

    Oct 13, 202612 minAudio

    There's a lot of talk about software being dead. Unsurprisingly, it's complicated.

    • Apple Podcasts

    Credit the people on this episode

  3. GPT 6 Astra - Good Beyond 3D?

    Sep 9, 20268 minAudio

    GPT 6 Astra was released. It's a good model, I have to say. Especially for 3D work it seems to be a real game changer. But due to all the hype, you may be disappointed...

    • Apple Podcasts

    Credit the people on this episode

  4. You may ignore Omarchy but not its impact

    Aug 26, 20268 minAudio

    Omarchy got a lot of hype and visibility recently. But even if you don't care or don't use it, you shouldn't ignore it.

    • Apple Podcasts

    Credit the people on this episode

  5. SvelteKit 3, Solid 2 - Do they matter anymore?

    Aug 18, 202614 minAudio

    We're not going back to the JS framework wars. BUT new frameworks and framework versions are important. For a different reason now!

    • Apple Podcasts

    Credit the people on this episode