Tagged Questions
-5
votes
1answer
136 views
Java lacking some convention?
I have been using Java for a couple of years now and I cannot think of another language to use. There are however some things that are bugging me.
Why are you allowed to have public variables? I ...
2
votes
2answers
233 views
Is using “out” or “ref” parameters in Java methods to return extra values bad?
I happened to create a mutable class like this:
class Mutable<T> {
private T value;
public Mutable() { this.value = null; }
public Mutable(T value) { this.value = value; }
T ...
30
votes
8answers
2k views
Is it necessary to add the default case while using switch cases?
During a recent code review I was asked to put default cases in all the files wherever switch block is used, even if there is nothing to do in default. That means I have to put the default case and ...
2
votes
8answers
475 views
tips, guidelines, points to remember for rendering professional code? [closed]
I'm talking about giving clients professional looking code. The whole nine yards, everything you hardcore professional highly experienced programmers here probably do when coding freelance or for the ...
2
votes
2answers
276 views
What package name to choose for a small, open-source Java project?
I'd like to publish a small open-source library in Java. I wonder what package name should I choose? I'm not a company and I don't have a domain that I could use as the basis for naming the package ...
5
votes
2answers
443 views
Should you create a class within a method?
I have made a program using Java that is an implementation of this project: http://nifty.stanford.edu/2009/stone-random-art/sml/index.html. Essentially, you create a mathematical expression and, ...
10
votes
13answers
1k views
Should I add an “Abstract” prefix to my abstract classes?
Suppose I have an abstract class named Task.
Is there a standard or convention that would suggest I should name it AbstractTask instead?
7
votes
3answers
249 views
When comparing a combination of String literals, is it convention to call .equals() on the literal? [closed]
There are benefits to each, and I understand the differences - but what is considered best / standard practice? Why?
"myString".equals(myStringVar)
Avoids a potential NPE and does not require a ...
2
votes
1answer
326 views
Package conventions for MVC app [closed]
Which (if either) of the below is the more conventional/acceptable way to structure packages in a J2EE app? I'm trying to follow an MVC pattern as much as possible.
foo.bar.users
...
5
votes
2answers
1k views
What are the reasons one would use fully qualified class names in source code?
I recently ran across code where the developers used both fully qualified class names AND imported class names in their source code.
Example:
import packageA.Foo;
public class Example {
public ...
11
votes
8answers
653 views
Conflicting Java Styles within a Team
I am part of a Java development team with a 6 week deadline. This necessitates writing a good deal of code very very quickly. However our development team has different styles of coding. Everything ...
3
votes
2answers
351 views
How to mark an empty conditional block in Java
In C++ when I wanted to mark that if is empty by design I added NULL; as statement:
if (cond1) {
...
} else if (cond2) {
NULL;
} else {
...
}
However in Java it seems to be impossible ...
371
votes
17answers
22k views
Where did the notion of “one return only” come from?
I often talk to Java programmers who say "Don't put multiple return statements in the same method." When I ask them to tell me the reasons why, all I get is "The coding standard says so." or "It's ...
28
votes
7answers
3k views
Excessive use “final” keyword in Java
While I understand what the final keyword is used for in the context of classes and methods as well as the intent of its use for in regards to variables; however, the project I just started working on ...
2
votes
6answers
1k views
Line break before/after operator
While Sun's Java code convention suggests to put line break before the operator many other guidelines disagree with it. I do not see any obvious pros and cons, so are there advantages of using one of ...
17
votes
9answers
545 views
Advantages and Disadvantages of Forced Code Reformat
I'm currently working at a place that may be looking at forcing developers to use an automated code formatter on version control check-in. I'm looking for developers opinions on the advantages and ...
5
votes
4answers
320 views
How to apply one of the OOP concepts (Closed for Modification and Open for extension)?
Days before, I created Question, Quiz, and Main classes. One Quiz has one or more Questions. From the main class I first create Question objects (the constructor accepts an array of numbers). The Quiz ...
8
votes
8answers
4k views
Best practices for constants
How do you guys handle constants, especially in Java (static final) and C++ (define)?
Do you use dedicated headers (C++) or classes (Java) for all constants?
Do you turn all literal values into ...
9
votes
9answers
412 views
Studies on code documentation productivity gains/losses
After much searching, I have failed to answer a basic question pertaining to an assumed known in the software development world:
WHAT IS KNOWN:
Enforcing a strict policy on adequate code ...