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

learn more… | top users | synonyms (1)

3
votes
2answers
142 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
249 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
76 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 ...
12
votes
2answers
470 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
132 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
92 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
133 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
136 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
47 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
54 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
32 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 ...
0
votes
2answers
55 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
118 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
226 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
41 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
74 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
100 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
241 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
115 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
338 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
70 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 ...
2
votes
2answers
167 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
329 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
58 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 ...
2
votes
3answers
149 views

What's the best way to retrieve a value and a status [closed]

Given that all else is equal, and there are no coding standards defining the best approach, what would be the recommended way in C++ to check that a value exists and return it if it does? For ...
0
votes
2answers
75 views

In which file types I should include the copyright header? [duplicate]

My manager told me to include 15 line copyright notice on top of every file. I am not sure whether I need to include in sql, xml, txt, documention, config files or even html templates. In which ...
8
votes
3answers
612 views

Do code style guides increase productivity? [duplicate]

Our team of 12 is currently considering implementing a style guide. The question came up if long term productivity benefits outweigh the short term productivity loss as everyone adapts. What has been ...
1
vote
1answer
46 views

Use a setStatus($arg) function or have separate enable() and disable() functions?

I've got two functions at the moment: suspendGroupsAndUsers($groupId){} enableGroupsAndUsers($groupId) {} But the difference between the two is one variable/string. Should I just have: ...
8
votes
3answers
581 views

Style guide for C++

Right now I am using Google C++ Style Guide in my C++ code and I was pretty happy with it. Recently I was told that this guide is very bad: it is used internally by Google (I knew that), is outdated, ...
7
votes
6answers
360 views

Should if/else statements be arranged by rareness of cases or difficulty of dealing with them?

In some code I'm writing right now, I have something like this: if (uncommon_condition) { do_something_simple(); } else { do(); something(); long(); and(); complicated(); } ...
0
votes
3answers
165 views

Javascript Naming Convention [closed]

I've been using Javascript for quite a while, but I've always ignored the common naming conventions that I see online (camelCase). I know it all depends on the developer's preference, but why camel ...
0
votes
1answer
120 views

Should the helper function in class be defined before the usage or after

I need to do the code review of fellow members. One of the member always defined the helper functions at the bottom and use them at top e,g class Sample { public function SendFile(){ file = ...
0
votes
4answers
283 views

Usage of magic strings/numbers [closed]

This is somewhat controversial topic, and I guess there is as many opinions as there are programmers. But for the sake of it, I want to know what are the common practices in business (or in your work ...
2
votes
4answers
650 views

DTOs matter on ASP.NET MVC JSON Action?

I recently came across an internal project where they were using DTOs throughout the solution, and when I sat down to implement a new MVC controller with a JSON REST endpoint I decided to use an ...
8
votes
4answers
444 views

Coding styles when using several disparate libraries

I am working on some C++ code that uses several libraries, including some C libraries, that all have different coding styles. It will be open sourced once it reaches a usable stage. Which would ...
1
vote
2answers
300 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
4answers
86 views

A metric to measure the cost of cut and paste programming

I'm hunting a metric to measure the cost of cut-and-paste programming. We already use tools to detect duplicated code - but if we don't clean up our duplicated code, how much will it cost us? We ...
0
votes
1answer
88 views

Which is preferred coding style to validate and return from a method [duplicate]

Which of the below is a preferred coding style (in c# .net) public void DoWork(Employee employee) { if(employee == null) return; if(!string.IsNullOrEmpty(employee.Name)) return; // Do ...
55
votes
7answers
3k views

Should you always pass the bare minimum data needed into a function

Let's say I have a function IsAdmin that checks whether a user is an admin. Let's also say that the admin checking is done by matching user id, name and password against some sort of rule (not ...
3
votes
6answers
844 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 ...
1
vote
2answers
97 views

Coding convention question about AS3 duplicate variable definition

AS3's got some awkward rules about variable scope, due to its use of hoisting. I don't like pointlessly leaving a bunch of compiler warnings lying around, but it's more important to me for my code to ...
0
votes
2answers
460 views

Good or bad code? Or “a secret reason”?

I think this code: if(file_exists("amodule.inc.php")) require_once("amodule.inc.php"); is misleading because of the use of the require_once. I think that - to keep the logic and "wording" ...
-1
votes
2answers
420 views

Interview Coding Assignments… how much do they account for? [closed]

So I've ran into a couple of companies that requires completing coding assignments before they give you a phone interview. I'm curious, do these coding assignments account for anything after the ...
0
votes
0answers
46 views

Boolean condition before variable [duplicate]

I have noticed this style from time to time: if ( 0 == myVar ) Rather than: if ( myVar == 0 ) Is this just the individual programmers idiom? A defensive programming style? Does anyone know if it ...
1
vote
2answers
212 views

Arguments for conforming to PSR-2

I am trying to convince the lead developer of an open-source project I'm contributing to, to conform to the PSR standards (PSR-2 in particular) created by the PHP Framework Interop Group. He is ...
16
votes
12answers
2k views

Correct comment to put for boolean function arguments that are “false”?

From some open source projects, I gathered the following coding style void someFunction(bool forget); void ourFunction() { someFunction(false /* forget */); } I always have doubt about what ...