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

learn more… | top users | synonyms (1)

31
votes
12answers
2k views

Would a cut and paste coder ever get past a job interview?

As a long time cut and paste coder I never committed much of the syntax of a language to memory. Even worse, I now use google to solve many of the coding problems which are of the type typically used ...
17
votes
7answers
1k views

Should a function use premature returns or wrap everything in if clauses? [duplicate]

Possible Duplicate: Where did the notion of “one return only” come from? Which is better? I see pros and cons for both, so I can't really decide on which one to stick to. Wrap ...
1
vote
2answers
414 views

How to set up something like an integration server that measures the quality of code and reject the code if the score is below a certain number?

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 ...
26
votes
9answers
2k views

Scientific evidence that supports using long variable names instead of abbreviations?

Is there any scientific evidence that the human brain can read and understand fully written variable names better/faster than abbreviated ones? Like PersistenceManager persistenceManager; in ...
18
votes
5answers
885 views

Are there any scientifically rigorous studies of coding style principles?

Is a coding style principle - e.g. the single-exit principle - really a good thing? Always, or just sometimes? How much difference does it really make? Whatever your opinions, these are obviously ...
3
votes
2answers
342 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 ...
30
votes
11answers
2k views

Intentional misspellings to avoid reserved words

I often see code that include intentional misspellings of common words that for better or worse have become reserved words: klass or clazz for class: Class clazz = ThisClass.class kount for count in ...
26
votes
4answers
18k views

Why is #include <iostream.h> bad?

I was reading another thread where a guy asked about C++ books for beginners, and one of the programmers answering wrote this: Some warnings: avoid all books that present an "hello world" stating ...
16
votes
6answers
1k views

When should I use a 2-property class over a pre-built structure like a KeyValuePair?

When should you put Key/Value type of data in it's own class instead of using a pre-built generic structure, such as a KeyValuePair or a Tuple? For example, most ComboBoxes I create contain a ...
4
votes
2answers
414 views

Writing a style guide, what are the best examples for breaking long lines?

You are writing a style guide and you are at the chapter about breaking long lines. What would be the best examples of long lines to demonstrate your rules of breaking long lines. The examples ...
17
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 ...
15
votes
6answers
867 views

Do you write titles in code comments? [closed]

