'Pro'gramming Tips
Seriously are you trying to teach me how to write code?
Well, Not exactly.
Analyse First - Code Next!
Ever wonder what value could be added while analysing the problem before jumping to code? Of course you may be doing it! Make sure not to skip below
- Have a phase wise solution to achieve the target.
- Don't go with assumptions.
- Make sure to the solution gets reviewed by peers, go with justifications & accept feedbacks.
- Don't ignore negative scenarios, most of the people fail to foresee them, land them in bugs during testing phase.
- Last but not least... Use boards or Papers to simulate your programme before coding.
Functional Programming
- Are you writing a single function to solve the whole problem? Never ever do that.
- Break the complex function to small functions, accepts input to produce output & doesn't rely on any shared resources.
- Unit Testing made easy. Possible to achieve ??.
- Reusability.
Avoid Tightly Coupled Code
- Implement the class from Interface/protocol. This may not be applicable in all cases (ex: Utils)
- Avoid declaring class variables with concrete class types. Instead define them with interface type.
- Helps to develop scalable solutions.
- Dependency injection made easy, to support multiple runtime configurations.
- Enables to Mock & Again Unit Testing made easy. Possible to achieve ??
Tightly Coupled Code
/// Tightly Coupled 'FeatureView' class ApiService { func fetchTransactions() } class FeatureView { var serviceLayer: ApiService // FeatureView is tightly coupled to APIService class }
Loosely Coupled Code
/// Loosely Coupled 'FeatureView' protocol ServiceProtocol { func fetchTransactions() } class ApiService: ServiceProtocol { func fetchTransactions() } class FeatureView { var serviceLayer: ServiceProtocol // FeatureView is loosely coupled to Service layer }
Appropriate names
- Don't ignore giving right names to your classes, methods & variables.
- It is good to be both clear and brief as possible, but clarity shouldn’t suffer because of brevity
- In general, don’t abbreviate names of things. Spell them out, even if they’re long.
- Prefixes are an important part of names in programmatic interfaces. They differentiate functional areas of software.
Code Documentation
It Matters!
- Documentation is one of the must thing, we often ignore while programming.
- It adds value to the code & sometimes it even make us to rethink about the implementation.
- Its main objective is to make every other developer understands the code, even the actual developer is not around.
- Always follow the standard way of documenting the code as per IDE guidelines.
Unit Testing
???? No Excuses!
- Ensures the quality of the code.
- Helps to find bugs during early phase of development.
- Guarantees productive time.
- its the only way that can assure you peaceful nights ??
PR reviews
- Do get your code reviewed by your peers.
- Raise small PR that helps to get them reviewed quickly.
- Follow IDE suggested best practices while writing code.
- Accept as many comments as possible to see optimised code.
Do practice for better results. Thanks for the read, Will keep sharing more tips.
Happy Coding????