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

learn more… | top users | synonyms (1)

0
votes
2answers
195 views

Naming Rules: Standards, Reserved, and what do they depend on? [closed]

I want to know the rules of naming (AlwaysCapitalize, _underscore, firstSmallLetter, etc...) for each of Namespaces, Classes, Interfaces, Exceptions, Data Members, Methods, Variables, etc.... also I ...
94
votes
22answers
7k views

Elegant ways to handle if(if else) else

This is a minor niggle, but every time I have to code something like this, the repetition bothers me, but I'm not sure that any of the solutions aren't worse. if(FileExists(file)) { contents = ...
49
votes
6answers
22k views

Why is trailing whitespace a big deal?

Trailing whitespace is enough of a problem for programmers that editors like Emacs have special functions that highlight it or get rid of it automatically, and many coding standards require you to ...
20
votes
12answers
1k views

When does the “Do One Thing” paradigm become harmful?

For the sake of argument here's a sample function that prints contents of a given file line-by-line. Version 1: void printFile(const string & filePath) { fstream file(filePath, ios::in); ...
0
votes
1answer
182 views

How to layout class definition when inheriting from multiple interfaces

Given two interface definitions ... IOmniWorkItem = interface ['{3CE2762F-B7A3-4490-BF22-2109C042EAD1}'] function GetData: TOmniValue; function GetResult: TOmniValue; function GetUniqueID: ...
4
votes
1answer
887 views

Programming in academic environment vs industry environment [duplicate]

Possible Duplicate: Differences between programming in school vs programming in industry? This is a general discussion about programming in the industry environment. The background story is ...
4
votes
1answer
289 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 ...
14
votes
9answers
703 views

Is it good practice to use functions just to centralize common code?

I run across this problem a lot. For example, I currently write a read function and a write function, and they both check if buf is a NULL pointer and that the mode variable is within certain ...
8
votes
4answers
991 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... ...
6
votes
3answers
715 views

Is it bad idea to use flag variable to search MAX element in array?

Over my programming career I formed a habit to introduce a flag variable that indicates that the first comparison has occured, just like Msft does in its linq Max() extension method implementation ...
37
votes
8answers
6k 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
430 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
817 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 ...
17
votes
9answers
7k 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
181 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
282 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
2k 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
846 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
247 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
238 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
6k 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
290 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
6k 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
3k 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
879 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
712 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
309 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
398 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
847 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
2k 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
322 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
792 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
196 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
283 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
669 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 ...
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 ...
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
939 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
341 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 ...