I was browsing some old code that I wrote (first year in the university) and noticed that I used to write comment titles preceeding various parts of the code. Stuff like (this is from a Monopoly ...
12
votes
5answers
570 views

Reformatting and version control

Code formatting matters. Even indentation matters. And consistency is more important than minor improvements. But projects usually don't have a clear, complete, verifiable and enforced style guide ...
11
votes
7answers
802 views

Are More Comments Better in High-Turnover Environments?

I was talking with a colleague today. We work on code for two different projects. In my case, I'm the only person working on my code; in her case, multiple people work on the same codebase, including ...
9
votes
1answer
757 views

Are there well-known PowerShell coding conventions?

Are there any well-defined conventions when programming in PowerShell? For example, in scripts which are to be maintained long-term, do we need to: Use the real cmdlet name or alias? Specify the ...
9
votes
4answers
451 views

How to avoid general names for abstract classes?

In general it's good to avoid words like "handle" or "process" as part of routine names and class names, unless you are dealing with (e.g.) file handles or (e.g.) unix processes. However abstract ...
8
votes
3answers
650 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 ...
8
votes
7answers
1k views

Why would an employer ask for a 'long' code sample?

What would a large project that spanned multiple files and >1000 lines show to an employer that a few individual files and a couple hundred lines couldn't capture?
8
votes
4answers
1k views

Is the use of explicit ' == true' comparison always bad? [duplicate]

Possible Duplicate: Make a big deal out of == true? I've been looking at a lot of code samples recently, and I keep noticing the use of... if( expression == true ) // do something... ...
8
votes
8answers
886 views

How would you feel if your code editor formatted your code for you as you typed, without tabs/spaces?

As with most things, I'm sure this concept has been tried before - I just haven't come across editors that use what I've termed 'Virtual Formatting'. The principle is that there's a floating ...
7
votes
9answers
2k views

Is it any good to use binary arithmetic in a C++ code like “C style”?

I like the fact that the C language lets you use binary arithmetic in an explicit way in your code, sometimes the use of the binary arithmetic can also give you a little edge in terms of performance; ...
7
votes
10answers
1k views

Single Line Statements & Good Practices

I have recently acquired a habit which I know many of you may frown upon, but which, in the end, helps me keeping an eye on global code structure rather than on the structure of a single, (sometimes) ...
4
votes
1answer
295 views

Is '@' Error Suppression a Valid Technique for Testing for an Optional Array Key?

Rarst and I were debating offline about the use of the '@' error suppression operator in PHP, specifically for use to test for existence of "optional" array keys, i.e. array keys that are being used ...
3
votes
2answers
451 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 ...
3
votes
1answer
393 views

Code Style for XAML

I started coding WPF applications a several months ago and now I am asking myself if there are some style guides for XAML. I do not need to get explained the benefits of Binding, Converters, Styles, ...
16
votes
15answers
2k views

I hate one of our coding standards and it drives me insane, how to process it? [closed]

Disclaimer: Not as exaggerated as the title suggests, but it still makes me uncomfortable. I'm just going to express honestly, so take it with a grain of salt. Just pretend that I'm talking about that ...
10
votes
5answers
554 views

Should coding standards be enforced by the continuous integration server?

Should coding standards/style be enforced by the continuous integration server running static analysis tools (ex. PMD, StyleCop/FxCop) and failing the build if the standards are not followed? What ...
10
votes
3answers
1k views

What is the pattern name for using method chaining to build an object?

I frequently use a pattern where I using method chaining to setup an object, similar to a Builder or Prototype pattern, but not creating new objects with each method call, instead modifying the ...
9
votes
4answers
1k views

C# return variables

In a debate regarding return variables, some members of the team prefer a method to return the result directly to the caller, whereas others prefer to declare a return variable that is then returned ...
8
votes
3answers
679 views

Should I nest functions in languages that allow me to do that or should I rather avoid it?

In JavaScript, PL/SQL and some other languages, functions can be nested, i.e. declared within another function. This could be used to break a large function into smaller pieces, but keep those pieces ...
8
votes
7answers
572 views

Commenting/In-Code Documentation Styles

This might be a stupid question, but it's been in the back of my head for a while and I can't find a decent answer anywhere else. I have a teacher who says we should explicitly list each parameter ...
7
votes
3answers
3k views

Should I use default access modifier or not — Coding practice?

Normally when creating new global variables I do not define its access modifier. So as per java it will adopt property default access modifier. When I'm need to access that variable in out of default ...
5
votes
8answers
2k views

What are the benefits of using comments

I just accepted a new job. Our application is in the 50,000 lines of code area. None of which is commented. I am finding it difficult to understand how the application works. Id like to prevent this ...
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 ...
3
votes
8answers
322 views

Avoid ELSE when setting a variable? [closed]

Which of these styles do people prefer? string mystring = "defaultvalue"; if (condition) mystring = "othervalue"; VS string mystring = null; if (condtion) mystring = "othervalue"; else ...
3
votes
5answers
492 views

Minimising little coding mistakes [closed]

I make a fair amount of small mistakes when I code (things such as getting an angle bracket to the wrong direction). It adds a fair amount of time to my coding because I have to debug several times ...
2
votes
3answers
350 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 ...
2
votes
2answers
220 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. ...
1
vote
1answer
95 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 ...
1
vote
3answers
207 views

About the usage of assertions [duplicate]

I stumbled upon an article named Programming With Assertions. And beside the mechanism of turning on and off assertions after compile time, I don't get it. Why were assertions introduced on language ...
0
votes
9answers
3k views

Line break before/after operator [closed]

While Sun's Java code convention suggests to put line break before the operator many other guidelines disagree with it. I do not see any obvious pros and cons, so are there advantages of using one of ...