Feedback about functional programming in Ruby

Hello guys,

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.

https://drive.google.com/drive/folders/18OoqjoKb7eZSNUThYYF5PUpaYOfy9sXh

Edit:

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”)

Hi @glserran! I amended the title slightly so it’s easier to see what this is about.

I don’t know Ruby that well but it’s clear that the code you wrote is far from idiomatic (for Ruby). There’s a time and place to introduce functional programming concepts in other languages, but job interviews are usually not that place.

I wish I had some feedback for you, but it’s hard for me to understand what is going on in the Ruby code – and we also don’t have the problem description. Maybe if you elaborated on that someone can help out?

1 Like

You know I realized you are right. Maybe I was so enchanted with what I consider elegant I never stopped to think that it might be confusing for someone that is so used to OO programming. Considering what I spoke with this people they actually told me that no one wanted to program in Haskell when I talked about my passion for the language. I should have gotten the clue.

You could try to look at this experience from another angle: maybe it saved you from a job you didn’t want in the first place? What’s the point spending all day at a job where your ideas are not understood, let alone valued? Once you get to meet people who share your enthusiasm about functional programming, I’m sure your approach will get you the job.

2 Likes

I will add to the very reasonable message by @mduerig that an tool-focused employee will seldom be a good fit for a company.

What if the stack changes in a few years? What if I need them to help in a different setting (management? hiring? integration with a team which is related but distinct to what you do now?).

A product/sector-focused prospect is generally considered a more viable choice. This of course has exceptions (that one firm that provides legacy COBOL support, etc.); a bit of research goes a long way in job interviews.