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

learn more… | top users | synonyms (2)

8
votes
10answers
2k 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
506 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
343 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
246 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
709 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 ...
84
votes
16answers
23k 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
350 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
682 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 ...
25
votes
3answers
21k 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?
4
votes
5answers
517 views

Minimising little coding mistakes [closed]

I make a fair amount of small mistakes when I code (things such as getting an angle bracket to the wrong direction). It adds a fair amount of time to my coding because I have to debug several times ...
3
votes
7answers
3k views

What is the benefit of multiple return values

I feel as if a return statement should only return one value. When it returns multiple, things get confusing. I know since the return type in Java has to be declared, this is difficult to do, but in ...
10
votes
6answers
13k views

How are multiple values returned in Java?

Sometimes you want to return multiple values from a function. How is this normally done in Java? One option is to use an array, like this Python snippet that returns a list or tuple: value, success ...
4
votes
2answers
502 views

Why are people afraid to die()?

I have seen a lot of people (first comment) hating die(); instead of exit; As the follow-up comments on that post note, die and exit are the same - the attitude appears to be one of perception, with ...
0
votes
9answers
7k views

Line break before/after operator [closed]

While Sun's Java code convention suggests to put line break before the operator many other guidelines disagree with it. I do not see any obvious pros and cons, so are there advantages of using one of ...
2
votes
6answers
6k views

PHP: brackets or no brackets with if/for/while/…?

Both these syntaxes are correct and equivalent: With brackets: foreach ($listOfThings as $thing) { echo $thing; } Without brackets: foreach ($listOfThings as $thing): echo $thing; endforeach; ...
7
votes
3answers
3k views

Should I use default access modifier or not — Coding practice?

Normally when creating new global variables I do not define its access modifier. So as per java it will adopt property default access modifier. When I'm need to access that variable in out of default ...
17
votes
14answers
2k views

Is it a bad idea to list every function/method argument on a new line and why?

I work with someone who, every time they call a function they put the arguments on a new line e.g. aFunction( byte1, short1, int1, int2, int3, int4, int5 ) ; I find ...
6
votes
6answers
2k views

Best practice in setting return value (use else or?)

