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

learn more… | top users | synonyms (1)

35
votes
8answers
5k views

How can I learn to effectively write Pythonic code?

Doing a google search for "pythonic" reveals a wide range of interpretations. The wikipedia page says: A common neologism in the Python community is pythonic, which can have a wide range of ...
7
votes
5answers
1k views

How to deal with different programming styles in a team?

We have a small dev team (only 3 developers) and we recently got a new team member. While he is a smart coder, his coding style is completely different from ours. Our existing code base contains ...
6
votes
8answers
421 views

What is the possible disadvantage of putting declarations in inner blocks, instead of at beginning of function?

At the place where I work, there are explicit guidelines for placement of declarations of variables. According to that, it is required to put them at the global level and / or at the beginning of ...
14
votes
5answers
815 views

Why am I seeing so many for(;;) constructs? [closed]

To my way of thinking, a for loop is used to iterate over a known or determinable range. String[] names = //something; for ( int i = 0; i < names.length; i++ ) { //do stuff } which is equivalent ...
16
votes
9answers
6k views

Why are people so strongly opposed to #region tags in methods?

I hear a lot about keeping methods short and I've heard a lot of programmers say that using #region tags within a method is a sure sign that it is too long and should be refactored into multiple ...
1
vote
5answers
2k views

Mixing jQuery with JavaScript

