Coding Principle

Hello Folks,

In this blog will be pointing out some utmost coding principle that would help y’all.

  • Follow the best practices / style guidelines in your programming environment / programming language. Use automatic style checking (e.g. findbugs, checkstyle, PMD).
  • Strive to self- documented code. Add comments if necessary.
  • Use a good IDE (e.g. Eclipse, VisualStudio) and good tools (e.g. SOAPUI for web service test, Maven for build, Hudson for continuous integration, Trac.)
  • Use software configuration management ( SCM ) system (e.g. SVN)
  • Use proven design patterns and beware of anti-patterns
  • Limit accessibility : e.g. declare classes/methods/fields as private instead of public
  • Loose coupling , strong cohesion e.g. Spring dependency injection.
  • Aspect oriented programming, separation of concerns (e.g. Spring AOP for logging, security, transaction, error handling, cache)
  • Use declarative configurations instead of programmatic coding for cross cutting concerns (e.g. WS-policy for security) . The code ideally only focus to the business logic, has little knowledge of the framework (e.g. using AOP & declarative transactions in Spring to hide the underlying transaction mechanism).
  • Use templates to reduce coding (e.g. Spring DAO templates, Velocity JSP templates)
  • Use standard library /solutions don’t reinvent new wheels.
  • If you use multithreading: beware of locking effects to the performance, beware of race condition
  • Defensive programming: test before executing (e.g. null checking in Java/BPEL), handle exception gracefully, protect from bad inputs (validate, substitute with legal values).
  • Beware of common errors in your development language (e.g. null pointer exception in Java or buffer overflow in C++)
  • Use abstraction layer (e.g. use JAAS for authentication, DAO layer for database access) for loose coupling / flexibility
  • Choose libraries, vendors , tools carefully, consider e.g. maturity, popularity, support, future viability
  • Use thin clients (more robust, better performance)
  • Use early/ static binding for better run-time performance
  • Use pre-assign size instead of using dynamic growth datatype
  • Use pre-assign number of parameters instead of using dynamic number of params
  • Build the instrumentation up front during coding, e.g. test ( TDD , performance measure), log , build /deploy script.
  • Reuse result (e.g. using temp variables) to reduce number of calls
  • Use implicit interface instead of explicit to reduce method call overhead.
  • If you use asynch/multithreading, do you have message timing/sequencing problem en how to deal with this problem? e.g. if the software received 3 message events (in arbitrary sequence) which are order interdependent?
  • Write a short “getting started” developer document (e.g. designs, data models, class diagrams, dependencies, configurations, service request/response examples, troubleshooting / error scenarios). This document will be especially useful when you act as an external consultant / temporary project developer or if you need to pass the project to other colleagues (perhaps you leave the company, or have to take another project, or get promoted.

Thankyou.