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

learn more… | top users | synonyms (2)

14
votes
1answer
305 views

What is the term for an anonymous JavaScript function that's called immediately?

I'm writing a JavaScript style-guide for my team, so that we can organise and contribute our documents easier. But I've hit a small bump which is where my question applies... What am I supposed to ...
38
votes
7answers
3k views

TODOs in Checked in Code [on hold]

I have been having a debate on this with people in my team over the past few weeks. Some in my team are against having TODOs checked into the source code of our project. Their reasoning is that a ...
0
votes
1answer
54 views

In *nix, is there a practice for storing static libraries?

Lets say you are building an application that staticly links against libraries that you provide it. Where should you store these static libraries? Should you make a directory in the parent directory ...
31
votes
8answers
5k views

How to work with programmer with different preference of indentation width? [closed]

I personally prefer 4 spaces for each indentation level, but there are colleagues that prefer 2 and even 5 spaces. We can of course use the same spaces level, but is there a way we can uses different ...
0
votes
0answers
64 views

A Standard Coding Guideline [closed]

I have been programming in C, C++ and a few other languages for more then 15 years and been switching companies over that time. I have faced one constant problem, that being the requirement for a ...
1
vote
0answers
55 views

Pointers vs IDs for “context-specific” functions

I need to be able to load, use, and free resources from a single monolithic object. I have two requirements: 1. That the resource loaded is owned by the object that created it and 2. All objects in a ...
4
votes
3answers
211 views

Creating a Java project without using any objects and just calling static methods on input?

I'm creating a program which takes a document, extracts it, and then moves this into a database. I've done most of this now and I've realised that I haven't made any instances of classes I've made (I ...
0
votes
1answer
223 views

Is writing code chronologically the best way for readability? [closed]

So I've been writing a lot of JavaScript lately. Despite what many people say I think JavaScript can be a simple and beautiful language. What I've pondered of late is how to structure the code so it ...
27
votes
5answers
2k views

Should I initialize C structs via parameter, or by return value? [closed]

The company I work at is initializing all of their data structures through an initialize function like so: //the structure typedef struct{ int a,b,c; } Foo; //the initialize function ...
2
votes
0answers
47 views

Should the order of definitions correspond to the order of declarations in header/source files? [closed]

