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

learn more… | top users | synonyms (1)

50
votes
17answers
6k views

Working on someone else's code

I have hardly a year's experience in coding. After I started working, most of the time I would be working on someone else's code, either adding new features over the existing ones or modifying the ...
58
votes
16answers
4k views

Is inconsistent formatting a sign of a sloppy programmer?

I understand that everyone has their own style of programming and that you should be able to read other people's styles and accept it for what it is. However, would one be considered a sloppy ...
2
votes
4answers
8k views

how to nicely use constant std::string in c++

In my current code project, there is an awful lot of constant strings I use to print out error messages. Hardcoding such strings is generally considered to be bad practice. Now I'm searching for a ...
5
votes
3answers
990 views

Style for control flow with validation checks

I find myself writing a lot of code like this: int myFunction(Person* person) { int personIsValid = !(person==NULL); if (personIsValid) { // do some stuff; might be lengthy int myresult ...
9
votes
2answers
1k views

Is this awkward spacing some type of style?

In reading another programmers code, he uses a format I have never seen. E.G. namespace MyNs.HereWeAre {//tab here for some reason public class SomeClass ...
2
votes
4answers
339 views

Linking in code comments (to other unique anchors/comments)

How would you recommend creating "anchors" in code comments, so that during maintenance, developers can easily cross-reference other code comments. I realise that software should be intelligently ...
14
votes
7answers
2k views

A defense for boilerplate?

To me, boilerplate code is obviously bad. However I've met a developer who displays resistance in any attempt to reduce boilerplate. I realized I didn't have a readily formed, well thought out ...
10
votes
3answers
5k views

When to use typedef?

I'm a bit confused about if and when I should use typedef in C++. I feel it's a balancing act between readability and clarity. Here's a code sample without any typedefs: int ...
4
votes
5answers
2k views

Alternative IDEs [closed]

After seeing http://www.kickstarter.com/projects/ibdknox/light-table I'm wondering if anyone has come across other alternative methods of developing. When working on embedded things Notepad++ was ...
5
votes
7answers
357 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()) ...
16
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
16answers
4k views

Recommendations for teaching junior programmers good coding style [duplicate]

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
665 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
260 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
2k 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
864 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
864 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
3k 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
744 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
262 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
252 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
523 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
789 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
541 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
637 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
4k 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
616 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
23k 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
437 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
340 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 ...