Since we are a method development group, we need to produce production level code. If you have not had much experience with any of the following, it is worth the time investment to get up to speed - not only so your project will be more stable, usable and maintainable, but to give you skills that future employers want to see, guaranteed.
Object-oriented programming (OOP) powerful and the standard in production development environments. Reminder of the main features and benefits below. Ensure you are integrating the all of the following principles in your code!
- Modularity and encapsulation: OOP allows you to break down complex programs into smaller, more manageable pieces, or modules. Each module can have its own data and functionality, making it easier to work on and test in isolation. Encapsulation ensures that the internal workings of a module are hidden from other parts of the program, reducing the likelihood of bugs and making it easier to modify and update the code.
- Code reuse: OOP encourages the creation of reusable code, which can save time and effort in the long run. Objects can be created once and used multiple times, reducing the amount of code that needs to be written and maintained.
- Inheritance and polymorphism: OOP allows you to create new objects based on existing objects, through inheritance. This can save time and effort in creating new code, and also helps ensure consistency across the program. Polymorphism allows objects to take on multiple forms, depending on the context, which can make code more flexible and extensible. This allows you to easily iterate on your tool development to test different features.
- Abstraction: OOP allows you to create abstract data types that capture the essence of a concept, without getting bogged down in implementation details. This can make code more understandable and easier to reason about.
It is important for your code to be readable and maintainable. Ensure you are integrating all of the following:
- Commenting
- Use comments to explain why code is written in a certain way, not what the code is doing.
- Avoid commenting every line of code, instead focus on complex or non-obvious sections of the code.
- Use descriptive names for variables and functions to reduce the need for comments.
- Use inline comments sparingly and only when necessary.
- Use a consistent commenting style throughout the codebase.
- Typing
- Use type hints for function arguments, return values, and class attributes.
- Use Union types to indicate that a function can accept multiple types of arguments.
- Use Optional types for arguments that are not required.
- Docstrings
- Use docstrings to describe the purpose and behavior of functions and classes.
- Follow the Google style guide for writing docstrings.
- Start the docstring with a one-line summary of the function or class.
- Include information on function arguments, return values, and exceptions that can be raised.
- Include examples of how to use the function or class.
💡
Circular imports can be a problem when typing. Use the following methods to avoid it:
- Using the following type check
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from models import Book- Use
from __future__ import annotationsand put your typing in single quotes
Most tools we develop should have the primary repo be on the algo-cancer account, and then you will fork this repo to your own account. When you want to push releases or changes, you submit a pull request to the algo-cancer repo.
- Use descriptive, hyphen-separated names that clearly indicate the purpose of the branch
- Follow the pattern:
type/description-of-change - Common types include:
feature/- For new featuresbugfix/- For bug fixeshotfix/- For urgent fixes to productiondocs/- For documentation updatesrefactor/- For code restructuringtest/- For adding or updating tests
- Examples:
feature/add-user-authenticationbugfix/fix-memory-leakdocs/update-installation-guide
Git Flow is our primary branching strategy. This creates a clean main that users see when initially visiting the repo, containing only release commits, while the actual development happens on the develop branch.
-
Main Branches
main(ormaster)- Production-ready code only
- All commits tagged with version numbers
- Never commit directly to main
develop- Primary development branch
- Contains latest delivered development changes
- Source branch for feature branches
-
Supporting Branches
-
feature/*- Branch from:
develop - Merge back into:
develop - Naming:
feature/description - Used for new features and non-emergency fixes
# Creating a feature branch git checkout develop git pull origin develop git checkout -b feature/new-feature # Completing a feature branch git checkout develop git merge --no-ff feature/new-feature git push origin develop git branch -d feature/new-feature
- Branch from:
-
release/*- Branch from:
develop - Merge back into:
mainANDdevelop - Naming:
release/version-number - For release preparation and minor bug fixes
# Creating a release branch git checkout develop git checkout -b release/1.2.0 # Completing a release branch git checkout main git merge --no-ff release/1.2.0 git tag -a v1.2.0 git checkout develop git merge --no-ff release/1.2.0 git branch -d release/1.2.0
- Branch from:
-
hotfix/*- Branch from:
main - Merge back into:
mainANDdevelop - Naming:
hotfix/version-number - For urgent fixes to production code
# Creating a hotfix branch git checkout main git checkout -b hotfix/1.2.1 # Completing a hotfix branch git checkout main git merge --no-ff hotfix/1.2.1 git tag -a v1.2.1 git checkout develop git merge --no-ff hotfix/1.2.1 git branch -d hotfix/1.2.1
- Branch from:
-
-
Branch Flow Overview
- Development of new features:
- Features branch off from
develop - When complete, merge back into
develop
- Features branch off from
- Creating a release:
- Branch off from
developtorelease/x.x.x - When ready, merge into both
mainanddevelop - Tag the merge in
mainwith version number
- Branch off from
- Fixing production issues:
- Create
hotfix/x.x.xfrommain - When complete, merge into both
mainanddevelop - Tag the merge in
mainwith version number
- Create
- Development of new features:
-
Key Principles
- No direct commits to
main developbranch always reflects latest delivered development changes- Feature branches should be short-lived
- Release branches lock down versions and allow for last-minute fixes
- Hotfix branches allow for emergency production fixes without disrupting development
- No direct commits to
-
Before Starting Work
git checkout main git pull origin main git checkout -b feature/your-feature-name
-
Regular Commits
- Commit frequently with clear, descriptive messages
- Follow conventional commits format:
type(scope): brief description Longer description if needed - Types: feat, fix, docs, style, refactor, test, chore
-
Pushing Changes
git fetch origin main git rebase origin/main git push origin feature/your-feature-name
-
Semantic Versioning (SemVer)
- Format: MAJOR.MINOR.PATCH (e.g., 2.1.3)
- MAJOR: Breaking changes
- MINOR: New features, backward compatible
- PATCH: Bug fixes, backward compatible
-
Tags and Releases
git tag -a v1.0.0 -m "Version 1.0.0 release" git push origin v1.0.0 -
Changelog Management
- Maintain a CHANGELOG.md file
- Document all notable changes for each version
- Include Added, Changed, Deprecated, Removed, Fixed sections
-
Preventing Conflicts
- Regularly pull changes from main
- Keep branches focused and short-lived
- Communicate with team members about file changes
-
Resolving Conflicts
# Method 1: Rebase git fetch origin main git rebase origin/main # Resolve conflicts in each commit git add . git rebase --continue # Method 2: Merge git fetch origin main git merge main # Resolve conflicts git add . git commit -m "Merge main and resolve conflicts"
-
Best Practices for Conflict Resolution
- Understand both versions of the code before resolving
- Consult with team members when necessary
- Use visual merge tools (e.g., VS Code, GitKraken)
- Test thoroughly after resolving conflicts
- Document complex conflict resolutions in commit messages
WIP
WIP