Tagged Questions
67
votes
11answers
4k views
Never use Strings in Java? [closed]
I stumbled upon a blog entry discouraging the use of Strings in Java for making your code lack semantics, suggesting that you should use thin wrapper classes instead. This is the before and after ...
1
vote
1answer
116 views
The purpose of using a constants pool for immutable constants
Originally posted at stackoverflow.com/q/23961260
I come across the following code with a lot of frequency:
if (myArray.length == Constants.ZERO_INT)
or
if (myString != null && ...
0
votes
2answers
274 views
How to enforce good coding style in team? [duplicate]
Even if I don't like enforcing people to do things (and I believe that it may decline the productivity and cause anger), I really want to enforce good coding style.
Is there a way to set up ...
24
votes
5answers
3k views
Why is it bad to write something in language X as if you're writing a program in language Y in terms of using a shared coding paradigm [closed]
A while ago, I asked a question on SO about something written in C++, but instead of getting an answer to the problem at hand, the comments went all crazy on my coding style, even when I indicated ...
22
votes
4answers
7k views
In Java, should I use “final” for parameters and locals even when I don't have to?
Java allows marking variables (fields / locals / parameters) as final, to prevent re-assigning into them. I find it very useful with fields, as it helps me quickly see whether some attributes - or an ...
1
vote
2answers
315 views
How to choose a code style for C++ [closed]
When starting to learn one new language, we have to choose perfect code style such as types or file name's first letter should be uppercase or lowercase, etc. But when I started to learn C++, I did ...
3
votes
6answers
953 views
More elegant way to avoid hard coding the format of a a CSV file?
I know this is trivial issue, but I just feel this can be more elegant.
So I need to write/read data files for my program, lets say they are CSV for now. I can implement the format as I see fit, but ...
9
votes
6answers
9k views
How are multiple values returned in Java?
Sometimes you want to return multiple values from a function. How is this normally done in Java?
One option is to use an array, like this Python snippet that returns a list or tuple:
value, success ...
3
votes
2answers
1k 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 ...
9
votes
4answers
687 views
What makes for “good style” in Java? [closed]
I had asked this question on Stackoverflow, and before it got booed off, I received the helpful suggestion from Péter Török that this might be a better place to post it.
I've been programming in Java ...
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 ...
1
vote
2answers
137 views
Is repeating links to the same class in a single javadoc comment a bad practice?
I'm currently writing an API and its documentation. For example I have something like this:
public interface Event {
}
public interface Process {
}
public interface EventProcessor {
/**
* ...
0
votes
5answers
123 views
Where to read from file?
In Java: I have a class Students. I would like to read a list of students from a file. Which one is more elegant:
Reading and constructing the list in main(), and creating a Student object with the ...
1
vote
3answers
201 views
About the usage of assertions [duplicate]
I stumbled upon an article named Programming With Assertions.
And beside the mechanism of turning on and off assertions after compile time, I don't get it. Why were assertions introduced on language ...
2
votes
1answer
217 views
Unindented elses
Been writing code since about 18 years now. Lately, I've got into the habit of not indenting elses and when I look at the code it does worry me a bit mostly that someone who might look at the code ...
6
votes
3answers
894 views
Is there an appropriate coding style for implementing an algorithm during an interview?
I failed an interview question in C years ago about converting hex to decimal by not exploiting the ASCII table if (inputDigitByte > 9) hex = inputDigitByte - 'a'. The rise of Unicode has made ...
4
votes
5answers
2k views
In Java, should private helpers go above or below public methods?
I've noticed that a coworker and I have opposite practices regarding the ordering of methods in our Java classes. One of us begins a class with its major public methods, and then put all of the ...
17
votes
5answers
1k views
What are the benefits of prefixing function parameter names with p*?
I often see projects (in Java projects and teams using Eclipse) that prefix function parameters with p.
For example
public void filter (Result pResult) ...
I personally don't see any benefit in ...
5
votes
2answers
558 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, ...
0
votes
4answers
253 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 ...
7
votes
4answers
419 views
Warn about 3rd party methods that are forbidden
Note: This question refers to code written in Java or C#.
I am managing a couple of large projects where we have discovered issues (not necessarily bugs) with some 3rd party/SDK methods and have ...
8
votes
5answers
584 views
Is it customary to write Java domain objects / data transfer objects with public member variables on mobile platforms?
We performed a code review recently of mobile application Java code that was developed by an outside contractor and noticed that all of the domain objects / data transfer objects are written in this ...
2
votes
3answers
550 views
Is there a faster way to work out this logic?
The purpose of this assignment was the find the smallest and largest of the integer(User inputs 5 entries)
I am a beginner Java programmer with no prior experience. Is there an easier way to do this ...
14
votes
5answers
5k views
Should a string constant be defined if it's only going to be used once?
We're implementing an adapter for Jaxen (an XPath library for Java) that allows us to use XPath to access the data model of our application.
This is done by implementing classes which map strings ...
12
votes
8answers
2k views
What is the accepted style for using the `this` keyword in Java?
I come from languages like Python or Javascript (and others that are less object-oriented) and I am trying to improve my working knowledge of Java, which I know only in a superficial way.
Is it ...
4
votes
1answer
813 views
Programming in academic environment vs industry environment [duplicate]
Possible Duplicate:
Differences between programming in school vs programming in industry?
This is a general discussion about programming in the industry environment.
The background story is ...
5
votes
3answers
616 views
Is it bad idea to use flag variable to search MAX element in array?
Over my programming career I formed a habit to introduce a flag variable that indicates that the first comparison has occured, just like Msft does in its linq Max() extension method implementation
...
2
votes
6answers
2k 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 ...
7
votes
3answers
2k views
Should I use default access modifier or not — Coding practice?
Normally when creating new global variables I do not define its access modifier. So as per java it will adopt property default access modifier. When I'm need to access that variable in out of default ...