Coding style is a set of guidelines that helps readability and understanding of the source code.

learn more… | top users | synonyms (1)

2
votes
9answers
274 views

Is too much whitespace a bad thing?

I'm often told by my friends and colleagues that I use way to much whitespace. I guess I do use a little too much whitespace. I often add a line break almost after every line and large blocks of ...
-2
votes
3answers
172 views

Is there an official programming format? [on hold]

A person can make their code readable and neat in their own way. However, is there a standard programming format that professional programmers are compliant to?
1
vote
1answer
92 views

Object Chain through an Interface

Say I have 3+ types of objects: function Sea() { var logs = [Logs]; this.getLog = function(ind){return logs[ind]} } function Log() { var bumps = [Bumps]; this.getBump = ...
3
votes
4answers
209 views

Improve coding quality

I have been dealing with programming for several years now (I am still a student but with a lot of internships). Mostly working with C++, Python and MATLAB, I noticed that whenever I download an SDK ...
3
votes
1answer
153 views

How reduce the usage of Magic Strings?

In the application database there is a configuration table with this schema: Table: ReleaseProperty ReleasePropertyID ReleaseID Name Value Currently to retrieve a specific property I pass to the ...
5
votes
3answers
370 views

Refactoring previous intern's noodle code with future interns in mind

Background I've run across this problem as I am currently an intern at a large company's local software division. I have been given the task of extending a project that several previous interns have ...
0
votes
1answer
57 views

Loading dynamic css based on user

I want to provide different UI theme based on user who logged in. For that I have came up with following 2 options: create separate files for all themes duplicating all the common css. This way I ...
2
votes
2answers
104 views

Should special (simpler) cases have separate code paths?

I have a rather complex method which can get called in two possible "scenarios". One is a special case of the other in which all the nested foreach loops are only executed once and several if ...
6
votes
1answer
235 views

How to manage a relatively large one-man project? [duplicate]

I am basically working on https://github.com/KirisurfProject/ entirely alone. This is around 4000 lines of Go code, plus around 1000 lines of Racket (a Lisp) code for the GUI part; the equivalent in ...
1
vote
2answers
56 views

Alias variable vs multiple use of getter

Would you rather: $this->getDoctrine()->getManager()->persist($currency); $this->getDoctrine()->getManager()->persist($user); $this->getDoctrine()->getManager()->flush(); ...
2
votes
1answer
125 views

Is serialization better done in instance methods or static methods

Say I have a class workStockItem, that I wish to serialize. Which is the better style? using a static method or using a non-static method (maybe even implemented as a property as seen below) ...
3
votes
3answers
156 views

Organization of DLL linked functions

This is a code organization question. I got my basic code working but when I expand it, it will be terrible. I have a DLL which I don't have a .lib for. Therefore I have to use the whole ...
1
vote
1answer
86 views

Is there an easy way to type in common math symbols?

Disclaimer: I'm sure someone is going to moan about easy-of-use, for the purpose of this question consider readability to be the only factor that matters So I found this site that converts to easting ...
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 && ...
1
vote
3answers
128 views

Use unnamed object to invoke method or not?

If I have a class with only only public method. When I use this class, is it good to use unnamed object to invoke its method? normal: TaxFileParser tax_parser(tax_file_name); auto content = ...
2
votes
4answers
130 views

Should our team order Javascript class methods/properties consistently? If so, how?

As our team is growing I've noticed that different developers put their class methods in different orders. For instance: var Foo = Backbone.Model.extend({ someVar: {}, initialize: ...
31
votes
3answers
873 views

Origins of code indentation

I am interested in finding out who introduced code indentation, as well as when and where it was introduced. It seems so critical to code comprehension, but it was not universal. Most Fortran and ...
-1
votes
1answer
245 views

_variable - why that underscore at the beginning? [closed]

Sometimes I see people writing variable names like this: int _variable; IMO That's really ugly. What's that about?
3
votes
4answers
482 views

Is lack of whitespace a sign of a cargo cult programmer? [closed]

Eric Lippert has written about cargo cult programming, and Steve McConnell has tackled the subject from a Software Engineering point of view. Eric provides a fairly succinct description: They ...
2
votes
4answers
843 views

Identify this programming style

Some of the legacy code I've inherited uses the fact that C# supports multiple assignment to write code like: void DisableControls() { ddlStore.Enabled = ddlProgram.Enabled ...
0
votes
2answers
273 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 ...
1
vote
2answers
169 views

Objective-C style: Do I implement factory methods or init methods?

I'm new to Objective-C programming, and creating various classes for an iOS application I'm working on. When creating objects, it seems like many classes in the built-in frameworks use the "static ...
4
votes
2answers
210 views

Using a closure to avoid code duplication in Python

Sometimes I find myself wanting to run the same code from a few different spots in the same function. Say I have some function func1, and I want to do the same thing from a few different spots in ...
1
vote
4answers
500 views

What is “using namespace” pollution?

I was looking at the google coding guide [here] and they do not recommend that one use the using namespace ornamespace:function` - if I did not misinterpret it. Does this apply to std as well? ...
2
votes
1answer
88 views

equivalence in callback and non-callback javascript

I'm pretty sure that the following two snippets are equivalent but I wanted to double check: CALLBACK STYLE function foo(input, callback) { // do stuff with input callback(); } function ...
14
votes
2answers
539 views

Creating nested functions for purely aesthetic reasons?

I've always wondered what other programmers think about the idea of creating pure aesthetic functions. Say I have a function that processes a chunk of data: Function ProcessBigData. Say I need ...
-2
votes
6answers
224 views

What is the coding standard for a long parameter list? [closed]

I am trying to code a constructor and the class needs a few variables to get it running. This method creates a log file containing a subset of a source file's entries based on a key and possible ...
-2
votes
1answer
109 views

Is there a named antipattern for unclear API not exposing the requirements? [closed]

In the source code I'm evaluating (jarjar), there exists java code that can be used like this: JarJarTask fixture = new JarJarTask(); fixture.addConfiguredRule(new Rule()); fixture.execute(); Which ...
1
vote
1answer
255 views

How to break these long C++ lines in a neat way? [closed]

I'm on my first bigger C++ project and find that I have some really long lines. My goal is to break them to 79 columns, but I do not really know how to do this in a neat way. Are there some guidelines ...
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 ...
35
votes
14answers
5k views

How important is it to clean up someone else's code when faced with a tight deadline? [closed]

(I'm talking about HTML / CSS code (not programming languages) but I think we also face the same issue as with programmers.) I am the senior front-end designer in a team and I often have to re-work ...
-1
votes
3answers
182 views

Should I always use “is” as prefix for boolean variables? [closed]

Should I always use is as prefix for boolean variables? What about booleans that indicate something in past? Should I write isInitialized or wasInitialized? Should I write for properties IsManyMembers ...
16
votes
5answers
2k views

How can you decompose a constructor?

Lets say I have a Enemy class, and the constructor would look something like: public Enemy(String name, float width, float height, Vector2 position, float speed, int maxHp, int ...
0
votes
0answers
58 views

Check some value between each function call

Can you recommend a nice way of checking a particular value between calls to a set of functions? E.g. something like this in Python (might not be terribly 'Pythonic'): self.error_code = 0 # this ...
0
votes
1answer
61 views

Preferred Scala code style for several embedded brace sets

I was wondering the correct way to format a situation such as this, where I have a def, a foreach and an if clause all nested, requiring braces. Currently I find it hard to read, and there is no ...
0
votes
1answer
42 views

How using tab affects commands like diff

In the page at http://pear.php.net/manual/en/standards.indenting.php, it is advised to use space instead of tab as it causes issue with diff, patches. Here is the excerpt from the page. Use an ...
1
vote
3answers
155 views

Accepting a numerical range in a function call

I have encountered two ways of doing it: void foo(int from, int to); /* 'from' inclusive, 'to' exclusive */ void foo(int startIndex, int rangelength); Has one style historically been preferred ...
1
vote
2answers
124 views

Approach to coding algorithms to minimize rework [closed]

I find myself reworking my code quite a bit, especially when learning to write algorithms that involve keeping track of multiple attributes and labels. I feel that having the pseudo-code written up, ...
-4
votes
2answers
266 views

How to really understand programming? [duplicate]

I have started to learn to program. I am interested in it and dont mind how long it takes to learn. But I am using books to start out and I find that there are some things I get and some things I have ...
2
votes
1answer
51 views

When should I pass setting-like value as class' variable and when as an assoc. array?

Following my other question, is there a general rule of thumb, when we should pass a setting-like value, that controls class' behavior (for example displayed texts) as as class' constant or variable, ...
1
vote
1answer
87 views

When should I pass value as class variable and when as a method argument?

Is there a general rule of thumb, when we should pass a value as as class variable and when as a method argument? Or is it just a choice of the developer? For example -- are there any reasons, why ...
0
votes
3answers
104 views

Long vs short scripts? Big vs small scripts? [closed]

As a programmer, I have always wondered whether it is preferable to write (a) short modular functions that are each stored in their own script (i.e., file) or (b) long comprehensive scripts that ...
-1
votes
4answers
246 views

(Is there | Why isn't there) a programming language that allows 'inline' arguments to a function? [duplicate]

What is the reason for 'trailing' arguments to functions in most programming languages? That is, we do something like this: def subtract(x, y): return x - y subtract(10, 5) ...rather than the ...
2
votes
1answer
127 views

How far to go when standardizing code [duplicate]

My small team and I have created a decent sized web application (~50k lines), with a fully featured API, all in Perl. As us perl hackers know.. it is easy to get sloppy. We had to port over a lot of ...
5
votes
4answers
378 views

Communicate to a junior developer about bad style

I have a friend who's managed to pick up comma first (best case might be made here: http://ajaxian.com/archives/is-there-something-to-the-crazy-comma-first-style) but it's 100% against our org's style ...
32
votes
11answers
4k views

Is it okay to make coding style changes on an open source project that doesn't follow best practices?

Recently, I came across a number of open source Ruby (or majority of it was Ruby) projects on GitHub that when checked with a code analyzing tool like Rubocop, create a lot of offenses. Now, most of ...
1
vote
2answers
84 views

Creating a large quantity of types VS using mostly the ones provided by the language [closed]

There are several times where you're coding a method which has two parameters with the same type, lets say, integers, NumberOfUnitA and NumberOfUnitB. Given that we're coding in a language that ...
3
votes
2answers
256 views

using unsigned integers in c, c++

I have a very simple question that baffles me for a long time. I am dealing with networks and databases so a lot of data I am dealing with are 32-bit and 64-bit counters (unsigned), 32-bit and 64-bit ...
2
votes
3answers
340 views

To store data or not?

I'd like to ask you about one simple thing. I have class A that do something (for example counts something ). There is also one class B that handle some parameters to this class (class A is member of ...
0
votes
2answers
105 views

Overloading Methods With Different Behavior - Style

I have a style question about overloading methods/constructors. I have a constructor which does something very simple, and then calls a method with some side effects. Sometimes however I don't want ...