Coding style is a set of guidelines that helps readability and understanding of the source code.
2
votes
1answer
143 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 ...
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 ...
2
votes
3answers
125 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 ...
-1
votes
2answers
182 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).
...
3
votes
6answers
865 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 ...
5
votes
4answers
332 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 ...
8
votes
4answers
361 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 ...
-5
votes
2answers
401 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?
11
votes
9answers
826 views
Should a programmer take writing lessons to enhance code expressiveness?
Given that programmers are authors and write code to express abstract thoughts and concepts, and good code should be read by other programmers without difficulties and misunderstandings, should a ...
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) ...
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 ...
17
votes
6answers
911 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
292 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;
...
7
votes
3answers
432 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 ...
2
votes
4answers
576 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 ...
1
vote
7answers
3k 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 ...
4
votes
6answers
330 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 ...
7
votes
5answers
475 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 ...
13
votes
2answers
3k views
What's wrong with relative imports in Python?
I recently upgraded versions of pylint, a popular Python style-checker.
It has gone ballistic throughout my code, pointing out places where I import modules in the same package, without specifying ...
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 ...
0
votes
2answers
637 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
802 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
258 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
451 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
242 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
759 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 ...
1
vote
3answers
224 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 ...
3
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 (""). ...
8
votes
5answers
409 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 ...
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 ...
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; ...
8
votes
3answers
242 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 ...
1
vote
6answers
436 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
331 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 ...
3
votes
3answers
514 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 ...
5
votes
4answers
1k views
Anonymous function vs. separate named function for initialization in jquery
We just had some controversial discussion and I would like to see your opinions on the issue:
Let's say we have some code that is used to initialize things when a page is loaded and it looks like ...
2
votes
4answers
276 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
2answers
290 views
How to deal with ad-hoc mindsets?
I joined a dev team of six two month ago. People are nice, all is good. But more and more I observe an ad-hoc mindset. Stuff gets quick fixed, at the cost of future usability, there is little testing ...
1
vote
4answers
368 views
Indenting labels in C
I noticed that in the Vim automatically indents labels in a rather unintuitive way (IMHO).
int main(void) {
goto end;
end:
return 0
}
Are there any style guidelines for labels?
For the ...
8
votes
5answers
433 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 ...
9
votes
4answers
1k views
How do you keep code with continuations/callbacks readable?
Summary: Are there some well-established best-practice patterns that I can follow to keep my code readable in spite of using asynchronous code and callbacks?
I'm using a JavaScript library that ...
10
votes
7answers
751 views
Are More Comments Better in High-Turnover Environments?
I was talking with a colleague today. We work on code for two different projects. In my case, I'm the only person working on my code; in her case, multiple people work on the same codebase, including ...
5
votes
3answers
282 views
Should I return iterators or more sophisticated objects?
Say I have a function that creates a list of objects. If I want to return an iterator, I'll have to return iter(a_list). Should I do this, or just return the list as it is? My motivation for returning ...
32
votes
8answers
1k views
When using method chaining, do I reuse the object or create one?
When using method chaining like:
var car = new Car().OfBrand(Brand.Ford).OfModel(12345).PaintedIn(Color.Silver).Create();
there may be two approaches:
Reuse the same object, like this:
public ...
2
votes
3answers
414 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 ...
46
votes
15answers
3k views
Working on someone else's code
I have hardly a year's experience in coding. After I started working, most of the time I would be working on someone else's code. Either adding new features over the existing ones or modifying the ...
52
votes
14answers
3k views
Is inconsistent formatting a sign of a sloppy programmer?
I understand that everyone has their own style of programming and that you should be able to read other people's styles and accept it for what it is. However, would one be considered a sloppy ...
1
vote
3answers
1k views
how to nicely use constant std::string in c++
In my current code project, there is an awful lot of constant strings I use to print out error messages.
Hardcoding such strings is generally considered to be bad practice.
Now I'm searching for a ...
3
votes
3answers
154 views
Style for control flow with validation checks
I find myself writing a lot of code like this:
int myFunction(Person* person) {
int personIsValid = !(person==NULL);
if (personIsValid) {
// do some stuff; might be lengthy
int myresult ...
6
votes
2answers
542 views
Is this awkward spacing some type of style?
In reading another programmers code, he uses a format I have never seen. E.G.
namespace MyNs.HereWeAre
{//tab here for some reason
public class SomeClass
...
