It seems that I wind up working a lot with XML data. On a particular project, that data was representative of content to be displayed in a template. The problem was that the content types were not uniform; sometimes it would be all paragraphs, though often a list was needed.
I knew I could technically solve the problem by just including CDATA in the content and manually entering in the HTML. That would be tough to manage, so I wanted a solution that would be able to determine the types/order of content present in the XML and display it accordingly in the template.
I was using AngularJS, so my XML data was being converted to a JSON object. I really struggled with this because as the content was translated into an object, the order of the
<paragraph>s meant something, but not in relation to the
I needed to figure out how to put all the items in a container in the right order to be used in the template. I toyed with the idea of placing an attribute on the
<content> element that would be a 'key' to display the content, and then I thought about having and ID for each element. All of these seemed like they'd be a lot of work and just because I had my ordered container of content still wouldn't mean that I could display it accordingly in the template.
I bounced the idea off of my manager to see if he would have a different approach to the problem. After talking it through a bit on the whiteboard, he introduced me to a few ideas to try and get the data in the right container, one of them being a recursive function/closure (new to me). While we were talking, I had a lightbulb moment of how to handle the repeat in the template (silly me!).
One thing I've learned in programming is to just make the solution work first. I didn't fuss about the beauty of the solution, I just wanted it to be functional. And, what do you know, IT IS! My next steps now are to take the function and clean it up a bit and see if I can use a recursive function somehow to do the work of my dirty nested double for loops.
I've learned that when I'm presented with a technical challenge, after I've exhausted all my ideas, I tend to reach out to my community for a different perspective. In this case it was my manager that was able to help me look at something from 1000 feet, but often it's another coworker or an online community.
I try to never force a solution to come, as that's when frustration occurs. If I'm working on a problem it tends to just linger around in my head and while I'm focusing on something else a solution will present itself.