CSCI 494-802: Industry Methods
2/25/2025
Clean Code, Code Review
Agenda
Attendance
Questions?
Any questions about Assignment 3?
Please do not merge the branch yet
Feedback
Push yourself out of your comfort zone
If python is your strongest language, try a different one for these easy problems.
As inspiration this individual solved the first 100 project euler problems with 100 different languages
https://github.com/jaredkrinke/100-languages
READ 10x more code than you write...
Clean Code
Clean Code
Take pride in your work
“Leave the campground cleaner than you found it”
“Presentation is as important as the quality of the content that you are presenting”
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
Functions rules
More Book Recommendations
Naming Variables
"A name should tell you why it exists, what it does, and how it is used. If a name requires a comment, then the name does not reveal its intent."
– Clean Code
“Take as much time as you would naming your first born child” - unknown internet
Clean Code Explained - Name Variables
Clean Code Explained - Write Functions
The benefits of writing clean code
1. Easier to start, or continue
2. Better for team onboarding
3. Easier to follow
Tips on writing clean code
1. Make code readable for people
2. Use meaningful names for variables, functions and methods
3. Let one function or method perform only one task
4. Use comments for clarification
5. Be consistent
6. Review your code regularly
Other Views
There’s No Such Thing as Clean Code
“Coding is generally a team sport”
Forget about Clean Code, let's embrace Compassionate Code
More Tips
Line of sight in code: Left edge is happy path, indented is error handling and edge cases
Code: Align the happy path to the left edge | by Mat Ryer | Medium
example: polymorphism over an if/else statement
Clean code summarized
Write small blocks of code
Small functions, small classes, small modules.
It will result in:
- higher cohesion
- better maintainability
- modular code structure
- ability to capture domain knowledge
- compliance with Single Responsibility Principle
And the improved readability will make your future self and your colleagues happier.
Clean Code Funny
Code Review (+1, +10)
Much of your day as a programmer will involve reviewing other pull requests and providing valuable feedback
Auditable
SOC1, SOC2, ...
+1
+1 is an acknowledgement of a code review
Github has a nice Code Review feature directly - DEMO
What do you look for during a +1?
Tact
Always remember:
10 Commandments of Egoless
Code Review tips
More code review tips
More Guidelines
Style Guides
a set of conventions (sometimes arbitrary) about how to write code for that project. It is much easier to understand a large codebase when all the code in it is in a consistent style.
http://google.github.io/styleguide/
https://javascript.info/coding-style
Google Engineering Tips
Conventional Commits / Comments
Automate Style Rules
Lint - https://en.wikipedia.org/wiki/Lint_(software)
Static Code Analysis -
https://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis
Cyclomatic complexity is a software metric used to indicate the complexity of a program. It is a quantitative measure of the number of linearly independent paths through a program's source code. It was developed by Thomas J. McCabe, Sr. in 1976.
Cyclomatic Complexity
Why is it important?
Cyclomatic Complexity
Use the following formula to calculate cyclomatic complexity (CYC):
CYC = E – N + 2P
P = number of disconnected parts of the flow graph (e.g. a calling program and a subroutine)
E = number of edges (transfers of control)
N = number of nodes (sequential group of statements containing only one transfer of control)
More on CYC
Metrics Study
Code Coverage
Tools exist to measure the lines of code that are covered by tests. Some companies require a certain threshold of testing (e.g. 75% of lines covered) with every pull request, otherwise the build fails.
codecov is an example
+10
+10 is a sanity check that another developer can checkout and run the code
This is not a full regression test but an assurance that the code in question passes a minimal test on a separate developer’s machine
Keep the local dev story working...
Capture Output
Attach these artifacts to any review. Be as verbose as possible, but be careful of logging PII (Personally Identifiable Information).
Questions?