Tidbits
-
Keep documentation nearby
Documentation that lives outside the code base is hard to keep updated, or even locate. Keep documentation near code, make it part of the PR process. Use readmes with examples right next to the code files, add large block comments in the code, be verbose.
-
Understand service lifetimes
When opting for dependency injection, get to know the ins and outs of service lifetimes—they can turn a powerful pattern into a production nightmare.
-
Make Git easier, use better tooling
Branching, merging, creating releases and cleaning up shouldn't be as hard as it is sometimes. I’ve been using the extremely useful scalable-git-branching-tools for a few months now and Git has never been so simple.
-
Thinking big is earned
Bringing ideas to the table requires investment in the work and people around you. Build trust, engage and prove you can deliver—you'll hit fewer road blocks and your career will be much more fulfilling.
-
Answer questions with code
One of the best answers to a code review question isn't a one-off explanation or phone call, its a refactor (or inline comment).
Conversations don't scale, your code needs to speak to the broader audience and respect people's time. If someone expresses confusion or concern that's your cue to reevaluate what your code is really saying.
- C#
Not everything needs to be public
internal is a great encapsulation tool that many throw out the door when unit testing. Add the following to the source .csproj file to make internals accessible:
<ItemGroup>
<InternalsVisibleTo Include="TargetProject" />
</ItemGroup>
-
Reduce debt at every opportunity
Don't let technical debt become so burdensome that it hinders work and sanity—follow the Boy Scout rule, "Always leave the campsite cleaner than you found it".
Features, stories, and tasks always have room to reduce debt and increase readability.
-
Always be threat modeling
Data is a liability. You should consistently be questioning which resources need protection, system boundaries, access capabilities from all sides, and what it would take to feasibly cause a breach.
-
Semantic slots brings context to styles
Semantic slots allow labeling of CSS property values with context friendly notation e.g. color: slot.get('body.text.primary');
Try out scss-semantic-slots and write more consistent SASS.
-
Dependency Injection is always the answer
There aren't many hills I'd die on, but DI is one I refuse to budge on.
The minor inconvenience of complexity is far out weighed by a code base's ability to be easily manipulated with minimal side effects.
-
Blazor + HTML minification
Blazor tracks local state through HTML comments. HTML minification should exclude Blazor: comments to avoid rendering the application unusable.
-
A job done well means not over-engineered
Over-engineering is a complexity that burdens code bases, developers and budgets. We need to encourage each other to solve today's problems, not tomorrows.
-
Could, would, should
Three powerful words I use consistently in code reviews. No condescending tones, no orders, just simple open ended questions leading the author to reevaluate and stay in control of their code.
-
Async locking
Async by design may not resume on its original thread which can result in deadlocks. Locking needs to occur through a shared resource, a semaphore.
-
Pre-filtering large datasets
When dealing with missing indexes or large data sets across joins, in-memory temp tables are often be a highly performant solution.
-
Use a dated coding journal
Every day a number of thoughts weave in and out of our minds. I forgot more than I remember so I take notes: where I left off, TODOs, design decisions, potential issues, follow-ups, action items, thoughts, and so much more.
Trust the note not the memory.
-
Quick Git - Undo local commits
git reset --soft {commit sha}
-
Quick Git - Remove local commits
git reset --hard {commit sha}
-
Quick Git - Undo local changes
# remove uncommitted files
git add .
git stash
git stash drop
# remove untracked files
git clean -fdx
-
Quick Git - Remove branches
# remove local branch
git branch -D {branch}
# remove remote branch
git push -d origin {branch}
-
Nest less
Nesting reduces readability and increases cognitive load. Reduce, or better yet, never nest. Return early and extract code blocks when feasible.
-
SOLID, KISS, DRY = suggestions, not rules
Extensibility, flexibility and maintainability should be balanced with future effort and developer sanity and onboard-ability.
Often times it is okay to repeat yourself, it is okay to be verbose and straightforward.
- C#
LINQ .Distinct on ordered results
If you've noticed that your ordered results become unordered after materializing with .Distinct(), give .GroupBy() a try.
- C#
WebApi [FromBody]
Web Api's [FromBody] seems to confuse a lot of developers. By default Web Api will only look for primitive types (string, int, etc) in the uri.
For actions using primitive types in the body such as Post(int userId) we must tell the Web Api binder to look at the body of the request, not the uri, by decorating arguments with [FromBody].
-
CSS adjacent selector (+)
The + selector will apply style to the element immediately following the + selector. In the example below the p tag immediately following the h1 tag will have top margin.
h1 + p { margin-top: 2em; }
-
Naming is hard
Naming and organization is one of the hardest parts of engineering. A poorly chosen name will haunt your code base for years, don't under think it.