My Programming Tips & Tricks
— programming — 2 min read
Here are some programming best practices, tips and guidance I've collected over the years. I aim to keep each point as concise as possible so that I can use it as reference material in the future. I hope you can find something useful in the list below!
Tips & Tricks
- Write so every function can be understood within 1 minute. If you have to get into the Zone, it’s a sign of smelly code
- Write code that is (stupidly) obvious and readable by future programmers, don’t use clever tricks.
- Keep your style and naming convention consistent, a project/solution is much easier to read with consistent naming on class, methods, tests. Try using a team shared EditorConfig.
- Understand the problem & solution before coding. TDD forces this.
- If you don't understand the problem or solution build a simple prototype. Then stop working on the prototype as soon as you understand.
- Use exploratory tests if you don't understand how something works e.g. a third party api.
- Design programs with reusable, modular layers
- Learn when to use CRUD, Clean Architecture, Event Driven Architecture, Event Sourcing, etc. There are times for simple architecture, times for complex and sometimes solutions are comprised of both.
- Use the correct tool for the job, this may take some investigation into the trade-offs between tools i.e. C# vs Python, Serverless vs Microservices.
- Design everything to be testable from the beginning (test first). Design your solution to be test first, application to be test first, code test first ... you get the idea. There are many reasons why.
- Don't optimise until it works.
- Classes should be highly cohesive (all field variables are used in functions). Break the class apart when field variables are used sporadically.
- It’s better to have lots of small classes than a class with lots of small functions
- Use integration tests for database code, this tests the query language (e.g. SQL), database schema, and the connection. Remember to setup and teardown test data.
- Use unit tests for as much as possible but they are especially useful for edge cases and exceptions.