If my header looks like this: class foo { public: foo(); ~foo(); QString b(); QString c(); QString a(); void setB(QString s); void setC(QString s); void ...
8
votes
6answers
3k views

How to reduce a switch in a switch statement?

So I'm making a method to create a salutation line based on two people from a database. There are four parameters: the two names (name1 and name2) and the two genders (gender and gender2). For every ...
1
vote
1answer
62 views

Best place to declare functions in this example

Suppose I have code that accepts html GET requests: server.get('path/to/some/endpoint', function(req,res) { function a() { //function goes here } } Is it better to declare functions ...
3
votes
1answer
62 views

What is more pythonic - subclassing dict or creating external functions to manipulate them?

Say I have a dictionary that contains complex classes that need to be loaded and unloaded in a special way. (Not especially special, just outside the bounds of this question.) Should I gracefully ...
-1
votes
1answer
94 views

Right-aligning code

I recently was looking for a CSS solution to vertically-align elements, and I found one here. One thing that I thought was nice was the right-justified code; example: .vertical-center { // ... ...
2
votes
1answer
139 views

Does applying a prefix to member variables make sense in C? [closed]

//C code struct Foo{ int m_nVar; } struct Foo f; f.m_nVar = 0; Despite the fact that many consider Hungarian Notation an anti-pattern, I am working in a code base that enforces it. 90% ...
0
votes
3answers
430 views

When to use single-line if statements? [closed]

When reviewing code, I prefer to read if statements that explicitly demonstrate that a fork in code execution may occur: if ( isFoo(baz) ) { runBar(); } When scanning hundreds of lines of the ...
2
votes
4answers
356 views

what is the difference between overengineering, underengineering and rightengineering? [closed]

What is the difference between over-engineering, under-engineering and right-engineering at coding/design perspective? I found over-engineering: Coding too much like doing future requirement code ...
0
votes
2answers
91 views

guideline on void methods that do not throw exceptions

In our codebase I saw a method that is similar to following: public void doSomething() { try { ... } catch (Exception e) { ... //log something ... } } ...
2
votes
1answer
116 views

Async library guidance

I'm creating a library that contains a class that exposes several Async methods: public class MyClass { public async Task<Foo> DoFooAsync() { /*...*/ } public async Task<Bar> ...
4
votes
4answers
171 views

Using a one-shot class to store not-quite-global variables

I sometimes find myself writing classes (in Python, in my case) that are used like this: MyClass(some_args).go() In other words, there's only one method in the class that any external code would ...
1
vote
2answers
65 views

Use of “this” in Golang

On the closest thing Golang has to a style guide found here, under Receiver Names this is written: The name of a method's receiver should be a reflection of its identity; often a one or two letter ...
-1
votes
2answers
65 views

python code style for long lists [closed]

when coding a very long list in python, is it better to fit several items on each line or should I limit it to 1 per line? 99% of the time I would go with style2 below but I have 5 lists each about ...
0
votes
2answers
220 views

Way to organize repetitive text in Java

Some times I have texts that appears in different places, like comments, messages... For example if I have a custom Exception, probably class doc, messages that passes as parameter to its constructor ...
6
votes
3answers
213 views

Member: Use unique IDs vs domain object

After a couple of useful answers on whether I should use domain object or a unique id as method/function parameter here Identifier vs domain object as a method parameter , I have a similar question ...
0
votes
0answers
33 views

Defensive Programming - “Return” placement [duplicate]

Sometimes I see myself writing code in the following way: if(value == null) return null; //... I will have here as many defensive conditions (and returns) as I need //... Continue to execute method ...
5
votes
2answers
186 views

Is there a name for the anti-pattern of having low-level components controlling higher-level ones?

For example, suppose I had a pageControl UI class and a searcher business logic class with the following : pageControl.js function searchButtonClicked() { // call business logic class method when ...
1
vote
2answers
134 views

Non-printable characters and editors

Today I was presented with a very nasty problem and I do not quite know where to ask this but hope here is ok. So I have the following string: "\0" (at least that's how it looks in visual studio). If ...
3
votes
4answers
227 views

Function wrappers with no args: bad practice?

My colleague likes to write classes containing methods looking like this: public function doTaskA() { return $this->doTask('A'); } public function doTaskB() { return $this->doTask('B'); ...
1
vote
4answers
90 views

Use the company style guide or try to match the incorrect source files? [duplicate]

I'm currently working on a large project in C++. The style guide for this language has been well defined by my company and is available for everyone to see. This particular code-base is being ...
5
votes
2answers
129 views

Identifier vs domain object as a method parameter

Are there any objective arguments for or against using objects vs unique ID as method/function parameters? (and members of other objects?). Specially in the context of statically typed languages ...
0
votes
0answers
82 views

Addicted to Interfaces - Good or bad? [duplicate]

After 2 years of programming, I usually found myself using the following design pattern: public interface ISomeInterface { void SomeMethod(); void OtherMethod(); } public abstract class ...
2
votes
4answers
68 views

If I have a method that needs verification in order to proceed, do I call it inside the method or before? [duplicate]

This has been bothering me. This is more of a pragmatic problem than technical. Imagine I have a SaveOrderChanges method which, as its name implies, will save the order changes when the user submits ...
1
vote
1answer
97 views

When the result set doesn't matter should Left Join or Inner Join be used

When you have a query where you're joining from a non-null foreign key to the foreign table it doesn't matter if you use LEFT JOIN or INNER JOIN from a result standpoint (since there won't be any ...
0
votes
2answers
79 views

Getters with data conversion in Java VOs

I am working on a standard Spring application where DAO layer returns entities to service layer and service layer returns VOs to other services and controllers. In a certain scenario, we have a VO ...
5
votes
2answers
113 views

What is a reasonable level of detail for a style guide? [closed]

We are developing embedded software for an automotive product in ANSI-C in a large team. Yesterday, in our regular code review, we had a general discussion about the style of our code. We have a ...
1
vote
3answers
198 views

Using prefix/postfix increment operator for simple incremental array access rather than actual index numbers

I cannot decide which method is better with consideration of both readability and fault-tolerance. Method #1: Object[] objects = getArrayOfKnownLength(); int i = -1; someMethod(objects[++i], ...
-2
votes
1answer
83 views

How to name variables without plural in a for-each loop? [closed]

How do you name loop variables when the list item is named after something without a plural? For instance (in python): [x for x in sheep]. x is not a great name, but sheep have/has no plural that ...
0
votes
3answers
247 views

What arguments are there to use a coding style for each distinct language? [duplicate]

I recently had a discussion about our coding style for C# projects. Two things in particular were very hard to agree upon. Method Naming C# has the de-facto standard of naming (at least public, ...
0
votes
3answers
205 views

Is there a use for non-const reference parameters?

Given a function like: void do_stuff( Thing & thing ) { // at this point, I can inadvertently or purposefully change thing } Is there a reason to purposefully change thing? Changing thing ...
8
votes
1answer
189 views

Why create a Global-ish Object.create function?

I'm a fairly experienced programmer in the .NET and Java realms, and I've started reading up on JavaScript. I bought Douglas Crockford's "The Good Parts" book, and I'm immediately put off by a few ...
0
votes
0answers
47 views

Using regions in C# applications [duplicate]

What is cons and pros using #region - #endregion tags in a C# application? Generally people are asking as disadvantages of using #regions. But I am asking if there is some advantages of #regions. I ...
0
votes
2answers
143 views

Style question: To use overloaded version or not?

Let's say I had an operator() overload that made temp_.matrix[k][j] and temp_(k+1, j+1) equivalent. In my class functions (where matrix belongs), would it be better to have if (temp_.matrix[k][j] == ...
2
votes
1answer
92 views

Should I consider uncertain future requirement while development? [duplicate]

I have one text box across multiple pages which is used to enter multiple customerids (as comma separated) . But in current page due to some subsequent implementation difficulties we make it as ...
0
votes
0answers
27 views

Using self.method vs the scope :method DSL

According to the Thoughbot Rails Style Guide, we should Use def self.method, not the scope :method DSL. My question is: is this simply for the sake of choosing one of these styles and sticking ...
0
votes
3answers
76 views

Handling source code table alignment

Sometimes there is need to have tables (big or small) in source code. ItemType const SomeTable[] = { // id name min max ITEM( 3, "Foo", 70, 180), ITEM(13, "Bar", 30, 50), ...
1
vote
1answer
81 views

Objective-c anonymous property coding style

If I have an interface defined like @interface MyClass @property (nonatomic, copy, readonly) NSString *myString; @end so that myString is externally visible but can't be written, what would be ...
1
vote
1answer
189 views

I have a particular coding style, does it have a name? [closed]

I don't know if it is just what my first Java lecturer taught me or if it is based on something. It has parts of it that are the same as the Oracle Java style (naming) but differs in other ways, as ...
1
vote
3answers
256 views

Alternative to goto-statement in this case? [duplicate]

Currently I am using gotos for closing handles and general cleanup if an error occurs. Since I don't want to nest all the ifs and a function for cleanup would require a return besides the cleanup(); ...
1
vote
1answer
106 views

Checking for valid state inside function or outside [closed]

This is a common occurrence in programming and is language agnostic, you have a function that needs to do something but in only in some cases. Maybe it's a feature-toggle, maybe it's a function that ...
-1
votes
1answer
132 views

Why does C++11 developers prefer space before colon in range-based for loops? [closed]

In most of the C++11 codes, I see: for (auto i : list) { // a space before colon ... } However, usually C++ developers do not prefer: for (int i = 0 ; i < list.size() ; ++i) { // spaces ...