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

learn more… | top users | synonyms (1)

34
votes
8answers
5k 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 ...
9
votes
4answers
925 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 ...
24
votes
21answers
2k views

What are your programming idiosyncrasies? [closed]

I noticed that I have a peculiar habit of finishing every line with a space. It carries over from my prose writing where a paragraph can have multiple sentences and so it is very common to follow a ...
5
votes
10answers
2k views

Have you changed your coding style recently? It wasn't hard wasn't it? [closed]

I've used to write code in C-like languages using the Allman style, regarding the position of braces. void foo(int bar) { if(bar) { //... } else return; //... } Now the last two ...
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: ...
0
votes
5answers
123 views

Where to read from file?

In Java: I have a class Students. I would like to read a list of students from a file. Which one is more elegant: Reading and constructing the list in main(), and creating a Student object with the ...
4
votes
4answers
285 views

In which order should I do comparisons? [duplicate]

I'm a strong proponent of writing if statements like this: variable == constant Because to me it just makes sense, it is more readable than the inverted: constant == variable Which seems to be ...
1
vote
4answers
1k views

Switching from ActionScript to JavaScript, tips for writing code?

I am quite comfortable with using actionscript3 and flash. I also have some experience with Java. But recently, I started learning JavaScript and node.js. I ultimately want to make a 3d game in ...
4
votes
3answers
432 views

Space between negative sign and variable name

I tried doing a Google search, as well as searching this Stack Exchange site but could not find a question relating directly to this. The PEP 8 -- Style Guide for Python Code has lots of good style ...
7
votes
7answers
1k views

Prevent developers from using constants

I have one one software system which allows developers to specify an ID or name to create NodeReferences. Both work fine, but ID's are not guaranteed to be the same across different environments. I've ...
12
votes
7answers
680 views

Is there a way to support different coding styles in a development team

The Problem: Two developers => three opinions on indention, braces on new line or not etc. We usually work with three or four people on our projects and each of those has it's own code style. I know, ...
2
votes
3answers
182 views

About the usage of assertions [duplicate]

I stumbled upon an article named Programming With Assertions. And beside the mechanism of turning on and off assertions after compile time, I don't get it. Why were assertions introduced on language ...
8
votes
3answers
237 views

Is a single object to be preferred over multiple variables?

It was quite hard to put what I meant into a title, but it's easy to put into code. C++ Is this int offset_x = 10; int offset_y = 40; ... element.move(offset_x, offset_y); To be preferred over ...
16
votes
12answers
4k 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
8
votes
3answers
3k views

Throwing an exception inside finally

Static code analyzers like Fortify "complain" when an exception might be thrown inside a finally block, saying that Using a throw statement inside a finally block breaks the logical progression ...
60
votes
6answers
4k views

Should the variable be named Id or ID?

This is a bit pedantic, but I've seen some people use Id as in: private int userId; public int getUserId(); and others use: private int userID; public int getUserID(); Is one of these a better ...
-1
votes
1answer
418 views

What is the C++ convention, if any, for naming to differentiate between structure types and other types? [closed]

In general, should I use some sort of convention for structure names which is distinct from other type name? I was thinking about this when my professor started talking about structures. I had the ...
2
votes
2answers
477 views

coding style for If condition [duplicate]

I came across below style of writing if statements in C#, on msdn code examples. Usually when I write if statements, the conditions I would write `(Customer != null) I want to know if there is any ...
2
votes
1answer
217 views

Unindented elses

Been writing code since about 18 years now. Lately, I've got into the habit of not indenting elses and when I look at the code it does worry me a bit mostly that someone who might look at the code ...
5
votes
3answers
831 views

Is there an appropriate coding style for implementing an algorithm during an interview?

I failed an interview question in C years ago about converting hex to decimal by not exploiting the ASCII table if (inputDigitByte > 9) hex = inputDigitByte - 'a'. The rise of Unicode has made ...
11
votes
4answers
470 views

Always pull out common cases and branch separately? [duplicate]

