Coding style is a set of guidelines that helps readability and understanding of the source code.
8
votes
2answers
146 views
Where should I define constants in scripts?
When writing scripts using a modern scripting language, e.g. Powershell or JavaScript, where should I define constants? Should I make all constants global for readability and ease of use, or does it ...
3
votes
3answers
468 views
When to write an explicit return statement in Groovy?
At the moment I am working on a Groovy/Grails project (which I'm quite new in) and I wonder whether it is good practice to omit the return keyword in Groovy methods. As far as I know you have to ...
4
votes
4answers
431 views
Switch or a Dictionary when assigning to new object
Recently, I've come to prefer mapping 1-1 relationships using Dictionaries instead of Switch statements. I find it to be a little faster to write and easier to mentally process. Unfortunately, when ...
2
votes
4answers
220 views
Long lines of text in source code [duplicate]
Possible Duplicate:
Is the 80 character limit still relevant in times of widescreen monitors?
I used to set a vertical line set at 80 characters in my text editor and then I added carriage ...
0
votes
3answers
180 views
What HTML attributes are mandatory or should be avoided? [closed]
I know that some attributes are mandatory for some HTML elements. For example, to write W3C compliant code, img element should have alt attribute.
In order to stay away from bad habits:
Are there ...
2
votes
1answer
140 views
How do I organize a GUI application for passing around events and for setting up reads from a shared resource
My tools involved here are GTK and Haskell. My questions are probably pretty trivial for anyone who has done significant GUI work, but I've been off in the equivalent of CGI applications for my whole ...
10
votes
5answers
377 views
Should coding standards be enforced by the continuous integration server?
Should coding standards/style be enforced by the continuous integration server running static analysis tools (ex. PMD, StyleCop/FxCop) and failing the build if the standards are not followed? What ...
13
votes
11answers
1k views
Teaching myself, as a physicist, to become a better programmer
I've always liked physics, and I've always liked coding, so when I got the offer for a PhD position doing numerical physics (details are not relevant, it's mostly parallel programming for a cluster) ...
1
vote
4answers
247 views
Is extensive documentation a code smell? [closed]
Every library, open-source project, and SDK/API I've ever come across has come packaged with a (usually large) documentation file, and this seems contradictory to the wide-spread belief that good code ...
7
votes
7answers
951 views
Why would an employer ask for a 'long' code sample?
What would a large project that spanned multiple files and >1000 lines show to an employer that a few individual files and a couple hundred lines couldn't capture?
4
votes
2answers
228 views
What should my “large codebase sample” look like?
If an employer asks for a large code sample, one for an entire project, what characteristics should the project have to show architectural skills and the ability to manage a large codebase?
For ...
2
votes
3answers
122 views
conventions for friend methods in Perl
Perl doesn't support a friend relationship between objects, nor does it support private or protected methods. What is usually done for private methods is to prefix the name with an underscore. I ...
3
votes
6answers
835 views
Using prefix incremented loops in C#
Back when I started programming in college, a friend encouraged me to use the prefix incrementation operator ++i instead of the postfix i++, citing that there was a slight chance of better performance ...
8
votes
7answers
205 views
How does a “Variables introduce state”?
I was reading the "C++ Coding Standards" and this line was there:
Variables introduce state, and you should have to deal with as little state as possible, with lifetimes as short as possible.
...
6
votes
3answers
235 views
Style bits vs. Separate bool's
My main platform (WinAPI) still heavily uses bits for control styles etc. (example).
When introducing custom controls, I'm permanently wondering whether to follow that style or rather use individual ...
6
votes
3answers
222 views
How should I get my code ready for OpenSourcing it and putting it on GitHub?
In a few weeks, my project is going to be finished and I want to start getting my code ready for other people to use it.
I am going to be posting everything to GitHub so people can tweak it and ...
7
votes
9answers
1k views
Is it any good to use binary arithmetic in a C++ code like “C style”?
I like the fact that the C language lets you use binary arithmetic in an explicit way in your code, sometimes the use of the binary arithmetic can also give you a little edge in terms of performance; ...
24
votes
9answers
2k views
Simple vs Complex (but performance efficient) solution - which one to choose and when?
I have been programming for a couple of years and have often found myself at a dilemma.
There are two solutions -
one is simple one i.e. simple approach, easier to understand and maintain. It ...
-1
votes
2answers
176 views
Generic software code style enforcer [closed]
It seems to me to be a fairly common thing to do, where you have some code that you'd like to automatically run through a code style tool to catch when people break your coding style guide(s).
...
5
votes
4answers
323 views
Method flags as arguments or as member variables?
I think the title "Method flags as arguments or as member variables?" may be suboptimal, but as I'm missing any better terminology atm., here goes:
I'm currently trying to get my head around the ...
-5
votes
2answers
396 views
Is there any reason why I should use parentheses when calling new in PHP?
When there are no arguments, we have these two options:
$obj = new MyClass;
vs.
$obj = new MyClass();
I always pick the former, just because.
Any thoughts?
8
votes
4answers
354 views
How to avoid general names for abstract classes?
In general it's good to avoid words like "handle" or "process" as part of routine names and class names, unless you are dealing with (e.g.) file handles or (e.g.) unix processes. However abstract ...
31
votes
16answers
3k views
Should I continue my self-taught coding practice or learn how to do coding professionally? [closed]
Lately I've been getting professional work, hanging out with other programmers, and making friends in the industry. The only thing is I'm 100% self-taught. It's caused my style to extremely deviate ...
10
votes
9answers
1k views
LINQ Style preference [closed]
I have come to use LINQ in my every day programming a lot. In fact, I rarely, if ever, use an explicit loop. I have, however, found that I don't use the SQL like syntax anymore. I just use the ...
67
votes
15answers
3k views
Is defining a variable to name a method argument a good practice?
For the sake of readability I often find myself defining temporary variables while calling functions, such as the following code
var preventUndo = true;
doSomething(preventUndo);
The shorter ...
-1
votes
8answers
398 views
Arguments for a coding standard? [closed]
A few friends and i are planning to work on a project together and we want a COMPLETELY DIFFERENT coding standard. We do NOT want to use the coding standard the libraries/language uses. Its our ...
17
votes
6answers
859 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 ...
4
votes
3answers
286 views
Should I prefer properties with or without private fields?
The codebase I'm working in now has the convention of using private fields and public properties. For example, most classes have their members defined like this:
// Fields
private double _foo;
...
4
votes
6answers
328 views
Order of subject and modifiers in variable names
I'm looking for experiences regarding the ordering of the subject and modifiers in variable names.
A simple object Shape would have just a subject for the variable name, such as Area.
A slightly ...
2
votes
4answers
563 views
Should I put newlines before or after binary operators? [closed]
When you're in Python or Javascript, you should always put binary operators at the end of the previous line, in order to prevent newlines from terminating your code prematurely; it helps you catch ...
7
votes
3answers
425 views
What statements and approaches should I avoid when learning functional programming?
I have 6 years of programming experience, mostly following the object oriented paradigm, and I'm interested in learning functional programming. My main goal is to become a functional paradigm ...
0
votes
7answers
2k views
If condition not true: default value or else clause? [closed]
I have searched Programmers and Stackoverflow and was not able to come up with a satisfying answer, even though I'm quite sure it must have been asked many times before. The only question I found has ...
7
votes
5answers
472 views
Discussions of simplicity
Recently at my company we've had a bit of a debate about abstraction vs. simplicity. One school of thought I'd characterize as "DRY and abstraction can do no harm," and leads to code like this:
def ...
6
votes
4answers
1k views
Are fluent interfaces more flexible than attributes and why?
In a EF 4.1 Code First tutorial the following code is given:
public class Department
{
public int DepartmentId { get; set; }
[Required]
public string Name { get; set; }
public virtual ...
12
votes
12answers
830 views
What is the regarded current best practises regarding the “this” keyword in front of field and methods in c#?
Unless it is needed to differentiate between a variable and field with the same name, I never put this. in front of a field or any member access in C#. I see this as no different to m_ prefix that ...
31
votes
17answers
9k views
Single statement if block - braces or no?
Which is better/more generally accepted?
This:
if(condition)
{
statement;
}
Or:
if(condition)
statement;
I tend to prefer the first one, because I think it makes it easier to tell what ...
0
votes
2answers
580 views
GUI advice for a responsive touchscreen
I am tasked with building a piece of software that interfaces with a MySQL database, in order to allow the user to pick songs to play and que using a touch screen, and then they are shown ...
5
votes
6answers
791 views
Indentation: is there any evidence to show whether 2 or 4 spaces is more readable? [closed]
At the company I work for, we're trying to standardize our development practices, and we want to make the right call regarding indentation.
Is there any empirical evidence (preferably research ...
-1
votes
2answers
255 views
How to mix different styles of programming on several languages?
I know that Senior Developer doesn't use only one language and only one platform or IDE.
Can you advise how to mix different styles of programming to make efficient code?
For example, best mixing is ...
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, ...
0
votes
4answers
239 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
757 views
Zero as a constant?
I have come across this programming idiom recently:
const float Zero = 0.0;
which is then used in comparisons:
if (x > Zero) {..}
Can anyone explain if this is really any more efficient or ...
2
votes
6answers
2k views
Single quotes vs double quotes [closed]
I just started a job where I'm writing Python after coming from a Java background, and I'm noticing that other developers tend to quote strings using single quotes ('') instead of double quotes (""). ...
1
vote
3answers
218 views
How to use correctly the comments in C/++ [duplicate]
Possible Duplicate:
Style and recommendations of commenting code
I'm learning to program in C and in my stage, the best form to use correctly the comments is writing good comments from the ...
8
votes
5answers
406 views
Reformatting and version control
Code formatting matters. Even indentation matters. And consistency is more important than minor improvements. But projects usually don't have a clear, complete, verifiable and enforced style guide ...
2
votes
4answers
273 views
Create new variable or make multiple chained calls?
What is the best way to get this attributes, thinking in performance and code quality?
Using chained calls:
name = this.product.getStock().getItems().get(index).getName();
id = ...
8
votes
3answers
238 views
How to get feedback from the community on large chunks of code?
Code Review.SE is great when you need feedback on a precise, short piece of code.
But where to get similar feedback about the code itself when:
you have thousands of LOC,
don't have colleagues in ...
7
votes
3answers
1k views
When to use typedef?
I'm a bit confused about if and when I should use typedef in C++. I feel it's a balancing act between readability and clarity.
Here's a code sample without any typedefs:
int ...
1
vote
6answers
416 views
Setters or constructor for many variables? [duplicate]
Possible Duplicate:
Are there guidelines on how many parameters a function should accept?
I have got class with 30 variables (it is application form), so I wonder what is the best practice ...
7
votes
4answers
324 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 ...

