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

learn more… | top users | synonyms (2)

4
votes
7answers
440 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
422 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
374 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
516 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 ...
6
votes
1answer
6k 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
528 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 ...
34
votes
11answers
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 ...
85
votes
18answers
41k 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) ...
9
votes
5answers
636 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
238 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 ...
18
votes
7answers
11k 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. ...
22
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 ...
7
votes
10answers
6k views

Variable names: underscores, no underscores, or camel case? [closed]

Variable names can be written in many ways, but the most common that I'm familiar with are: thisisavariable, this_is_a_variable, and thisIsAVariable. Which of these are preferred, and why?
-1
votes
8answers
513 views

Arguments for a coding standard? [closed]

A few friends and i are planning to work on a project together and we want a COMPLETELY DIFFERENT coding standard. We do NOT want to use the coding standard the libraries/language uses. Its our ...
35
votes
4answers
15k views

In Java, should I use “final” for parameters and locals even when I don't have to?

Java allows marking variables (fields / locals / parameters) as final, to prevent re-assigning into them. I find it very useful with fields, as it helps me quickly see whether some attributes - or an ...
4
votes
3answers
280 views

Deciding between obj->func() and func(obj)

I was thinking about this when I was starting to set up some code for a new project: are there any rules of thumb for when a method should be part of an object, and when it should be a stand alone ...
1
vote
3answers
440 views

PHP ORM style of querying

Ok so I have made an ORM library for PHP. It uses syntax like so: *(assume that $business_locations is an array)* Business::type(Business:TYPE_AUTOMOTIVE)-> ...
5
votes
7answers
835 views

What is the convention for skipping lines in programming?

I was wondering what is the convention for skipping lines? Do we group similar things together, skip no lines or just group everything together except if statements or similar constructs. If there is ...
0
votes
2answers
162 views

How to systematize tagging in code? [closed]

