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

learn more… | top users | synonyms (1)

1
vote
5answers
1k views

What is the Best Style for Functions with Multiple Returns and If/Else Statements? [duplicate]

Possible Duplicate: Elegant ways to handle if(if else) else In a function where there are multiple returns, what is the best style to use? This style, where there is no 'else' because it ...
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 ...
3
votes
3answers
422 views

Is there any good reason why lines with only whitespace should be truncated?

Typically, when you hit Enter in a smart editor, it copies the indentation of the last line by inserting the same amount of spaces, so if you don't delete them, the code looks like this: sub sum { ...
1
vote
4answers
306 views

How should I write my if statements? [duplicate]

Possible Duplicate: Make a big deal out of == true? When I was a young padawan in the world of programming, a person I considered a mentor told me that if statements are more aesthetically ...
9
votes
7answers
2k views

Keep my classes and methods as small as possible?

A few days ago, I was talking to a Software Engineering PhD candidate and at some point she said to me: Keep your classes and methods as small as possible And I wonder if this is always a good ...
45
votes
14answers
7k views

Should I encourage junior developers to use explicit or implicit typing?

I am looking to solicit the community's opinion on whether or not it would be advisable to teach junior developers to code with implicit typing (using var) or should I encourage the use of explicit ...
4
votes
4answers
268 views

The importance of the length of a program?

Why is the length of a program important? What difference does it make? [Aside from the fact that a short program looks "good".]
6
votes
3answers
596 views

Programming standards and principles to become better programmer [closed]

I am a c# developer. I have always been interested in increasing my skills and knowledge and trying to pickup new technology. However now I want to enhance my knowledge in Programming standards and ...
2
votes
3answers
4k views

Why “Foo” is so a special word? [duplicate]

Possible Duplicate: Using “Foo” and “Bar” in examples I discovered that in many examples of code i various books/questions/answers/tutorials the word Foo is used to ...
0
votes
2answers
196 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 = ...
51
votes
6answers
24k 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
191 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
909 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
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 ...
14
votes
9answers
707 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
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... ...
6
votes
3answers
729 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
2k 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
440 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
818 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
183 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
283 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
858 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
7k 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 ...
17
votes
13answers
301 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 ...
13
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
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 ...
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
313 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
419 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( ...
9
votes
1answer
876 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
324 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
839 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
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 ...
1
vote
1answer
201 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
285 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 ...