1
vote
1answer
144 views

Java code quality in methods calling methods

I am currently working with an "interesting" code-base and see the following type of thing alot in the code. public Object doSomething() { Object obj = new Object(); // Do some stuff to the ...
2
votes
1answer
186 views

equals and hashcode methods autogenerated, is it always a good practice?

Preamble: Let's say I aim to cover all my classes with test coverage. Despite the common opinion (expecially in Java community) to "not pay too much attention to Cyclomatic Complexity (CC) and code ...
2
votes
3answers
287 views

Which one of these designs is preferred? [duplicate]

In the case of an application with a single simple responsibility (eg, a simple replacement for grep or wc), which of these designs is preferred and why? I find that they are all testable and they all ...
12
votes
7answers
2k views

Avoid too complex method - Cyclomatic Complexity

Not sure how to go about this method to reduce Cyclomatic Complexity. Sonar reports 13 whereas 10 is expected. I am sure nothing harm in leaving this method as it is, however, just challenging me how ...
13
votes
9answers
3k views

Are too many if-else statements for validation bad? [duplicate]

From the book Professional Enterprise .Net, which has 5 star rating on Amazon that I am doubting after having a read through. Here is a Borrower class (In C# but it's pretty basic; anyone can ...
4
votes
3answers
564 views

Code review if nobody in team has knowledge in some technology?

Sample situation: A team of Java developers starts an iOS project. Only one developer has Objective-C/iOS knowledge, and in the beginning he will work on this project alone. How we can perform code ...
0
votes
1answer
349 views

Really bad example projects that use sonar [closed]

When consideringen whether to use sonar or not, it would be great to see both good code as well as bad code that use sonar for static code analysis. I have browsed http://nemo.sonarsource.org/ ...
15
votes
5answers
854 views

Is this pattern bad? [duplicate]

I notice that when I code I often use a pattern that calls a class method and that method will call a number of private functions in the same class to do the work. The private functions do one thing ...
4
votes
3answers
1k views

HTML code in Java class

A conceptual question, I tried to google but couldn't find any definitive answers, so here it goes: Is it a good practice to write Java methods to return HTML strings that will be returned to the ...
9
votes
1answer
551 views

Is there a modern replacement for a mutation testing tool like Jester for Java?

“Why just think your tests are good when you can know for sure? Sometimes Jester tells me my tests are airtight, but sometimes the changes it finds come as a bolt out of the blue. Highly ...
1
vote
2answers
120 views

@Deprecated as of version x.y in JavaDoc

This question & its answers are useful but not sufficient for my problem. My Question is if I want to add a javadoc as @Deprecated As of version x.y, replaced by {@link SomeClass} in my current ...
47
votes
10answers
3k views

When does “proper” programming no longer matter?

I've been building an android game in my spare time. It's using the libgdx library so quite a bit of the heavy lifting is done for me. While developing, I carelessly selected datatypes for some ...
13
votes
2answers
957 views

What is the best approach for inline code comments?

We are doing some refactoring to a 20 years old legacy codebase, and I'm having a discussion with my colleague about the comments format in the code (plsql, java). There is no a default format for ...
4
votes
1answer
241 views

Distinguishing repetitive code with the same implementation

Given this sample code import java.util.ArrayList; import blackjack.model.items.Card; public class BlackJackPlayer extends Player { private double bet; private Hand hand01 = new Hand(); ...
8
votes
11answers
7k views

Why is using System.out.println() so bad? [closed]

Of course, it is very good use to use a logging framework for the error messages or warnings. But sometimes I use System.out.println() if I want to try something new in a short time. Is it really so ...
0
votes
4answers
251 views

Is 'Protection' an acceptable Java class name

This comes from a closed thread at stack overflow, where there are already some useful answers, though a commenter suggested I post here. I hope this is ok! I'm trying my best to write good ...
9
votes
5answers
929 views

Is it bad coding practice to create something in a get if it does not exist?

So I have a webservice that has something like a getAccount where it would return an identifier to the account if it got it, else throw an exception. The client will always want to create an account ...
26
votes
5answers
2k views

Is use of finally clause for doing work after return bad style/dangerous?

As part of writing an Iterator, I found myself writing the following piece of code (stripping error handling) public T next() { try { return next; } finally { next = ...
2
votes
2answers
254 views

SONAR and DesignForExtensionCheck Rule

When enabling SONAR on an in-house Java project, there are a large number of violations being reported due to the rule DesignForExtensionCheck. Whilst I agree with the theory that all classes/methods ...
2
votes
3answers
270 views

in doubt of using code generators

I am now entering the world of java ee 6. And I am supposed to used different technologies like jsf, jpa, different kinds of beans and all that stuff. I am learning using the netbeans IDE, which is, ...
6
votes
5answers
1k views

Prefer class members or passing arguments between internal methods?

Suppose within the private portion of a class there is a value which is utilized by multiple private methods. Do people prefer having this defined as a member variable for the class or passing it as ...
3
votes
1answer
6k views

What is the best way to comment a deprecated class in Java?

I would like to know the best way to add a comment to identify a deprecated class in Java. Should I remove the previous comment added to the top of the class that helps another programmer to know what ...
5
votes
6answers
303 views

How to keep a project easy to understand and intutive?

I am working on this project, which will soon contain loads of packages, projects etc. (Java). So, from the start I need to keep track of the high level package and class structure, monitor which ...
1
vote
6answers
467 views

Structuring multi-threaded programs

Are there any canonical sources for learning how to structure multi-threaded programs? Even with all the concurrency utility classes that Java provides I'm having a hard time properly structuring ...
18
votes
9answers
3k views

Is there any reason to use “plain old data” classes?

In legacy code I occasionally see classes that are nothing but wrappers for data. something like: class Bottle { int height; int diameter; Cap capType; getters/setters, maybe a ...