Maaaaaan, fck algorithms and data structures! Who needs them anyway?!
is something you could hear me say when asked about this topic before so it might come as a surprise that I’ve been heavily investing in learning them in-depth by picking up a number of algo and data structures books and courses, I’m plowing through them like there’s no tomorrow and I’m having the time of my life!
So why the sudden change of heart? What made me go from a proper, full on algo&DS hater to an enthusiastic fanboy?
Well, buckle up buckaroo cause the answers to those questions are a real wild ride!
If you’re an algo&DS hater, like I was, the goal of this article is to introduce you to a viewpoint that might just convince you that algo&DS still have a place in a modern software developers toolbox and if you’re an algo&DS lover that thinks they’re absolutely mandatory for any and all software developers then the goal of this article is to bring you closer to the “other side” and convince you that there are devs out there that are very productive and valuable while at the same time knowing little to nothing about algorithms and data structures ( and how to help them learn )!
The problem(s)
When I was talking smack about algo&DS and why I had no interest in learning them I had my 2 “go-to” complaints - these might sound familiar:
- “I’m an experienced dev! So why didn’t I, in my years of professional work, pick up algorithms and data structures naturally?
It’s obvious that they’re not needed so what’s the point in learning them?” - “The programming language / framework / library takes care of that for me!
Why learn something so low level and ‘primitive’ when the programming language / framework / library itself handles it far better than I can?”
Finances!
I’ll be honest with you, finances are important to me, I want to continuously improve and I want that improvement to be reflected in the amount of $$$ I’m making, I’ve seen firsthand that knowing algorithms = more cold hard cash!
It’s really not that hard of a concept to grasp, the more you know the more valuable you are which you then translate to money and going by that logic I’m not earning nearly enough as much as I could by not knowing algo&DS You can’t implement a solution you don’t know
You can’t implement a solution you don’t know
When you have a hammer everything looks like a nail
A few years ago I really got in to functional programming while I was working on an Angular 2+ web app project which, as you might know,
leans heavily on the OOP side.
All of my teammates came from an OOP background, we had to implement 2 sidebars on certain screens and this was
initially done using a pure imperative approach and everything was fine and well for a while…
All of sudden the client started giving us conditions
when these sidebars should be visible and in some cases the content of the sidebars needed to change based on certain input, because of initial
imperative OOP approach this meant a lot of if ‘s, the complexity of it really wasn’t worth the results! Yikes! 😬
Seeing the frustration this was inducing in the team, not to mention the dread of new conditions from the client I wanted to try out this new thing I was reading about while I was playing around with functional programming called declarative programming as it seemed like the perfect solution for our problems…
It turned out to be exactly what we needed!
All the if
’s were removed and this huge chunk of code was replaced with 2 variables isLeftSidebarVisible
and isRightSidebarVisible
that controlled
( this might come as a big surprise… ) is left sidebar visible and is right sidebar visible ( told you it’s a big surprise! )
It turned out to be so effective that it became the standard how we handled sidebar state throughout the app and a template on how future similar issues were solved.
Is there a point somewhere in this wall of text you call a story” - I hear you say
“There is” - you hear me say ( in your brain 🧠 ) and it’s not that I’m some hero developer that swooped in to save the day but rather that even though I was working with very good devs they couldn’t implement a solution they didn’t know existed!
See where I'm going with this?
Algo&DS are the building blocks of ( all? ) modern software and it’s hard to imagine there’s a modern programming language out there that doesn’t
implement them under the hood and then expose a function for devs to use so while you’re calling Array.sort()
and thinking nothing of it,
in the background some super smart algo&DS stuff is being done to make that function call as speedy and memory efficient as possible. Awesome!
The point I’m trying to make is that you’ve probably been using algo&DS in some shape or form without even realizing it or calling it a different name so that problem point 1 up there isn’t actually true, you HAVE been using algo&DS all this time!
The great thing about it is that you don’t need to know EXACTLY what’s happening under the hood but having an idea how stuff like that is implemented by the programming language will make you more of a “native speaker”, that’ll lead to better decisions when choosing which API to use and that leads to you becoming a better software developer.
On to problem point number 2!
The programming language takes care of it for me!
Not really tho 🤷♂️ see, programming languages are intended for generic and generalized problem-solving since software products can have vastly different requirements and different algo’s and DS are used in different situations there isn’t a silver bullet that’s the perfect solution for every situation so what programming languages do they provide all the necessary API’s to developers to implement the best solution for their use case so it’s up to YOU as the developer to implement the best solution and praying that the programming language / framework / library will save you is just… well… lazy.
It might be hard to image what exactly I’m talking about here so let me give you an
example!
When I started working with JS I fell in love with its Array
and all the functionality that came with it, I’d try to do everything using it.
One particular use case kept popping out very often - the need to store some data associated with some key and I’d solve that by creating an array
and adding items with (usually) an id prop so in JS it would look something like this [{ id: 1, name: 'Bojan' }]
and when I needed to interact with a
particular item inside that array I’d search through the entire array to find it.
If you know basic algo&DS you already know why this is a problem and if you don’t and are wondering what’s the problem this might convince you to take in interest in algo&DS.
The problem is that this is a well known use case in software development that is why there’s a baked in solution for it in every programming language
and it’s called a “hash map” - the difference with my array approach is that accessing data in a hash map is instant vs having to go over every item inside the
array to find the one with the correct id
, hash map is clearly the winner here.
And now we get to the meat of the matter - I thought I was doing everything correct!
I thought my approach was fine but it was not,
it’s terrible compared to the proper way and the only reason it didn’t blow up in my face is because modern hardware and programming languages are
SO good that they compensate for bad developers 😬
The reality of the situation hit me
I was a bad developer thinking I was great!
That really hammered the idea in to my head that I would benefit greatly from learning more about algorithms and data structures and if you don’t know them yet yourself learning them will definitely benefit your software development career! I guarantee it.
The “other” side
I’m not going to spend much time defending devs that don’t know algo&DS mainly because I can’t in my right mind advocate for NOT knowing things but out there exists a cohort of devs ( I know because I was in this group before ) that through trial and error found out what works and what doesn’t and can be trusted to develop features and be productive so if you do know algo&DS and work with someone who doesn’t.
Don’t immediately become na elitist and start shaming - something I see very often online, talk to that dev and introduce concepts piece by piece, don’t just drop every single algorithm and data structure on their head and think your job is done, that topic is HUUUUGE it’s easy to feel overwhelmed.
Your goal should be to gradually improve your coworker until they’re up to speed with all the more popular algorithms and data structures I guarantee you’ll see their confidence sky rocket and be much more enjoyable to work with!
Finally, it’s worth summing up and saying again you can build software and even have it be decent quality without knowing a single algo or DS mainly because the tools that we as devs are using have advanced so incredibly that they can compensate for that fact but you’re aiming to be a professional developer there is no way you won’t benefit from at least having a cursory knowledge of algo&DS and if you take to it and start going in depth I’m sure you’ll see your problem solving skills go through the roof!