Whenever you want to return a value from a method, but whatever you return depends on some other value, you typically use branching: int calculateSomething() { if (a == b) { return x; } else ...
84
votes
10answers
27k views

Why do most of us use 'i' as a loop counter variable?

Has anyone thought about why so many of us repeat this same pattern using the same variable names? for (int i = 0; i < foo; i++) { // ... } It seems most code I've ever looked at uses i, j, ...
29
votes
10answers
17k views

Why Should I Avoid Inline Scripting?

A knowledgeable friend recently looked at a website I helped launch, and commented something like "very cool site, shame about the inline scripting in the source code". I'm definitely in a position ...
3
votes
1answer
117 views

Objected oriented application exit

We are writing a program that does a standard "auto update software on startup". If the software finds an update ready, it will start the update process and then exit (and not run the program). We ...
5
votes
7answers
3k views

Is there something better than a StringBuilder for big blocks of SQL in the code

I'm just tired of making a big SQL statement, test it, and then paste the SQL into the code and adding all the sqlstmt.append(" at the beginning and the ") at the end. It's 2011, isn't there a better ...
38
votes
11answers
3k views

Is it bad habit not using interfaces? [closed]

I use interfaces rarely and find them common in others code. Also I create sub and super classes (while creating my own classes) rarely in my code. Is it a bad thing? Would you suggest changing ...
13
votes
8answers
360 views

Styling compound AND / OR if statements

How do you style complex compound AND / OR if statements for maximum readability? How do you indent and where do you place the line breaks? My particular situation is something like the following. ...
14
votes
9answers
3k views

LINQ Style preference [closed]

I have come to use LINQ in my every day programming a lot. In fact, I rarely, if ever, use an explicit loop. I have, however, found that I don't use the SQL like syntax anymore. I just use the ...
8
votes
8answers
972 views

How would you feel if your code editor formatted your code for you as you typed, without tabs/spaces?

As with most things, I'm sure this concept has been tried before - I just haven't come across editors that use what I've termed 'Virtual Formatting'. The principle is that there's a floating ...
14
votes
10answers
2k views

How important is a good coding style for the decision to hire a programmer? [closed]

Even as a student I am asked to review the code of programmers who have (not) passed a test (create a list of Fibonacci numbers on android). While I am very strict on coding style I just read about ...
22
votes
9answers
8k views

Style and recommendations of commenting code

I want to hear from you any advice and experience of writing comments in your code. How do you write them in the most easy and informative way? What habits do you have when commenting parts of code? ...
27
votes
9answers
12k views

Using JOIN keyword or not

The following SQL queries are the same: SELECT column1, column2 FROM table1, table2 WHERE table1.id = table2.id; SELECT column1, column2 FROM table1 JOIN table2 ON table1.id = table2.id; And ...
10
votes
5answers
7k views

Why have a method that returns a bool/int and has the actual object as an output parameter?

I see the following code pattern all over the place in my company's codebase (.NET 3.5 application): bool Foo(int barID, out Baz bazObject) { try { // do stuff bazObject ...
-1
votes
7answers
274 views

Single line comments for multiple indented lines of code [closed]

After many years of coding, trying various programming styles, weeding out unreadable or impractical stuff, I still can't figure out one thing: what is the best way to single-line-comment multiple ...
29
votes
3answers
6k views

if ('constant' == $variable) vs. if ($variable == 'constant')

Lately, I've been working a lot in PHP and specifically within the WordPress framework. I'm noticing a lot of code in the form of: if ( 1 == $options['postlink'] ) Where I would have expected to ...
7
votes
5answers
1k views

How do you get consistency in source code / UI without stifling developer's creativity?

We have a small team (2-3) of programmers writing a program with a lot of forms and dialogs. We have a problem where we cannot keep good consistency in what we write, or how we write it. The latest ...
4
votes
7answers
456 views

Returning from a long function on the first false condition

I have a long(ish) function of the following pattern: bool func(some_type_t *p1, another_t *p2) { bool a = false, b = false, c = false, etc = false; a = (some_long && expression ...
14
votes
12answers
1k views

What is the regarded current best practises regarding the “this” keyword in front of field and methods in c#?

Unless it is needed to differentiate between a variable and field with the same name, I never put this. in front of a field or any member access in C#. I see this as no different to m_ prefix that ...
3
votes
3answers
457 views

C# Coding Standard - Position of Attribute in relation to Target

I had thought that this was one of the few solved problems in C# coding standards / style; Attributes always appear on the line above the thing to which they are applied a la [SomeClassAttribute] ...
-2
votes
7answers
400 views

Vector operations: vec1.dot(vec2) vs vec1 * vec2 vs dot(vec1, vec2) [closed]

What's your preferred way to implement/use vector operations? vec1.dot(vec2) allows to reuse vec1 but is hard to read for longer equations dot(vec1, vec2) A friend of mine prefers this as "dot" ...
4
votes
8answers
529 views

Programming style: Reoccuring error checks

Hey, I have a question about programming style, because in my current code I am using a bigger function which calls some smaller functions and all of these need to be error-checked. So something like ...
7
votes
1answer
8k views

Header comment format

I realize that the "header comment" format varies from programmer to programmer, but what would be an example of a "good" header comment?
10
votes
8answers
544 views

What about all those coding rules?

I always supported the idea of having coding rules for developers in a company or a specific project. Especially if the company is size greater than 10. The bigger the company the bigger the need. I ...
38
votes
12answers
2k views

Intentional misspellings to avoid reserved words

I often see code that include intentional misspellings of common words that for better or worse have become reserved words: klass or clazz for class: Class clazz = ThisClass.class kount for count in ...
3
votes
5answers
2k views

How to not mix HTML with PHP?

I made an application in EXTJS, but my technical architect and project manager say we don't want big file, so removed the EXTJS and made in object oriented PHP and JavaScript code, mixing HTML with ...
23
votes
7answers
10k views

How far should 'var' and null coalescing operator '??' be entertained without hampering readability?

I know the title of the question is very subjective, but I was confronted with usage of ?? operator by my peers, where at the same time I was not very happy/comfortable with applying var in new ...
103
votes
18answers
52k views

Are `break` and `continue` bad programming practices?

My boss keeps mentioning nonchalantly that bad programmers use break and continue in loops. I use them all the time because they make sense; let me show you the inspiration: function verify(object) ...
11
votes
5answers
810 views

Named arguments (parameters) as a readability aid

A long time ago I programmed a lot in ADA, and it was normal to name arguments when invoking a function - SomeObject.DoSomething(SomeParameterName => someValue); Now that C# supports named arguments, ...
2
votes
3answers
192 views

Is prefixing symbols also considered as namespacing?

For example, the Objective-C convention is to prefix the symbols with two or three capital letters which are abbreviations of the project: NSString, CABasicAnimation, MGTwitterEngine… In C, many ...
8
votes
4answers
241 views

Programming in other writing systems such as those who write right-to-left

How do programmers in countries whose writing system is, say, right-to-left write their code? Say if they were using C# compiler, do they follow the left-to-right approach or do they have a different ...
19
votes
7answers
14k views

What should my “code sample” look like? [closed]

I've just had quite a good phone interview (for a CakePHP-related position, not that it's especially important to the question). The interviewer seemed to be impressed with my resume and personality. ...
23
votes
18answers
2k views

Why write clean, refactored code? [duplicate]

This is a question I've been asking myself for a long time. Thought of throwing out it to you. From my experience of working on several Java based projects, I've seen tons of codes which we call ...