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

learn more… | top users | synonyms (2)

0
votes
0answers
59 views

A Standard Coding Guideline [on hold]

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 ...
0
votes
0answers
40 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 ...
-5
votes
0answers
87 views

How did ATM machine “recognize” my father's handwriting on a check? [on hold]

I was at the ATM the other day and I deposited a check that was hand-written from my father. The check was for $100. After I inserted the check, the ATM knew it was for $100, without me even entering ...
4
votes
3answers
203 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
217 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 ...
23
votes
5answers
2k views

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

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
61 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
88 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
136 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
427 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
84 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
111 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
170 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
62 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
63 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
218 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
209 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
32 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
183 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
125 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
224 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
88 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
81 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
94 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
78 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
110 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
197 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
79 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
202 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
187 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
45 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
142 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
91 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
26 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
80 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
188 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
252 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
105 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
129 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 ...
0
votes
2answers
287 views

Is it ok to break the “is a” relationship if I just want part of a class' functionality?

I asked a question about extending TreeMaps into "sort by value" TreeMaps on the "code review" site on stackoverflow. Based on the response, I re-wrote the code. I like it. But, it feels like I might ...
0
votes
0answers
58 views

Ordering of methods in class [duplicate]

How do you order the methods in your classes? I am aware of the alphabetical approach and the telling a story approach and so far I prefer the story approach, but how do you handle private/helper ...
8
votes
7answers
1k views

what should be logger's position in the parameter list [closed]

In my code I inject a logger to many of my classes through their constructor's parameter list I noticed that I put it randomly: sometimes it's the first on the list, sometimes last, and sometimes in ...