There are several almost standard tags used in comments: FIXME, TODO, BUGBUG. Which other tags do you use and for what? Are there any standards on using them, i.e. format (supplementing with date ...
11
votes
10answers
1k views

Is it true that a stricter coding style is always better?

I am currently studying computer science and was wondering how strict coding styles are in industry, how much it differs between industries and if it is true that a stricter coding style is always ...
9
votes
6answers
405 views

Giving a presentation on “code style and design patterns” [closed]

My company (small, about 40 people across 3 offices) occasionally does "developer workshops" online where one of the devs hosts a presentation about some tech topic. It's not necessarily about our ...
12
votes
5answers
803 views

Evolution in coding standards, how do you deal with them?

How do you deal with evolution in the coding standards / style guide in a project for the existing code base? Let's say someone on your team discovered a better way of object instantiation in the ...
7
votes
9answers
909 views

What's Your Method of not forgetting the end brackets, parentheses

disclaimer: for simplicity sake, brackets will refer to brackets, braces, quotes, and parentheses in the couse of this question. Carry on. When writing code, I usually type the beginning and end ...
30
votes
9answers
2k views

Scientific evidence that supports using long variable names instead of abbreviations?

Is there any scientific evidence that the human brain can read and understand fully written variable names better/faster than abbreviated ones? Like PersistenceManager persistenceManager; in ...
10
votes
9answers
443 views

How have you found, refined and maintained your coding style?

Recently, I've been switching between several projects and development environments. The expectations for coding style in each is different. Now, my question is three part, the first, just of ...
7
votes
5answers
170 views

Do you have any team guidelines regarding exceptions? [closed]

My team recently inherited a project from a team where the amount of developers dropped so low they had to offload some work. One of the projects we inherited was a project littered with nested code, ...
5
votes
2answers
556 views

API/Technical Writers Guide [closed]

Is there any good book/tutorial/guide for programmers, which can help them to write good programming documentation/tutorials/guides?
64
votes
20answers
5k views

How forgiving do you need to be on new employees? [closed]

Recently we have a new developer in our team. We are getting him up to speed and he is picking it all up quite fast, but a new developer means new (foreign) coding styles and ways to solve things. It ...
2
votes
2answers
523 views

How to describe styles and approaches of C++ programming? [closed]

How can I say more than just "C++" on my resume, reports or other writings, to convey clearly what kind of C++ programming I've been doing? Are there well-defined styles of C++? ("Styles" might ...
35
votes
10answers
10k views

Does the usage of LINQ and Lambda Expressions lead to less readable code?

I'm having a discussion with a co-worker on Linq, I'll copy here: Co-Worker: Lets be honest here. Linq syntax sucks. It's confusing and non-intuitive. Me: oh come on, more confusing ...
8
votes
7answers
614 views

Commenting/In-Code Documentation Styles

This might be a stupid question, but it's been in the back of my head for a while and I can't find a decent answer anywhere else. I have a teacher who says we should explicitly list each parameter ...
25
votes
16answers
2k views

Are short identifiers bad? [closed]

Are short identifiers bad? How does identifier length correlate with code comprehension? What other factors (besides code comprehension) might be of consideration when it comes to naming identifiers? ...
0
votes
1answer
209 views

Tips for a novice PHP developer to drive down long-term maintenance costs

I'm an experienced Java developer who is just starting up a project for an NGO. I will be working on the project for at least 6 months, following which the NGO will have to pay or find a volunteer to ...
2
votes
2answers
381 views

Coding Style And defects

Over the years I have developed several style based techniques which I use to keep my from make Error if(const == lvalue) rather then if(lvalue == const) since the first can't fall victim to the ...
104
votes
19answers
28k views

Should I return from a function early or use an if statement?

I've often written this sort of function in both formats, and I was wondering if one format is preferred over another, and why. public void SomeFunction(bool someCondition) { if (someCondition) ...
7
votes
9answers
1k views

What are your thoughts on Periods/Full Stops in code comments? [closed]

I saw this asked in the SO Tavern, so I'm posting the question here. I thought it an interesting question. (Of course it doesn't belong on SO, but I think it's OK here.) Do you add periods (or, as ...
4
votes
4answers
146 views

Most logically consistent way to create methods of the form a affects b?

I have a common scenario where I have an object (a) that logically affects another object (b), like a makes a note on b, or a marks b as disabled (usually a is a user object of the system and b is ...
33
votes
10answers
4k views

Doesn't “if (0 == value) …” do more harm than good? [closed]

This is one of the things that I hate most when I see it in someone else's code. I know what it means and why some people do it this way ("what if I accidentally put '=' instead?"). For me it's very ...
13
votes
7answers
2k views

What are the pros and cons of a language using whitespace vs. {}'s to indicate scope? [closed]

There seems to be a conflict over whether its better to use whitespace or tokens like brackets to indicate scope. I've seen many praise python's solution to the inconsistent indentation problem, but ...
70
votes
15answers
18k views

What's wrong with circular references?

I was involved in a programming discussion today where I made some statements that basically assumed axiomatically that circular references (between modules, classes, whatever) are generally bad. ...
3
votes
1answer
181 views

FromXYZ vs Overloaded Method

I'm trying to think of the cleanest way to implement a couple of methods that open a file. Consider the following method signatures: public static DomainObject Load(Uri urlToFile) { /* downloads ...
20
votes
12answers
1k views

Are long functions acceptable if they have internal structure?

When dealing with complicated algorithms in languages with support for nested functions (such as Python and D) I often write huge functions (because the algorithm is complicated) but mitigate this by ...
11
votes
4answers
1k views

If you favor “T *var”, do you ever write “T*”? [duplicate]

Possible Duplicate: int* i; or int *i; or int * i; Thinking about where we place our asterisks; how do those that prefer to keep the "pointerness" away from the type and with the identifier ...
16
votes
12answers
12k views

int* i; or int *i; or int * i; [closed]

What is your favorite method to declare a pointer? int* i; or int *i; or int * i; or int*i; Please explain why. see also: http://www.stroustrup.com/bs_faq2.html#whitespace
26
votes
12answers
5k views

Does anyone prefer proportional fonts? [closed]

I was reading the wikipedia article on programming style and noticed something in an argument against vertically aligned code: Reliance on mono-spaced font; tabular formatting assumes that the ...
15
votes
6answers
756 views

“A”, “an”, and “the” in method and function names: What's your take? [closed]

I'm sure many of us have seen method names like this at one point or another: UploadTheFileToTheServerPlease CreateATemporaryFile WriteTheRecordToTheDatabase ResetTheSystemClock That is, method ...
15
votes
6answers
905 views

Do you write titles in code comments? [closed]

I was browsing some old code that I wrote (first year in the university) and noticed that I used to write comment titles preceeding various parts of the code. Stuff like (this is from a Monopoly ...