I just asked this question at SO about some bugginess I am experiencing with jQuery and IE8, and someone commented that he was appalled that I would mix JavaScript with jQuery (he has since deleted ...
4
votes
3answers
177 views

What could be some pitfalls in introducing a style guide and documentation generating software in a development team?

I'm considering using appledoc, a flavor of Doxygen for use in generating Objective-C code documentation, in order to create documentation for my company's iOS apps. The idea is that a server will ...
4
votes
4answers
276 views

How do you proactively guard against errors of omission?

I'll preface this with I don't know if anyone else who's been programming as long as I have actually has this problem, but at the very least, the answer might help someone with less xp. I just stared ...
1
vote
6answers
1k views

'Recommended' file length and line widths

I was curious if anyone knew of a recommendation from a reputable source for the max number of lines of code for a given file. For example, Google's Closure Linter recommends that each line should not ...
17
votes
13answers
2k views

Is it an appropriate use of #define to make typing repeated code easier?

Is there any view on whether using the #define to define full lines of code for simplifying coding is good or bad programming practice? For example, if I needed to print a bunch of words together, I'd ...
15
votes
2answers
806 views

Does objective-c's method overhead make a 'many small methods' design approach inadvisable?

I generally favour using small methods, as recommended by, amongst others, Bob Martin in Clean Code. I've also read enough about Objective-C's internals to have at least some idea about how its ...
42
votes
11answers
6k views

Should I reuse variables?

Should I reuse variables? I know that many best practice say you should not do it, however later when different developer is debugging the code and have 3 variables that look a like and only ...
0
votes
4answers
244 views

How do I convince some one that test should do assertion (not assertions) and not the helper methods

Joined a new employer and came across a new style of writing tests. @Test() public testMethodWhichDoesNotDoAnyAssertion() { LoginPage loginPage = signUpPage.doLogin("username","password"); ...
1
vote
4answers
235 views

What are the pros and cons of directly exposing a Table/View entity class to the client?

I'm developing a multi-tier application. We separate our project into three logical layers: client, service and data access. However, almost all methods in the service layer don't do anything except ...
0
votes
6answers
5k views

C++: Spaces vs Tabs [duplicate]

Possible Duplicate: Tabs versus spaces—what is the proper indentation character for everything, in every situation, ever? I have always used tabs in all my code (C, C++, python etc.) but I ...
16
votes
13answers
275 views

How to name parts of your program as a non native English speaker [duplicate]

Possible Duplicate: Do people in non-English-speaking countries code in English? I am from the Netherlands and we speak Dutch. I have worked on quite a few projects now in various ...
3
votes
7answers
5k views

Is there a common capitalization convention in C++? [closed]

I do a lot of work in Python and Java, and both those languages have fairly common (though not universal) conventions on how capitalization should be used in identifiers: both use PascalCase for class ...
12
votes
8answers
2k views

What is the accepted style for using the `this` keyword in Java?

I come from languages like Python or Javascript (and others that are less object-oriented) and I am trying to improve my working knowledge of Java, which I know only in a superficial way. Is it ...
18
votes
5answers
856 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 ...
7
votes
5answers
711 views

How much does/should your style imply about your skill in a language?

Two things I've noticed in the past week that make me wonder: An interview where my Perl skills were reviewed. I always use C-style for loops and use map about once in every 10,000 lines of code, so ...
3
votes
3answers
307 views

Do simple accessors and mutators benefit from commented block headers?

Short Question Is it necessary to add the function header comments for simple accessors and mutators? Example u8 OBJ_get_state_x(void) {return obj.state_x;} void OBJ_set_state_x(u8 x) ...
6
votes
4answers
367 views

Reason behind multi-line declaration style?

I'm a little curious about the reason behind the Windows header file declaration styles. When I read them, I see multi-line declarations such as the following: WINBASEAPI HANDLE WINAPI GetStdHandle( ...
8
votes
1answer
820 views

Offensive programming / coding [closed]

Last time I heard about "offensive programming/coding". I am not sure what it exactly mean. Why it is better, from defensive programming? Can someone give me some examples or answers?
9
votes
4answers
1k views

How much of Computer Science is actually focused on programming? [closed]

The reason why I ask this is because, when I read articles such as Wikipedia's HCI or reports on A.I., I find that much of what it talks about is actual design theory. Is this what most of Computer ...
10
votes
8answers
1k views

What qualifies “too many database requests” in code?

This is a discussion myself and some of my colleagues are having and thought I'd come out here and see what if there's a general consensus on it. It basically comes down to the following 2 opinions ...
8
votes
4answers
316 views

When is it preferred to combine Add/Edit functionality, and when to keep them separate?

I regularly come across situations where I need to Add or Edit an item, and sometimes I use separate methods for Add and Edit, and other times I combine them into a single method. Is one method ...
3
votes
5answers
734 views

Functions with side-effects in Delphi/Pascal

What is the proper approach to functions that have side-effects in Delphi/Pascal? For example, I could have a boolean function DeleteFile that returns True if the file was deleted and False ...
5
votes
7answers
2k views

Is it bad practice to use short-circuit evaluation instead of an if clause?

I'm working on an installation script, and especially there I have many things that need to be checked and actions that only need to be performed in case of related outcomes. For example, a folder ...
5
votes
8answers
1k 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 ...
1
vote
1answer
189 views

Namespaces and naming

I'm having some trouble working this one out, probably more than I should. This is a pretty large project, with a very clearly defined structure, with no obvious problems, but I can't seem to figure ...
4
votes
4answers
280 views

If the purpose of a single complicated LOC is clear, would you bother to split it on to multiple lines to make its method clear as well?

Given some (relatively) complicated line of code, I would often be inclined to split it onto multiple lines to make its function/purpose clear to others. However, if it is quite clear from context ...
10
votes
3answers
4k views

What should I include in XML documentation comments?

I'm trying to make a point of documenting my code better, especially when it comes to the XML comments on class members, but often it just feels silly. In the case of event handlers, the naming ...
13
votes
14answers
662 views

Should we encourage coding styles in favor of developer's autonomy, or discourage it in favor of consistency?

A developer writes if/else blocks with one-line code statements like: if (condition) // Do this one-line code else // Do this one-line code Another uses curly braces for all of them: if ...
15
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 ...
45
votes
16answers
3k views

Strictness in programming methods among Stack Overflow users [closed]

I've been a member of Stack Overflow for a couple of weeks now and have answered questions and read others answers, mostly in C/C++. True, I have learned about some things. For example, undefined ...
4
votes
8answers
888 views

Comparison of operator overloading abuse in different languages

A common argument against operator overloading is that it can be and is abused, e.g. A+B doing something completely different to addition. Examples are often quoted in C++ snippets, where the ...
1
vote
1answer
330 views

“positively formulated” vs. “reads as english sentence” style logic

Sorry, I'd be happy to have someone improve the title of this question. What are the benefits and downsides of "positively formulated" logic vs. having it "english readable". I'm looking for a ...
5
votes
6answers
399 views

Can one truly develop a programming style?

I started teaching myself programming half a year ago, and I've noticed I keep using a few basic techniques over and over again, is this the onset of a style or just ignorance of variation?
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 ...
5
votes
15answers
1k views

What do you think of opening brace comments in source code? [closed]

I have developed a habit of writing comments in my code by putting the comments on the same line as the opening brace, after the brace. I've found that this saves vertical space. It also leaves a hint ...
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) ...
3
votes
1answer
378 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, ...
3
votes
8answers
317 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 ...
2
votes
3answers
235 views

Portable programming style

I'm a Python programmer that prefers to develop on Windows but still end up deploying to a Linux server. I've just finished writing a little script: stuff that downloads files from a site, generates ...
9
votes
4answers
686 views

What makes for “good style” in Java? [closed]

I had asked this question on Stackoverflow, and before it got booed off, I received the helpful suggestion from Péter Török that this might be a better place to post it. I've been programming in Java ...
74
votes
16answers
18k views

What is the benefit of not using Hungarian notation?

One of the things I struggle with is not using Hungarian notation. I don't want to have to go to the variable definition just to see what type it is. When a project gets extensive, it's nice to be ...
32
votes
15answers
3k views

Pointless Code In Your Source

I've heard stories of this from senior coders and I've seen some of it myself. It seems that there are more than a few instances of programmers writing pointless code. I will see things like: ...
12
votes
11answers
326 views

Should 'mathematical' functions follow mathematical notation?

I suppose this question is going to be immediately flagged as subjective, but which do you think is better: double volume(double pressure, double n_moles, double temperature) { return n_moles * ...
2
votes
3answers
509 views

What are pros and cons of using temporary “references”?

In C and C++ (and I guess other languages that allow taking a "reference" to an array element or something similar), when you have an array like type, accessing individual elements of such an array ...
14
votes
2answers
11k views

What is the difference between K&R and One True Brace Style (1TBS) styles?

I have read the Wikipedia article on Indent Styles, but I still don't understand. What is the difference between K&R and 1TBS?