learning-it by example

#324 Forward deployed engineer interviews 6 min

Customer Hack to Reusable Connector: Refactor and Measure

Three copied scripts, 33 repeated lines. One 16-line connector gave the same orders.

1. According to the video, when is it time to pull copied code together into one piece?
2. In the made-up customer connector example, how many lines of code did the three copied scripts and the single connector have?
3. When three copied customer scripts are refactored into one connector, why compare the connector's orders with the old scripts' orders for each customer?
4. What kind of customer needs code or a bigger config, because a data-only connector entry cannot describe it?
5. In the made-up customer connector (connector.py), how is a new customer added?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. Change the page size

    Copy the code folder first. In fakeapi.py change size=3 to size=2 in the get_page function. Predict whether the number of orders found for each customer will change. Run python run.py and look at the three lines that end with 'orders as the old script'.

    A hint

    The scripts and the connector both read pages until one is empty. I saw the same 5, 4 and 6 orders.

  2. Break the paid test for one customer

    Put the page size back. In connector.py change "PAID" to "OPEN" in the entry for acme. Predict what run.py will print and whether it will check the other two customers. Run python run.py.

    A hint

    The run compares the connector with the old script and stops at the first difference. The old script still keeps the PAID orders.

  3. Add a fourth customer as data only

    Put "PAID" back. In fakeapi.py add this entry to DATA: "dave": [{"num": n, "cost": n * 5, "open": n % 2 == 0} for n in range(1, 8)]. In connector.py add this entry to CUSTOMERS: "dave": {"id": "num", "total": "cost", "scale": 1, "paid": ("open", False)}. Predict which orders count as paid. Then run python -c "import connector; print(connector.run('dave'))".

    A hint

    Paid means the open flag is False. I saw 4 orders with ids 1, 3, 5 and 7 and pounds of 5.0, 15.0, 25.0 and 35.0. run.py now counts 17 connector lines.

These tasks are for you to try on your own machine. Nothing is checked or saved.

What this does not show

Made-up customers and API; 'repeated' means identical lines of text; the connector holds only differences that fit in data, and some customers would need code.

Up next in Forward deployed engineer interviews

More in Forward deployed engineer interviews

All Forward deployed engineer interviews videos

Related videos