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

learn more… | top users | synonyms (1)

5
votes
7answers
355 views

Which style is better to check and log the error?

I have read some code and here are two ways to check and log the error in cpp code that repeats in my project many times. Which way is better? 1. bool AClass::myMethod() { if (!SomeCondition()) ...
15
votes
10answers
4k views

Passing member variable as a method parameter

In a project, I've found a code like this: class SomeClass { private SomeType _someField; public SomeType SomeField { get { return _someField; } set { _someField = value; ...
14
votes
5answers
8k views

Should a string constant be defined if it's only going to be used once?

We're implementing an adapter for Jaxen (an XPath library for Java) that allows us to use XPath to access the data model of our application. This is done by implementing classes which map strings ...
63
votes
17answers
4k views

Recommendations for teaching junior programmers good coding style

I am a big fan of good coding style, producing clean, clear code that runs well and is easy to use and integrate into larger systems. I believe that we programmers are essentially craftspeople who ...
6
votes
5answers
659 views

Are SQL Injection vulnerabilities in a PHP application acceptable if mod_security is enabled?

I've been asked to audit a PHP application. No framework, no router, no model. Pure PHP. Few shared functions. HTML, CSS, and JS all mixed together. I've discovered numerous places where SQL injection ...
-1
votes
2answers
256 views

How should I group these variables?

I have a shape that will be defined by: char s_type; char color; double height; double width; These variables are scanned in from a request string sent to my server and passed into my printing ...
5
votes
3answers
1k views

What are the names for various forms of camel-case style naming?

For the purposes of communicating coding styles to my co-workers, what would I formally call the following variants of camel case? camelCase and CamelCase Notice that the former version ...
28
votes
10answers
3k views

I can't program because the code I am using uses old coding styles. Is this normal to programmers?

I have my first real job as programmer, but I can't solve any problems because of the coding style used. The code here: Does not have comments Does not have functions (50, 100, 200, 300 or more ...
0
votes
6answers
281 views

Function parameter names

I just found the following code in our code base: public String identifyArchitectureName(String platformName, String input) ... In my opinion input is one of the most meaningless names for a ...
8
votes
5answers
3k views

Any Practical Alternative to the Signals + Slots model for GUI Programming?

The majority of GUI Toolkits nowadays use the Signals + Slots model. It was Qt and GTK+, if I am not wrong, who pioneered it. You know, the widgets or graphical objects (sometimes even ones that ...
21
votes
10answers
1k views

Are nullable types preferable to magic numbers?

I have been having a little bit of a debate with a coworker lately. We are specifically using C#, but this could apply to any language with nullable types. Say for example you have a value that ...
28
votes
11answers
3k views

Why the recent shift to removing/omitting semicolons from Javascript?

It seems to be fashionable recently to omit semicolons from Javascript. There was a blog post a few years ago emphasising that in Javascript, semicolons are optional and the gist of the post seemed to ...
5
votes
8answers
846 views

creative & complex vs simple and readable

Which is a better option? It's not always that when you have something creative your code is going to look ugly. But at times it does go a bit ugly. e.g. if ( (object1(0)==object2(0) && ...
25
votes
7answers
15k views

Practical considerations for HTML / CSS naming conventions (syntax) [closed]

Question: what are the practical considerations for the syntax in class and id values? Note that I'm not asking about the semantics, i.e. the actual words that are being used, as for example ...
10
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 ...
9
votes
8answers
849 views

Functions that only call other functions. Is this a good practice?

I'm currently working on a set of reports that have many different sections (all requiring different formatting), and I'm trying to figure out the best way to structure my code. Similar reports we've ...
8
votes
5answers
2k views

Which style to use for unused return parameters in a Python function call

Is there any recommended/generally accepted coding style for handling situations where a function returns a tuple of values but only one of those values is used afterwards (note that this is mostly ...
6
votes
4answers
4k views

How to ensure a single coding standard in .NET with tool support

Probably, the basic situation is familiar to everyone. You have agreed on certain coding standards in your team and now it is time to make sure that everybody follows them. Some do it via heavy ...
10
votes
3answers
2k 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 ...
14
votes
8answers
1k views

A Class named Class?

This is more of a style question, but it is something I am currently pondering for a project of mine. Assume that you're creating an application which is modeling a school. So there are entities like ...
9
votes
3answers
736 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 ...
64
votes
11answers
4k views

What are the drawbacks of elastic tabstops?

Look here: a typical holy war on tabs vs spaces. Now look here: elastic tabstops. All problems solved, and a bunch of very useful new behaviours added. Are elastic tabstops even mentioned in that ...
4
votes
5answers
412 views

Is it a good idea to generate code with the help of your IDE? [duplicate]

Possible Duplicate: Should newbies use IDE autocomplete (Intellisense)? Since I moved on to actual IDEs for C++, Java and Python, I noticed they automatically try to complete my code. For ...
42
votes
17answers
5k views

Why Use !boolean_variable Over boolean_variable == false

A comment on this question: Calling A Method that returns a boolean value inside a conditional statement says that you should use !boolean instead of boolean == false when testing conditions. Why? To ...
7
votes
6answers
368 views

Is it a problem to have different styles of HTML coding within team?

I with 2 other friends are new to web development. We are learning HTML, CSS, Javascript and are creating simple websites to get a feel of different things. And as HTML is only a markup and not a ...
3
votes
2answers
256 views

How to go about bring up the topic of bad programming practices with colleague [duplicate]

Possible Duplicate: How do I approach a coworker about his or her code quality? My development colleague is producing numerous blocks of code which I am a bit concerned doesn't really make ...
2
votes
2answers
194 views

In Functional Programming, should domain-relevant simple functions (e.g., sorts) be reified?

In a functional application, should you wrap common higher-level functions in domain-meaningful names or should you leave them "bare"? For instance, if you have a list of Addresses, and "sorted by ...
3
votes
2answers
250 views

Designing class methods: self contained or explicit calls?

I'm probably butchering the terms, if someone knows the appropriate terms - that'd be great. But my question is: should I design my classes so that their methods' parameters be accessible from the ...
3
votes
1answer
522 views

Has anyone thoroughly compared C# common coding standards?

Most of the C# programmers I know embrace one of the common coding standards. However being aware of the standards is one thing, telling the differences is another. Browsing the common coding ...
9
votes
6answers
771 views

How do you name your GUI controls?

It's a generally considered a bad practice to use the Hungarian notation, but is common to find GUI controls named userNameTextBox and userNameLabel. Do you put the control type in it's name? Isn't ...
0
votes
1answer
519 views

XAML code styling [duplicate]

Possible Duplicate: What's the recommended control naming convention for XAML markup? Because the old answers now doesn't apply any more as Google Group(s) no longer exists I'm looking ...
6
votes
6answers
625 views

Returning an object or false in dynamic languages

Consider the following JavaScript function: function Foo() { function getPreferences() { if ([there is an existing preferences object]) { return preferences; } return false; } } ...
55
votes
12answers
17k views

What is the ideal length of a method? [closed]

In object-oriented programming, there is no exact rule on the maximum length of a method , but I still found these two qutes somewhat contradicting each other, so I would like to hear what you think. ...
67
votes
11answers
5k views

Never use Strings in Java? [closed]

I stumbled upon a blog entry discouraging the use of Strings in Java for making your code lack semantics, suggesting that you should use thin wrapper classes instead. This is the before and after ...
1
vote
5answers
346 views

Which code snippet would you rather come across? [closed]

I was just taking a look at CodeIgniters encryption class and found the following function: function sha1($str) { if ( ! function_exists('sha1')) { if ( ! function_exists('mhash')) ...
2
votes
5answers
614 views

How does a fresher with a clean slate turn into a good programmer? [closed]

As a graduate fresh out of college with a clean slate, how can one go about being a good programmer who writes good maintainable code? How does one learn good coding practices and apply them? Can one ...
2
votes
4answers
305 views

Do more object declarations affect the program?

I am programming in Windows Forms and MySQL. If I declare this in the program, I can use the connection and command objects in the whole .cs page: MySqlConnection connection = null; MySqlCommand ...
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 ...
27
votes
4answers
22k 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
435 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
337 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 ...
50
votes
4answers
9k views

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

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
270 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
626 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
5k 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
203 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 ...
96
votes
22answers
8k 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 = ...
56
votes
6answers
32k 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 ...
19
votes
12answers
2k 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); ...