coding-style

Is gratuitous use of 'var' keyword considered harmful?

Possible Duplicate: Use of var keyword in C# I use it almost all the time unless I'm not assigning to the variable immediately, in which case it's not an option. Good or bad? ...

How to get all n sets of three consecutives elements in an array or arraylist with a for statement ?

Hi, I'm trying to do a convex hull approach and the little problem is that I need to get all sets of three consecutive vertices, like this: private void isConvexHull(Ponto[] points) { Arrays.sort(points); for (int i = 0; i <points.length; i++) { isClockWise(points[i],points[i+1],points[i+2]); } ...

Enum.TryParse with Flags attribute

I have written code to TryParse enum either by value or by its name as shown below. How can I extend this code to include parsing enums with Flags attribute? public static bool TryParse<T>(this T enum_type, object value, out T result) where T : struct { return enum_type.TryParse<T>(value,...

Is this a good approach to execute a list of operations on a data structure in Python?

I have a dictionary of data, the key is the file name and the value is another dictionary of its attribute values. Now I'd like to pass this data structure to various functions, each of which runs some test on the attribute and returns True/False. One approach would be to call each function one by one explicitly from the main code. Howe...

Java: repetition, overuse -- problem?

I try to be as minimalist as possible. Repetition is a problem. I hate it. When is it really a problem? what is static-overuse? what is field-method overuse? what is class-overuse? are there more types of overuse? Problem A: when it is too much to use of static? private static class Data { private static String f...

Purpose of "$Id: ..." line in the header of source files

/* $Id: file.c,v 1.0 2010/09/15 01:12:10 username Exp $ */ I find this line in many source code files in the comment at the top (header) of the file. Why? Is it aimed for the version control software? -Thanks. ...

PHP and writing clean code

Hello Im trying to find best practices to write PHP. I just wonder is this a bad habit. For example, processing variables. $var = 1 $var = doSomething($var); $var = doSomething2($var); $var = doSomething3($var); It looks a bit awful. Here is a example of a real code that I just did: $this->rSum = explode(",", $this->options["rSu...

Which is the best and appropriate way to write the code in Winforms ?

What is the best way to write the code ? (1) Like directly writing the code in the button_click() event. or (2) Make the function of that code which I write in button_click() event and write this function in one class and then that function I should call in the button_Click() event.Like is it called three-tier approach to write the c...

Consistency vs Design Guidelines

Lets say that you get involved in the development of a large project that is already in development for a long period ( more than one year ). The projects follows some of the current design guidelines, but also has a few different, that are currently discouraged ( mostly at naming guidelines ). Supposing that you can't/aren't allowed to...

page separator in Kate editor

PEP 8 says: Python accepts the control-L (i.e. ^L) form feed character as whitespace; Many tools treat these characters as page separators, so you may use them to separate pages of related sections of your file This look like a great idea for me, but in the text editor I use(kate) "control+L" is for save all files. Someon...

Code formatting for initializing lists

I've just found in my java project this code snippet: List<IssueType> selectedIssueTypes = new ArrayList<IssueType>(); for (Object item : selectedItems) selectedIssueTypes.add((IssueType) item); How do you think, can this style be used? ...

Return statements for all functions

How common is it for coding style guidelines to include a requirement that all functions include at least one return statement (even functions which return void)? To avoid being subjective or argumentative, I'd like answers which can name specific companies or open-source projects which have this requirement. If you haven't ever come ac...

Purpose of IF, ELSE, FOR macros ?

I have a source code of a library which has a lot of strange IF, ELSE, FOR, etc. macros for all common C-keywords instead of using just usual if,else,for,while keywords. These macros are defined like this: #define IF( a) if( increment_if(), a) where increment_if() function is defined so: static __inline void increment_if( void) { ...

Recommendations for 'C' Project Architecture Guidelines?

Now that I got my head wrapped around the 'C' language to a point where I feel proficient enough to write clean code, I'd like to focus my attention on project architecture guidelines. I'm looking for a good resource that coves the following topics: How to create an interface that promotes code maintainability and is extensible for fu...

Circular increment: Which is "better"?

When you have a circular buffer represented as an array, and you need the index to wraparound (i.e., when you reach the highest possible index and increment it), is it "better" to: return (++i == buffer.length) ? 0: i; Or return ++i % buffer.length; Has using the modulo operator any drawbacks? Is it less readable than the first so...

Is my javascript coding style following best-practice?

What is the 'best practise' with regard to coding style. Should I use _ for private members? Should I use this._privateMember? Please re-write my code in proper style if its wrong: (function()){ var _blah = 1; someFunction = function() { alert(_blah); }; someOtherFunction = function { someFunction(); } }...

'AND' vs '&&' as operator

Actually, I am facing a codebase where developpers decided to use 'AND' and 'OR' instead of '&&' and '||'. I know that there is difference in operators precedence (&& goes before 'and'), but with given framework (prestashop to be precise) is clearly not a reason. So, my question: which version are you using? Is 'and' more readable than '...

Is there a standard literal constant that I can use instead of "utf-8" in C# (.Net 3.5)?

Hi, I would like to find a better way to do this: XmlNode nodeXML = xmlDoc.AppendChild( xmlDoc.CreateXmlDeclaration( "1.0", "utf-8", String.Empty) ); I do not want to think about "utf-8" vs "UTF-8" vs "UTF8" vs "utf8" as I type code. I would like to make my code less prone to typos. I am sure that some standard library has declatred ...

Can Eclipse parse and use emacs-style meta information in source code?

In emacs, it is possible to start a file off with a line this: /* -*- mode: java; c-basic-offset: 4; indent-tabs-mode: nil -*- */ This instructs emacs to use 4 spaces for indentation. I like the idea of storing this coding style meta-information directly and explicitly in the source code. Are there any options for doing this in othe...

Common coding style for Python?

Hi, I'm pretty new to Python, and I want to develop my first serious open source project. I want to ask what is the common coding style for python projects. I'll put also what I'm doing right now. 1.- What is the most widely used column width? (the eternal question) I'm currently sticking to 80 columns (and it's a pain!) 2.- What quot...