My Life as a Junior Web Developer: Studying Algorithms Paid Off

I just wanted to give a little encouragement for any new developers out there who, like me, struggled to learn programming algorithms and data structures. I initially had a hard time wrapping my head around them and didn’t appreciate what they were teaching me. On the surface, all I thought I was doing was repeating someone else’s solution for the Fibonacci series or a search method already available in language X. Ok cool, but when am I going to write a function for the Fibonacci series for work, probably never, or so I thought.

I recently was working with an API giving me a nasty set of data, it’s got
nested arrays for days. But for this particular data structure, I was only interested in a two different keys found in the chunker, let’s call them Ramen and Udon. Ramen and Udon pointed strings I needed to translate to spanish. Just glancing at the raw data structure, it looked like I only needed a couple of nested for loops, no big deal. I found Ramen and Udon, translated the strings, spit out the array to the console again…oh wait, there’s a key called Sushi that is pointed to another set of arrays that can have Ramen and Udon. Ok, well let’s add a check for a Sushi key, then loop through those arrays for Ramen and Udon again. Have I confused you yet? At this point I hate my code, here’s an example of it in Ruby.

arraysForDays.each do |key1, val1|
 if key1 == “Ramen” or key1 == “Udon”
 #Do the thing with the value
 elseif key1 == “Sushi”
 val1.each do |key2, val2|
 if key2 == “Ramen” or key2 == “Udon”
 #Do the thing again with the value
 elseif key2 == “Sushi”
 #….loop all the things again??
 # There has got to be a better way

Yeah, super ugly I know, but then I remembered those pesky algorithms I
studied. I have an unknown nesting of arrays, I know what keys I’m interested in, and I have a base case. Using the problem solving skills I learned from studying programming algorithms, I was able to write a recursive algorithm that searched through the array, found all the Ramens and Udons and successfully translated regardless of how many Sushis and levels of nesting there were, yosh (well done)!

So keep studying guys, it will pay off, learning algorithms is not just for 
interviews, tests, or the super elite software engineers. They are for training your brain to break down problems into steps which are much easier to understand and lead to readable and easy to maintain code.