software-engineering 5 min read

Navigating the Coding Odyssey

Why you should code the shortest path from point A to point B first, before abstractions, tooling or splitting up the work, told through a sailing analogy.

p.s: Lookout for XKCD-gallore in links below.


TL;DR: The key takeaway is to prioritize coding the shortest path first, especially when dealing with new and uncertain problems!

// the_early_days

In my journey from being a rookie engineer to being a seasoned engineer, I have observed an intriguing phenomenon: As a novice engineer, you’re typically handed a task or come up with an idea, and then you go ahead and execute it in the most straightforward way.

Essentially, it’s like travelling from point A to B through the simplest route.

Two hand-drawn sea charts. On the first, labelled "year 1", a small sailboat goes in a straight line from point A to point B with a tick: it works. On the second, labelled "year 5", the route from A loops past islands named OOP, design patterns, frameworks and monads and ends in a question mark short of B.
⛵ setting_sail ⛵

Your code might not be a masterpiece, but it works. As you grow, you accumulate knowledge – you get acquainted with object-oriented programming, algorithms, design patterns, frameworks, abstractions, higher-order functions, monads, and [everything] [in] [between] that you stumble upon. You begin new projects, convinced that you must employ these newfound skills, but somehow, things don’t always go as planned…

// keeping_it_simple

Suddenly, you find yourself amongst a group of engineers where it feels like the team is accomplishing less compared to when you were a [lone newbie].

What often slips through the cracks here is the realization that for any new task, no matter how intricate, the core idea remains the same - code the most direct route from point A to B. Here, it’s beneficial to deliberately avoid getting entangled in thoughts about the perfect abstraction or the golden standard of execution. That’s for later!

A hand-drawn maze. A red thread runs from the entrance, point A, labelled "code today", through the corridors to the exit, point B, labelled "code that does the job".
🧭 staying_the_course 🧭

If you’re working on a completely new project, consider it “prototyping”, and if it’s part of an ongoing project, think of it as laying down a “guideline thread”. Imagine you’re navigating a maze, and you’re using a thread to mark your path from the entrance to the exit. The essence remains – focus on the fundamental work needed to connect points A and B.

where:

  • POINT A signifies the existing condition of the code
  • POINT B marks the code fulfilling the intended functionalities

The code might lack elegance, but as long as it meets the objectives, you’ve effectively navigated the maze.

Do not obsess over optimizing your code prematurely!

// dealing_with_distractions

👉 This principle in the last point may sound like something simple that everyone should know, but when you’re in a busy team, it’s easy to forget. Often, team members will suggest pausing the project to spend time on things like setting up tools, trying out fancy new libraries, or cleaning up the code to make it [better].

A hand-drawn sea chart. A sailboat holds a straight course from A to B while three islands on either side wave signs at it: "set up tooling first", "try this shiny new library" and "clean it all up first".
⛈️ navigating_the_storm ⛈️

While these suggestions aren’t inherently bad, they aren’t always the priority.

What’s crucial is to question whether the requirements call for these steps and if the central challenge has been addressed. If not, steer clear of distractions!

// adapting_and_refining

The rationale behind this approach is that you may end up investing time in refactoring or setting up environments only to realize that your entire strategy was flawed. This means starting afresh, rendering the initial efforts [futile].

It’s pivotal to initially approach the task as a whole – resisting the urge to segregate the workload prematurely, which may lead to arbitrary divisions.

The best ways to split up the work so that everyone knows what they should do might not be clear at first. It’s smarter to figure them out by working on the problem several times. So, it helps to be in a small team initially that really focuses on what it’s doing, because working on the issue over and over helps find the best ways to handle it.

// refining_for_deployment

However, this approach may have some pitfalls. 👉

You might end up with a rudimentary piece of code that meets the bare minimum requirements. You might even demonstrate it to the product team. But is it ready to be deployed? Not quite. Now, it’s time to allocate resources to refine the coarse aspects, security tests, and more.

This transformation phase morphs your initial prototype ---> deployable product.

A hand-drawn before and after. On the left, a small raft labelled "prototype". An arrow passes a checklist of tests, security, CI/CD and refactoring, all ticked, and leads to a proper sailing ship labelled "deployable product" moored at a dock.
⚓ docking_at_port ⚓

Handling this stage effectively, particularly when liaising with Product teams, varies depending on the dynamics. It’s important to keep the Product in the loop regarding the uncharted territories of the problem, elucidate what you aim to discern, or categorize the task as a “prototype” without much elaboration.

One must not let the pressure from product teams with stringent timelines undermine or neglect the crucial facets of the SDLC.

After all, if it’s a software product meant for [deployment], it warrants prod-readiness, tests, CI/CD, and possible refactoring for clarity and maintainability!

// a_matter_of_judgement

A hand-drawn decision chart. A new task arrives and the diamond asks "do you know the waters?". If yes, well charted, the arrow leads to "split the work, follow the plan" with three boats sailing in parallel lanes. If it's new and uncharted, the arrow leads to "code the shortest path first!" with a single boat going straight from A to B.
🏴‍☠️ concluding_the_voyage 🏴‍☠️

As with most things, this comes down to making a [wise decision]!

There might be instances where the problem you’re dealing with is not all that complex, and you have a clear understanding of the best way to divide the work, meaning the decisions you make are well-thought-out. In such scenarios, you can work simultaneously on different parts and follow a set plan.

However, when you’re tackling a fresh, uncharted problem where there’s a significant chance of things not going as planned,


Always opt for coding the shortest path first!


Comments

    Supports `code`, ```blocks```, **bold**, *italics* and links.

    Keep reading