Code Quality
How do you ensure code quality in your application?
A. code quality means writing readable and robust code, that conforms as much as possible to the style-guideline that is used, and that has as little as possible defects. It also means writing maintainable code with proper automated and manual tests.
Automated tests
Have regular code reviews. There are tools like Crucible from Atlassian that gives your team an efficient way to benefit from the power of constant code review with features like inline commenting, simple workflow, asynchronous reviews, email and RSS notifications, JIRA integration and much more.
Code quality tools
Using continuous integration servers (on a clean separate machine) like Bamboo, Hudson,CruiseControl, etc to continuously integrate and test your cod
Not stopping to code once the code works. Too many developers feel their job stops at making something happen. It is a best practice to constantly refactor code with proper unit tests in place.
What do you look for when you are reviewing others' code?
Potential issues relating to thread-safety, performance, memory leak, scalability, transaction management, exception handling, etc. Also, look for the key areas like best practices, design concepts, and design patterns.
Naming conventions,Delete unused code,Unnecessary comments,Repeated code due to copy-paste,Tightly coupled code,Badly defined variable scopes or variable types,Deeply nested loops or conditionals,Not properly handling exceptions
UML diagrams
Use case diagrams
interaction between external users (i.e. actors) and the system. A use case is a summary of scenarios for a single task or goal. An actor is responsible for initiating a task. The connection between actor and use case is a communication association.
Usecase diagrams have the following possible relationships ...Include,Extend and Inhertance
Class diagrams have the following possible relationships
Association: A relationship between instances of 2 classes.
Aggregation: An association in which one class belongs to a collection (does not always have to be a collection. You can also have cardinality of “1”). This is a part of a whole relationship where the part can exist without the whole. For example: A line item is whole and the products are the parts. If a line item is deleted then the products need not be deleted.
Composition: An association in which one class belongs to a collection (does not always have to be a collection. You can also have cardinality of “1”). This is a part of a whole relationship where the part cannot exist without the whole. If the whole is deleted then the parts are deleted. For example: An Order is a whole and the line items are the parts. If an order is deleted then all the line items should be deleted as well (i.e. cascade deletes).
Generalization: An inheritance link indicating that one class is a superclass of the other. The Generalization expresses the “is a” relationship whereas the association, aggregation and composition express the “has a” relationship.
Realization: Implementation of an interface.
Dependency: A dependency is a weak relationship where one class requires another class. The dependency expresses the “uses” relationship. For example: A domain model class uses a utility class like Formatter etc.
A. code quality means writing readable and robust code, that conforms as much as possible to the style-guideline that is used, and that has as little as possible defects. It also means writing maintainable code with proper automated and manual tests.
Automated tests
- Unit tests using JUnit or TestNG. For unit tests use mock objects to ensure that your tests don't fail due to volatility of the data changes. There are mocking frameworks like EasyMock, Mockito, andPowerMock.
- Integration testing of your services with JUnit or TestNG. Your integration tests are only as good as the quality of the data. You could either use dedicated test databases or use frameworks like DBUnit to manage extraction and insertion of data.
- Web testing using Selenium + WebDriver. Selenium + WebDriver allows you to reenact web user experience and run it as an automated unit test using JUnit or TestNG.
- Load testing your application with tools like JMeter, OpenSTA, etc. The Badboy compliments JMeter by allowing you to record scripts and then exporting the scripts as a JMeter file to be used in JMeter
Have regular code reviews. There are tools like Crucible from Atlassian that gives your team an efficient way to benefit from the power of constant code review with features like inline commenting, simple workflow, asynchronous reviews, email and RSS notifications, JIRA integration and much more.
Code quality tools
- Checkstyle ensures the style of your Java code is standardized and "nice". It checks white spaces, new lines, formatting, etc. (i.e. it looks on the code line by line). This only ensure style of your code.
- On the other hand there is PMD which not necessarily checks the style of your code but it checks the structure of the whole code. PMD scans Java source code and looks for potential problems like possible bugs, dead code, suboptimal code, overcomplicated expressions, duplicate code, etc.
- FindBugs is a static analysis tool to look for bugs in Java code. It discovers possibleNullPointerExceptions and a lot more bugs.
- Sonar is a very powerful tool covering 7 axes of code quality
Using continuous integration servers (on a clean separate machine) like Bamboo, Hudson,CruiseControl, etc to continuously integrate and test your cod
Not stopping to code once the code works. Too many developers feel their job stops at making something happen. It is a best practice to constantly refactor code with proper unit tests in place.
What do you look for when you are reviewing others' code?
Potential issues relating to thread-safety, performance, memory leak, scalability, transaction management, exception handling, etc. Also, look for the key areas like best practices, design concepts, and design patterns.
Naming conventions,Delete unused code,Unnecessary comments,Repeated code due to copy-paste,Tightly coupled code,Badly defined variable scopes or variable types,Deeply nested loops or conditionals,Not properly handling exceptions
UML diagrams
Use case diagrams
interaction between external users (i.e. actors) and the system. A use case is a summary of scenarios for a single task or goal. An actor is responsible for initiating a task. The connection between actor and use case is a communication association.
Usecase diagrams have the following possible relationships ...Include,Extend and Inhertance
Class diagrams have the following possible relationships
Association: A relationship between instances of 2 classes.
Aggregation: An association in which one class belongs to a collection (does not always have to be a collection. You can also have cardinality of “1”). This is a part of a whole relationship where the part can exist without the whole. For example: A line item is whole and the products are the parts. If a line item is deleted then the products need not be deleted.
Composition: An association in which one class belongs to a collection (does not always have to be a collection. You can also have cardinality of “1”). This is a part of a whole relationship where the part cannot exist without the whole. If the whole is deleted then the parts are deleted. For example: An Order is a whole and the line items are the parts. If an order is deleted then all the line items should be deleted as well (i.e. cascade deletes).
Generalization: An inheritance link indicating that one class is a superclass of the other. The Generalization expresses the “is a” relationship whereas the association, aggregation and composition express the “has a” relationship.
Realization: Implementation of an interface.
Dependency: A dependency is a weak relationship where one class requires another class. The dependency expresses the “uses” relationship. For example: A domain model class uses a utility class like Formatter etc.
Security
<web-app>
<security-constraint>
<web-resource-collection>
<web-resource-name>Employer</web-resource-name>
<description></description>
<url-pattern>/execute/employ</url-pattern>
<http-method>POST</http-method>
<http-method>GET</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<description></description>
<role-name>advisor</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>FBA</realm-name>
<form-login-config>
<form-login-page>/execute/MyLogon</form-login-page>
<form-error-page>/execute/MyError</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description>Advisor</description>
<role-name>advisor</role-name>
</security-role>
</web-app>
<security-constraint>
<web-resource-collection>
<web-resource-name>Employer</web-resource-name>
<description></description>
<url-pattern>/execute/employ</url-pattern>
<http-method>POST</http-method>
<http-method>GET</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<description></description>
<role-name>advisor</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>FBA</realm-name>
<form-login-config>
<form-login-page>/execute/MyLogon</form-login-page>
<form-error-page>/execute/MyError</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description>Advisor</description>
<role-name>advisor</role-name>
</security-role>
</web-app>