3 mistakes I made today

2 minute read

Today I want to share with you three mistakes that I made.

I’m sharing these mistakes to learn from them and to give you a bit a glimpse of what my day-to-day looks like as a software engineer.

🤓 What’s the context?

I am currently part of a team that is building a facebook chatbot using Node.js and Google Dialogflow. We use Chatbase for analytics and I’m in charge of building the integration of Chatbase with our Node backend.

⛔️ Mistake 1: Returning something else than I thought

The first mistake that I made: I returned something else than I thought.

This is wrong.

const addUserMessage = (userMessage) => {
    const set = chatbase.newMessageSet();

    // Add user message to set 
    return set.newMessage()
              .setMessage(userMessage);
}

This is right.

const addUserMessage = (userMessage) => {
    const set = chatbase.newMessageSet();

    // Add user message to set 
    set.newMessage()
       .setMessage(userMessage);

    return set
}

The function addUserMessage is supposed to return the newMessageSet from the variable set. However, the method set.newMessage() doesn’t return the set(), but the actual message that was being set!

✅ Know what you’re returning!

⛔️ Mistake 2: A subtle typo

The second mistake was stupid typo which took me way too long to find.

const receivedMessage = async event => {
    const senderID = event.sender.id;
    const message = event.message;
    const messageId = message.mid;

    const chatbaseMessageSet = chatbaseConnector.createMessageSet(senderID, senderId, messageId, message);

    ...
}

Can you spot the mistake?

I just realized that we are very inconsistent with our spelling, using both ID and Id. Very confusing.

✅ Be consistent with your grammar!

⛔️ Mistake 3: My object turned into a int?

The third and final mistake was that I didn’t realise the function I was working on was being called somewhere incorrectly.

the function was being called incorrect of the day was that I didn’t realise the function was being called with too much (wrong) arguments somewhere.

This is what I thought the function looked like when I started working on it.

const dialogFlowResponseHandler = async (sender, response) => {
  ...
};

So I added another parameter to the function like so.

const dialogFlowResponseHandler = async (sender, response, chatbaseMessageSet) => {
  ...
};

Little did I know that somewhere else in the code this function was being called

const dialogFlowResponseHandler = async (sender, response, userId) => {
  ...
};

Which had the nice benefit of turning the intended chatbaseMessageSet into a nice integer every time that function was called, crashing the app!

✅ Double check where the functions are being called that you are working on!

🔮 Recap

Today I made some silly mistakes. The good thing is that we can learn from these.

👇 Three lessons

  • Know what you’re returning.
  • Be on the lookout for silly typos.
  • Double check the code that you’re working on.

Subscribe

Comments