coding-style

Is it acceptable to use tricks to save programmer when putting data in your code?

Example: It's really annoying to type a list of strings in python: ["January", "February", "March", "April", ...] I often do something like this to save me having to type quotation marks all over the place: "January February March April May June July August ...".split() Those took the same amount of time, and I got 2x the # of mont...

How to do source cleanup / code formatting (defined in eclipse) using ant task

Hi all We have a defined a set of rules in Eclipse for code formatting and clean up. is there a way to run the code clean up using ant task ? I know that there are tools like checkstyle but these tool have thier own configurations and rules, and I don't want to maintain 2 sets of rules. I'm looking for an ant task that will use the s...

ASP.NET Control Styles for Child Controls

On a control like the GridView, you can specify the HeaderStyle attributes as attributes of the GridView element (e.g., HeaderStyle-Wrap="false"), or as an attribute of the HeaderStyle child element. Is one way better than the other? Or, is it just a readability preference? <asp:GridView ID="myGrid" runat="server" HeaderStyle-Wrap="fals...

Using "this" in front of member variables in C++

Possible Duplicates: Is excessive use of this in C++ a code smell Given that most organizations have a coding standard for member variables like "m_memberVar" or "memberVar_", are there good reasons to use "this->memberVal" format instead? Is there any reason not to? ...

Using $this, self::, parent:: for code readability.

I would like to know if it is acceptable/preferred to use self::method() and parent::method() when working in php classes. You can use $this->method() but $this-> can also refer to a class variable, a parent class variable, or a method from the parent class. There is no ambiguity in self:: Is self:: depreciated and/or are there any ca...

Do you use a flag or make it two operations?

An interesting discussion arose today around the concept of having one method with flags versus two methods for each state of the flag. Which makes more sense and why? void Submit(object data, bool isDraft); or void Submit(object data); void SubmitAsDraft(object data); I am tending toward the later, where each operation explicitly...

#pragma once vs include guards?

I'm working on a codebase that is known to only run on windows and be compiled under Visual Studio (it integrates tightly with excel so it's not going anywhere). I'm wondering if I should go with the traditional include guards or use #pragma once for our code. I would think letting the compiler deal with #pragma once will yield faster co...

Is it OK to use a macro to specialize std::swap?

So, I have a macro. // swap_specialize.hpp #include <algorithm> #ifndef STD_SWAP_SPECIALIZE #define STD_SWAP_SPECIALIZE( CLASSNAME ) \ namespace std { \ template<> inline \ void swap( CLASSNAME & lhs, CLASSNAME & rhs ) \ { lhs.swap(rhs); } } #endif So then I have a class // c.hpp #include...

Formatting associative array declaration

When declaring an associative array, how do you handle the indentation of the elements of the array? I've seen a number of different styles (PHP syntax, since that's what I've been in lately). This is a pretty picky and trivial thing, so move along if you're interested in more serious pursuits. 1) Indent elements one more level: $arr...

Putting constants on the left side in comparisons?

Possible Duplicates: == Operator and operands How to check for equals? (0 == i) or (i == 0) Why does one often see null != variable instead of variable != null in C#? I saw many people suggesting to put constants on the left side in all comparisons to avoid the problem of missing an equal sign. Example: use "if (0 == value)"...

Is this a good practice? "/*/something/*/something//*/"

/*/ comment here do some thing. /*/ do some thing. //*/ Why people write code like that? Is this a good practice? ...

Should I use block identifiers ("end;") in my code?

Code Complete says it is good practice to always use block identifiers, both for clarity and as a defensive measure. Since reading that book, I've been doing that religiously. Sometimes it seems excessive though, as in the case below. Is Steve McConnell right to insist on always using block identifiers? Which of these would you use? ...

c++ standard practice: virtual interface classes vs. templates

I have to make a decision regarding generalization vs polymorphism. Well the scenario is standard: I want to make my monolithic interdependent code to be more modular, clean and extensible. It is still in a stage where the change of design principle is doable, and, as I look at it, highly desirable. Will I introduce purely virtual base...

Declaring ID for ASP.NET Controls

If you don't provide an ID for your declared controls in ASPX files, I know that VS will automatically generate one for you. Should I always give the controls a descriptive ID even when I won't be accessing them from the code-behind? ...

Deciding whether or not a run a function, which way is better?

I have some data being loaded from a server, but there's no guarantee that I'll have it all when the UI starts to display it to the user. Every frame there's a tick function. When new data is received a flag is set so I know that it's time to load it into my data structure. Which of the following ways is a more sane way to decide when to...

Is there a particular naming convention for Java methods that throw exceptions?

I'm tempted to add a suffix like "Ex" to differentiate methods (with similar signatures) that throw Exceptions from those that don't. Is there such a convention? ...

When to use '$(this)' and 'this' in a jQuery plugin? (Article on net.tutsplus.com)

Hello, I'm learning jQuery now, and was reading an article of Jeffrey Way, "You Still Can’t Create a jQuery Plugin?" Almost everything is clear, but there are some points that I still cannot understand. Problems begin on the 'Step 3: Building the Plugin', heading title 'For Each...', and next 'Error Checking'. this.each(function() ...

Is there a coding convention for a "line rule" for Java

I like to organize my Java files a little and would like to know if there is a standard way of doing this. For example: public class Example { private int exampleInt; private String exampleString; /*------------------------------------------------------------*/ /* I N N E R C L A S S E S ...

Why is capitalising class names in Java (and others) only a suggestion and not a rule?

I am wondering why Java, with its many safety features and constraints, allows developers to start a class name with a lowercase letter even though it would be an extremely stupid idea to do so. Or have I overlooked a case where this could be useful? Or is it simply a case of not bossing the programmer around? ...

are there any style guides recommendations or conventions for formatting complex boolean logic?

I worked on a project which involved complex boolean logic. This complexity made the code very efficient, but unfortunately hard to read. So we laid the logic out as below, which made it easier to see the groups within the compound statements, and also made it possible to add comments to parts of the logic. (This code isn't real code f...