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

learn more… | top users | synonyms (1)

8
votes
6answers
976 views

Should my team use some common well-regarded coding standard as a basis for its own?

The R&D team I'm in has decided to adopt a coding standard. We have only recently formed, and have too little code and common coding time of our own to base our standards/conventions document on ...
5
votes
4answers
535 views

How can I stop myself overwriting member variables with 'new' ones?

The bulk of my programming experience has been with C++ and (shudder) FORTRAN (I'm a scientist not a programmer as such, but I do my best). I've recently started using python extensively and find it ...
44
votes
3answers
1k views

Coding Style for Visually Impaired Programmer

I am visually impaired. With glasses I see well enough to drive, but at the font size I'm comfortable working at I can only see about 15 lines of 100 characters at a time. This has affected my ...
3
votes
3answers
599 views

Avoiding boilerplate in PHP classes

I am working on a PHP code and as it grows getting more and more tired of repeating the same standard pattern again and again and again: class BolerPlate { protected $property1; protected ...
0
votes
2answers
569 views

What is the exact syntax of inline?

CASE 1 (Definition and declaration in same source file) Suppose both my prototype and definition of global function is in .cpp file. Where should I write inline keyword to make compiler know? In ...
1
vote
2answers
306 views

How much functional programming expertise can programmers be expected to have? [closed]

I'm coding in a non-functional language with functional mechanisms (C# to be specific, but you could substitute, say C++ and use function pointers, or what have you) on a small team. It's my habit to ...
2
votes
1answer
361 views

Maintaining code-style conventions for large projects [closed]

For a while I've been maintaining an ad-hoc script to check code style against our project's guidelines. I'm aware of AStyle/Uncrustify and have used them, but they are best for once-off code-style ...
2
votes
3answers
277 views

Should I make a variable readonly when I modify it, but I don't actually set it outside of the constructor?

Background: I was writing some code. It looked something like this: class X { private List<int> _myList = new List<int>(); public void MyMethod(int x) { ...
5
votes
2answers
843 views

C++11 Header-only Library: in-class body vs. out-class body code?

BACKGROUND:optional Since 2002 I've been slowly building my own Windows Native C++ library. And let's just say that I have jumped 150KLOC (reusable code) having everything I need and the kitchen sink ...
4
votes
6answers
3k views

Clarification of “avoid if-else” advice [duplicate]

The experts in clean code advise not to use if/else since it's creating an unreadable code. They suggest rather using IF and not to wait till the end of a method without real need. Now, this if/else ...
0
votes
1answer
271 views

How to format this line according to PEP 8? [closed]

I'm trying to adhere to PEP 8, with a 78 character limit on the length of my lines. I have the following statement: startTime = time.strptime(request.GET.get('st', (dt.datetime.now() - ...
6
votes
3answers
297 views

Is there any situation in which it would be appropriate to use unless… else?

This construction is considered wrong unless #.. else #.. end This is for the general reason of double-negative confusions. It translates to: if not #.. if not not #.. end We all agree ...
2
votes
4answers
644 views

Coding convention regarding the usage of underscores [closed]

There seems to be divided opinion on this subject, and I wanted to get people's insights on whether they've found using underscore prefixes and suffixes to be helpful with coding or not. You know, ...
2
votes
2answers
1k views

Should I use semicolons to delimit Scala statements?

I'm used to delimit statements by a semicolon from Java, so naturally I do it in Scala code too. I also feel that the code is easier to read, because it's evident where one statement ends and another ...
3
votes
3answers
360 views

Blank lines in C

I'm working through K&R and I notice that their code is extremely tightly spaced. I haven't developed C since at University, but professionally most source from other languages I've worked in has ...
3
votes
2answers
255 views

How can I keep current with Python coding style?

I've been using Python since version 2.2. I do pick up new language constructs like for example with statement or dictionary/set comprehensions. However, I've realized that even though I'm being ...
4
votes
3answers
292 views

Placeholders in strings

I find that I sometimes use placeholders in strings, like this: $ cat example-apache <VirtualHost *:80> ServerName ##DOMAIN_NAME## ServerAlias www.##DOMAIN_NAME## DocumentRoot ...
0
votes
3answers
177 views

which style of member-access is preferable [duplicate]

the purpose of oop using classes is to encapsulate members from the outer space. i always read that accessing members should be done by methods. for example: template<typename T> class foo_1 { ...
3
votes
3answers
1k views

articles in variable names and hard-coding strings

re-edited by author: no this is not 2 questions. This is one question about code review questions containing two separate points. Please do not edit my question. For naming variables, the two sides ...
5
votes
3answers
417 views

Coding Convention: C++ Header/Interface Files

I'm reading through a PDF on C++ programming from this page on Stanford's site. It says that when you're creating a C++ header file for a library interface, use a #ifndef preprocessor command to make ...
2
votes
4answers
177 views

function exit condition on parameter consistency check [duplicate]

When checking for parameter consistency a the top of a function body, what is the best strategy? This one: protected void function(Object parameter) if (parameter == null) return; ...
62
votes
15answers
6k views

Should I use parentheses in logical statements even where not necessary?

Let's say I have a boolean condition a AND b OR c AND d and I'm using a language where AND has a higher order of operation precedent than OR. I could write this line of code: If (a AND b) OR (c AND ...
4
votes
6answers
3k views

sizeof style: sizeof(type) or sizeof variable?

I've seen two styles of using sizeof for memory-related operations (such as in memset or malloc): sizeof(type), and sizeof variable or sizeof(variable) Which one would you prefer, or would you use ...
7
votes
3answers
796 views

Reason for placing function type and method name on different lines in C

I just started at a company and one of the style comments at my first code review was that the return type and method name should be on different lines. For example, this void foo() { } should be ...
6
votes
3answers
474 views

Is the usage of internal scope blocks within a function bad style?

There are some (quite rare) cases where there is a risk of: reusing a variable which is not intended to be reused (see example 1), or using a variable instead of another, semantically close (see ...
2
votes
4answers
327 views

How do you decide what code to put into a function?

I started out with a script that was a few hundred lines. Later, I realized I wanted another script that would require much of the same code. I decided to wrap certain areas of the original script ...
33
votes
13answers
6k views

In languages that don't allow underscores in integer constants, is it a good practice to create a constant for 1 billion?

In languages that don't allow underscores in integer literals, is it a good idea to create a constant for 1 billion? e.g. in C++: size_t ONE_BILLION = 1000000000; Certainly, we shouldn't create ...
1
vote
2answers
162 views

Is repeating links to the same class in a single javadoc comment a bad practice?

I'm currently writing an API and its documentation. For example I have something like this: public interface Event { } public interface Process { } public interface EventProcessor { /** * ...
15
votes
7answers
1k views

Should I write compact code or code with lots of spaces? [duplicate]

I have two friends that have completely different schools of thought on how to lay out their code. The first says that code should be well-indented and use lots of spaces and to name variables ...
3
votes
7answers
1k views

Ensuring that headers are explicitly included in CPP file

I think it's generally good practice to #include the header for any types used in a CPP file, regardless of what is already included via the HPP file. So I might #include <string> in both my HPP ...
1
vote
5answers
250 views

Is it a good practice to write a method that gets something and checks the value? [duplicate]

Occassinally I have to write methods like this: string GetReportOutputDirectoryAndMakeSureExist() { string path = Path.Combine ( ... ) //whatever logic if(!Directory.Exists(path)) ...
3
votes
5answers
2k views

Programming Style in Large Scale C++ Applications

Recently I've been browsing source code of large applications written in C++ to learn a bit but I couldn't help but notice that most if not all use a lot of IFDEFs and class-less functions (where they ...
10
votes
5answers
1k views

What are the downsides of mixing tabs and spaces? [duplicate]

The advantage of using tabs for indentation is that people can configure their editor to use the tab width they are comfortable with. The only argument against this seems to be that people don't want ...
1
vote
3answers
370 views

Code Base with awful code conventions, follow them?

With no time to refactor, when you are working on legacy code, with the most awful conventions, what is the best practice? Will trying to follow better coding style would improve readability or ...
8
votes
2answers
847 views

What does Uncle Bob mean by 'noun phrase names'?

I am reading Clean Code by Uncle Bob. Because I am not a native-English speaker, I couldn't understand following statement: Classes and objects should have noun or noun phrase names like ...
3
votes
3answers
1k views

When are chained assignments (i.e. a=b=c) bad form?

I'm working on a VB.Net WinForms project and found myself writing code like this: this.Fizz.Enabled = this.Buzz.Enabled = someCondition; I couldn't decide whether that was bad code or not. Are ...
2
votes
2answers
221 views

Helper Methods Placement [duplicate]

Here's a question that's always bugged me. I'm going to use java as an example because I've almost never run into a problem in java where I didn't need to use helper methods in its class structure. ...
43
votes
12answers
3k views

Coding style (do more, then simplify) [duplicate]

I'm a CS student and I have been coding for a few months shy of a year now, and I seem to have developed what I think may be a "bad" habit and I'm wondering if anyone does the same (or whether it's a ...
3
votes
2answers
484 views

Programming by Intention, Depth-First or Breadth-First?

Say I have the following graph of dependencies between procedures/functions/methods: o / \ v e / \ / \ r f l w That is, function o first calls function v, and then ...
6
votes
3answers
332 views

Dynamic typing function arguments - how to keep readability high?

Dynamic typing newbie here, hoping for some wizened words of wisdom. I'm curious if there is a set of best practices out there for dealing with function arguments (and let's be honest, variables in ...
2
votes
4answers
8k views

Forward declaration vs include

Reduce the number of #include files in header files. It will reduce build times. Instead, put include files in source code files and use forward declarations in header files. I read this in here. ...
1
vote
1answer
132 views

Less code or less operation

Sometimes I hesitate between "More code to avoid unnecessary operations" and "less code but with redundant operations". Let me just take an example (Win32 API): I try to paint some controls manually ...
0
votes
2answers
1k views

unique_ptr and references - coding style question

I'm pretty sure this is a question purely about aesthetics but I wanted to get all your opinions on it before I start proliferating this type of code in my codebase. Consider the following code: ...
5
votes
2answers
269 views

Is it OK to have a method return different types based on a parameter?

I'm looking for a reference to clean coding styles that I can pass to a team member. In particular, the rule that a method should not change its return type based on an input parameter. If you need ...
8
votes
6answers
1k views

Should my code be DRY or readable if it can't be both?

I'm writing Ruby code for a simple encryption exercise and have frequently run across this dilemma (the exercise is a solitaire cipher if you must know). It is a question of whether I should pad out ...
2
votes
2answers
310 views

Choosing between words with different spellings for function names

A question has been bothering me for a while: when developing international projects, it is common sense to use English as the reference language since it is the language that the most people ...
3
votes
2answers
344 views

Are there standard style guides for PHP?

I've been working in a very small team for PHP development and we've been using an ad-hoc, "Invented Here" style guide. Now that our team and codebase is growing, we would like to use a more ...
2
votes
4answers
3k views

Microsoft's coding standards for ASP.NET controls

I cannot find any naming standards/conventions in MSDN for naming ASP.NET controls. One of the following standards tends to be used by programmers: lblAddress AddressLabel Address According to ...
2
votes
4answers
2k views

Is using `continue`, `break` in non-`switch` loops and `?:` bad practice? [duplicate]

Back in college I've been told that using break; and continue; outside switch statements (e.g. to escape for or while loops) is wrong, bad practice and bad habits at the same time because it only ...
6
votes
3answers
957 views

Is relying on implicit argument conversion considered dangerous?

C++ has a feature (I cannot figure out the proper name of it), that automatically calls matching constructors of parameter types if the argument types are not the expected ones. A very basic example ...