Last updated on
Week 11: Webapp cont.
Congrats on completing week 11 of CS-214. Here is a debrief of the week, with administrative announcements, interesting questions from you and deep dives into course content.
Administrivia
- Unguided lab: remember to sign up for the unguided lab check-offs on Moodle. The check-offs will run from Friday 11 December till Friday 18 December.
The MVP
At this point, you should have a minimum viable product (MVP): a version of your app that does just a fraction of what it needs to do, but which captures the essence of your idea (see last week’s debrief). If you do not have an MVP yet, try building that before moving on to the full-feature app.
For next week, we recommend that you build a second prototype, now with most of the functionality complete:
- Backend: All state transitions and projections;
- Frontend: Complete UI and actions triggering transitions;
- Tests: Complete unit and integration tests.
The idea is to keep a full week for debugging, polishing things up, preparing your demo, etc.
If you think that you won’t be able to reach the goal you originally set out to do, now is a great time to pivot. Decide on a plan that is feasible, and go for that instead – a fully working app with fewer features beats a broken demo of dreams.
A Tale of Two Branches
How effective branching enables collaborative software development
It was the best of times, it was the worst of times.
Working together on a software project can be exhilarating – to design a system, develop its components independently, and then to see it all fit together perfectly at the end. It can also be a nightmare – to design a system, develop its components independently, only to find yourself in Git merge hell at the end. So how should you do this effectively?
There are numerous reasons to introduce a branch in your repository: to develop a new feature, to designate “production-ready” code, to fork the status quo, etc. For the unguided lab, the feature branch is arguably the most relevant, so let’s dive into that.
The purpose of a feature branch is to temporarily diverge from the main code, to develop your feature in isolation. Compared to developing your feature on the main branch, a feature branch has a number of benefits:
- Isolates the work. As you’re developing your new feature on the main branch, the branch might change due to others also developing new features. The good Git committer that you are, you’ve broken up your feature into smaller self-contained commits. However, because of the parallel work by others, the various commits are getting interleaved on the main branch. This clutters the boundaries between your work and the work of others. A feature branch keeps work isolated.
- Eases code review. This same isolation also helps code reviewing. As you stack up the commits for your feature, you would like to get feedback from one of your peers. If they have to sieve through the interleaving of your commits and others’, it clutters the review. A feature branch makes it easier to review as it’s easy to get an overview of its changes.
- Quick to abort. Imagine after developing most of your feature you find out that it doesn’t work as anticipated, or that it is simply not relevant anymore. If you had already pushed your self-contained commits to main, you have to revert those changes to remove the unnecessary or unwanted code. This might be difficult if others already start depending on (some of) your changes, but at the least it will clutter the main branch with irrelevant changes.
- Easier validation. Whether you’re validating your feature through unit tests, integration tests or user tests, it becomes significantly easier to validate your change if you’re indeed only validating your change. An isolated (feature) branch with your changes stacked on top of a working baseline allows you to do this.
- Enables context switching. Even if you’re not working in a group, feature branches can be useful for context switching. If you’re working on two features in parallel, because you’re for example blocked on making progress on one change, separate branches allow you to separate your work clearly. Context switching on a main branch is possible – you could stash your changes and come back to them later – but it’s easier when you have cleanly separated workspaces.
Whilst Git branches offer benefits (the best of times), they can also result in merge conflict hell (the worst of times). A few useful tips to effectively use branches:
- Scope changes. If the feature is too broadly scoped, e.g. “develop the unguided lab”, then there is a high chance that it will conflict logically with other people’s features. As a result, you’re more likely to find yourself sieving through the conflicts that Git so kindly provides you when you want to merge your changes with others’.
- Eventually merge. If a branch is long-lived, the rest of the code base might have moved on by the time it’s ready to be merged. You can of course regularly rebase your branch on top of main to mitigate this, but each rebase potentially takes time as well, if there were significant changes to main. Prefer multiple shorter-lived changes over a single long-lived change.
- Design modular code. Another way to lower the odds of conflicts is to design modular code. You can imagine how a single class that defines your whole app can quickly cause problems when people try to edit the same file. Instead, having single-purpose classes and clean interfaces between them makes for less overlap between various feature branches.
Branches can be your friend, or your enemy, depending on how you use them. If you manage to use them effectively, you’ll find that it enables collabarative software engineering at a much greater scale than fighting over the main branch can.