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

learn more… | top users | synonyms (1)

9
votes
6answers
1k views

Should my code be DRY or readable if it can't be both?

I'm writing Ruby code for a simple encryption exercise and have frequently run across this dilemma (the exercise is a solitaire cipher if you must know). It is a question of whether I should pad out ...
2
votes
2answers
289 views

Choosing between words with different spellings for function names

A question has been bothering me for a while: when developing international projects, it is common sense to use English as the reference language since it is the language that the most people ...
3
votes
2answers
270 views

Are there standard style guides for PHP?

I've been working in a very small team for PHP development and we've been using an ad-hoc, "Invented Here" style guide. Now that our team and codebase is growing, we would like to use a more ...
2
votes
4answers
2k views

Microsoft's coding standards for ASP.NET controls

I cannot find any naming standards/conventions in MSDN for naming ASP.NET controls. One of the following standards tends to be used by programmers: lblAddress AddressLabel Address According to ...
1
vote
4answers
1k views

Is using `continue`, `break` in non-`switch` loops and `?:` bad practice? [duplicate]

Back in college I've been told that using break; and continue; outside switch statements (e.g. to escape for or while loops) is wrong, bad practice and bad habits at the same time because it only ...
7
votes
3answers
678 views

Is relying on implicit argument conversion considered dangerous?

C++ has a feature (I cannot figure out the proper name of it), that automatically calls matching constructors of parameter types if the argument types are not the expected ones. A very basic example ...
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 ...
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 ...
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 ...
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, ...
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 ...
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
433 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 ...
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 ...
-1
votes
1answer
424 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 ...
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 && ...
7
votes
3answers
333 views

Is changing the type of a variable partway through a procedure in a dynamically typed language bad style?

In Python (and occasionally PHP) where variables do not have fixed types, I'll frequently perform 'type transformations' on a variable part-way through my code's logic. I'm not (necessarily) talking ...
2
votes
2answers
272 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 ...
4
votes
5answers
2k 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 ...
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 ...
64
votes
19answers
12k views

How important is it to reduce the number of lines in code?

I am a Software developer who works on J2SE (core java). Often during our code reviews we are asked to reduce the number of lines in our code. It's not about removing redundant code, it's about ...
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 ...
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
696 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 ...
19
votes
2answers
1k views

Is it a good idea to provide different function signatures that do the same thing?

Here is a C++ class that gets constructed with three values. class Foo{ //Constructor Foo(std::string, int, char); private: std::string foo; char bar; int baz; }; All of ...
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 ...
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 ...
9
votes
7answers
972 views

Temporary variables vs line length requirements

I've been reading Martin Fowler's Refactoring. It is generally excellent but one of Fowler's recommendations seems to be causing a little trouble. Fowler recommends that you replace temporary ...
0
votes
1answer
572 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
695 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. ...
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. ...
3
votes
1answer
280 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 ...
8
votes
4answers
726 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 ...
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 ...
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? ...
5
votes
4answers
315 views
+100

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?
8
votes
4answers
706 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 ...
0
votes
1answer
60 views

How properly perform passing operation result to View

I'm developing web site on self made MVC engine. I have actionController that handles operations like register, login, post submit and etc. actionController receives operation name and parameters. Of ...
5
votes
2answers
424 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 ...
5
votes
3answers
832 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 ...
99
votes
16answers
20k views

Is there an excuse for short variable names?

This has become a large frustration with the codebase I'm currently working in; many of our variable names are short and undescriptive. I'm the only developer left on the project, and there isn't ...
5
votes
3answers
210 views

How to name an subclass that add a minor, detailed thing?

What is the most concise (yet descriptive) way of naming a subclass that only add a specific minor thing to the parent? I encountered this case a lot in WPF, where sometime I have to add a small ...
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; ...
5
votes
1answer
1k views

Pythonic use of the isinstance function?

Whenever I find myself wanting to use the isinstance() function I usually know that I'm doing something wrong and end up changing my ways. However, in this case I think I have a valid use for it. I ...
3
votes
5answers
265 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 ...