15
votes
12answers
2k views

Why use getters only as opposed to marking things final? [duplicate]

I'm working in a java role after working a couple years in functional programming. Our company was bought by google and I took a java role after the acquisition. Coming back to java as a polyglot ...
3
votes
3answers
486 views

Is it common to use code you don't understand? [closed]

I have been working on a project recently that uses a pretty comprehensive framework built by someone else. The framework is free to use commercially and privately as anybody sees fit, so there are no ...
12
votes
6answers
5k 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 ...
6
votes
2answers
832 views

Java convention for if/else if order

I have an if/else if structure that on some cases does nothing. From the code I have seen in my career, the "empty" case is normally left out. But when I wrote my code, it just doesn't feel right to ...
3
votes
2answers
2k views

Excessive use “this” keyword in Java [duplicate]

The this keyword is primarily used in three situations. The first and most common is in setter methods to disambiguate variable references. The second is when there is a need to pass the current ...
4
votes
2answers
773 views

Java naming conventions vs. C++/C naming conventions

I am a Java developer who is starting to pick up more and more C++/C (yes I know they're different, bear with me). One thing that struck me as odd was the different naming conventions used by these ...
3
votes
3answers
1k views

articles in variable names and hard-coding strings

re-edited by author: no this is not 2 questions. This is one question about code review questions containing two separate points. Please do not edit my question. For naming variables, the two sides ...
4
votes
4answers
4k 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
10k 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
822 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 ...
4
votes
2answers
824 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
610 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
4k views

Should I add an “Abstract” prefix to my abstract classes? [closed]

Suppose I have an abstract class named Task. Is there a standard or convention that would suggest I should name it AbstractTask instead?
8
votes
3answers
516 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
472 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
4k 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 ...
12
votes
8answers
1k 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
996 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 ...
523
votes
21answers
50k 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 ...
38
votes
7answers
10k views

Excessive use “final” keyword in Java [duplicate]

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 ...
0
votes
9answers
3k views

Line break before/after operator [closed]

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 ...
18
votes
9answers
773 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
467 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 ...
10
votes
8answers
12k 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
450 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 ...