We had a disagreement in a code review. What I had written: if(unimportantThing().isGood && previouslyCalculatedIndex != -1) { //Stuff } if(otherThing().isBad && ...
2
votes
2answers
270 views

Style for creating IEnumerable unions

There isn't any cool LINQ sugar for creating unions. The Enumerable.Union() method is usually called like this: var bigList = list1.Union(list2); The alternative is to call Enumerable.Union() which ...
7
votes
1answer
368 views

Is using '{}' within format strings considered Pythonic?

I just learned you can write '{}{}'.format(string_a, string_b) instead of '{0}{1}'.format(string_a, string_b) in Python, i.e. you can omit the numerals for the string format parameters when you ...
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
5answers
1k views

In Java, should private helpers go above or below public methods?

I've noticed that a coworker and I have opposite practices regarding the ordering of methods in our Java classes. One of us begins a class with its major public methods, and then put all of the ...
11
votes
5answers
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 ...
0
votes
2answers
258 views

Need some advice and feedback on my code's design

I am looking for feedback on the design of my program. I have a shell script call function.sh that defines a lot of helper functions. My intent is to use those bash functions defined in functions.sh ...
13
votes
6answers
6k views

What should my “code sample” look like?

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. ...
9
votes
1answer
1k views

Why doesn't CSS natively support variables and hierarchy?

I am new to UI development, but I feel very uncomfortable with how CSS works. My use case is that I wanted to apply some specific styles inside a particular div on a page. CSS attempt: div.class1 ...
-3
votes
1answer
694 views

Why do some programmers prefer spaces over tabs? [duplicate]

Possible Duplicate: Why do some languages recommend using spaces rather than tabs? While reading over the style guides for PHP PSR-0 PSR-1 PSR-2 I noticed the rule Code MUST use 4 ...
4
votes
5answers
501 views

How can I avoid mistakes using the same variable name again?

This isn't a rare case and occurs with me often and I spent countless time trying to debug the code. Latest example, this PHP code where I used $email for the parameter and for object as well. ...
18
votes
15answers
2k views

I hate one of our coding standards and it drives me insane, how to process it? [closed]

Disclaimer: Not as exaggerated as the title suggests, but it still makes me uncomfortable. I'm just going to express honestly, so take it with a grain of salt. Just pretend that I'm talking about that ...
4
votes
7answers
446 views

Should I spend time prettifying unit tests? [closed]

The company I used to work for before we had automated unit tests to test our work. However the coding standards and architecture was not very important for tests. Of course you had to indent code ...
0
votes
1answer
569 views

Preventing override of methods in Objective-C [closed]

Objective-C lacks private methods or java-esque final methods. This means that it is possible for a subclass to (accidentally) override some of the internals of a superclass. How does one prevent ...
2
votes
1answer
688 views

call sub function based on variable value

I have a function containing other functions. These function are called based on value of variable action. These sub functions are logically grouped - i.e., they all deal with file manipulation. ...
59
votes
11answers
3k 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 ...
25
votes
11answers
2k views

Maintenance wise, is `else while` without intervening braces considered safe?

Is else while without intervening braces considered "safe" maintenance wise? Writing if-else code without braces like below... if (blah) foo(); else bar(); ...carries a risk because the ...
3
votes
1answer
279 views

Are there published guidelines, standards, or references that propose more than 80 chars per line?

Despite increases in screen size and resolution, many sources still suggest that code be limited to 80 characters per line. I realize than there are many different opinions on this subject, but I ...
5
votes
2answers
420 views

Best practice to represent SQL in program source code

Where SQL statements are executed from a program, what is the best practice to store the statement text? Most often it is in a read only string, in the source file it is executed in. I think a ...
8
votes
4answers
724 views

Java style classes in c++

I came across this article proposing a style of coding in c++ that looks a bit weird at first. But after reading it over and pondering for a bit I'm really considering giving it a try. The most ...
11
votes
9answers
881 views

Should a programmer take writing lessons to enhance code expressiveness?

Given that programmers are authors and write code to express abstract thoughts and concepts, and good code should be read by other programmers without difficulties and misunderstandings, should a ...
35
votes
15answers
10k views

If you need more than 3 levels of indentation, you're screwed?

Per the Linux kernel coding style document: The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program. What can I deduce ...
23
votes
8answers
6k views

Should I write HTML or CSS first?

There are a lot of analogies for HTML/CSS development; which can be a bit confuse for a beginner. HTML = foundations/house CSS = walls/blueprint/wallpaper Is there any best practice here? ...
6
votes
1answer
272 views

What is the convention for the star location in reference variables?

I have been learning Objective-C, noting that different books and examples use differing conventions for the location of the star (*) when naming reference variables: MyType* x; MyType *y; MyType*z; ...
63
votes
20answers
4k views

How forgiving do you need to be on new employees?

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 ...
3
votes
5answers
264 views

Using 'new' in a projection?

I wish to project a collection from one type (Something) to another type (SomethingElse). Yes, this is a very open-eneded question, but which of the two options below do you prefer? Creating a new ...
5
votes
3answers
209 views

Commenting regular expressions

Are there any common practises for commenting the regular expressions: inline comments referring different part of RegEx or general comment for all expression?
1
vote
4answers
1k views

Should I use C style in C++?

As I've been developing my position on how software should be developed at the company I work for, I've come to a certain conclusion that I'm not entirely sure of. It seems to me that if you are ...
8
votes
4answers
702 views

css - use universal '*' selector vs. html or body selector?

Applying styles to the body tag will be applied to the whole page, so body { font-family: Verdana } will be applied to the whole page. This could also be done with * {font-family: Verdana} ...
4
votes
4answers
284 views

Single statement non-braced ifs and code merges [duplicate]

I've seen code merges being used as an argument for bracing even single statement ifs. For example: if (condition) { do something; } Unfortunately I can't think of a change that would break a ...