I just join the group to fully embrace haskell. I come from a recent interview dissapoinment So the story is like this. I have some experience programming. Sadly I have more experience on languages like java. In my heart I love functional programming though, its only that it is really hard to get a functional programming job in my country. So I am reading about haskell, just read Graham Hurton’s book. I find it exciting. I just recently found out about optics! too which just makes me eager to learn more. I am not just an improvised programmer. I have an Msc, I have been programming for some years now. I even took a class from Philip Wadler himself. So this gets me really excited.
The thing is that now I am looking for a job. So I had this interview from a small company and they ask me to implement a program which basically grabbed an xml and then parsed it and stored it to the database with some rules related to the particular data. The problem in question was in ruby. I didn’t know the language so I learned it just for this interview. So here is the thing, as I told you I am reading Hurton’s book and I find the part where He talks about parsing I find it natural and elegant. So I decided to just mimic it since the problem in question to put it in practice. I am not saying it went well. So I wrote my code. It worked, it was fast. But I got terrible feedback. This is why I come to you. I got told it was confusing! I know this code is in ruby but bear with me. I want feedback from real pros, or a least people with certain mindset and I just think I will not get it from ruby programmers. So I share my code with you.
My idea was to implement a simple working version of composable functions that served my specific purpose. It is not really great code but I thought it would do. The goal was to have a declarative specification of the requirements. I know this is not the best but I really expected other kind of response. So here is the code. thanks in advance.
I will state the problem clearly. My intention here is a general comment on the ideas rather than particulars on the language. The problem basically requires the following. You are provided with an XML schema. This schema provides a list of items, let’s say meals for sale. This lists are segmented by business. So you will actually have a list of businesses with their corresponding menu. Now, you have to sync your local database with your corresponding rules.
1.- If the menu has no calories data discard the particular meal.
2.- If a meal in the database is not in the feed mark it as unpublished in db.
3.- if the restaurant is not already in db mark it.
4.- Meals have associated list of urls. Preserve the order in the feed in the database.
5.- XML tags don’t correspond to the database name columns.
6.- There is a bunch of other fields required nested through. Example. Each meal has a list of ingredients. Add those to the database.
This is not the actual problem. But the basic idea is that a feed of data is sent and it has to be transformed and updated in the database according to a set of rules for mapping the data.
The approach I used was defining a base for composing all this transformations required through a streamed parsers. This parser works by notifying each at each level the staring and ending tags, data, cdata, etc… What I wanted is to specify in a declarative way this transformations for each field and to be able to stop any further computation if at some point data was declared to be invalid or not relevant. For example for calories tag.
CALORIES_TAG = DataField(“calories”)