Consider the two code segments below.
Which one is better and Why? If you
have any other idea, please do
mention. Where can I find answers to
coding practices like these? If you
are aware of any book / article,
please do share.
//Code 1
bool MyApplication::ReportGenerator::GenerateReport(){
bool retval = false;
...
I have a big object say MyApplicationContext which keeps information about MyApplication such as name, path, loginInformation, description, details and others..
//MyApplicationCtx
class MyApplicationCtx{
// ....
private:
std::string name;
std::string path;
std::string desciption;
struct loginI...
Okay, so I've got a .NET console application with it's Main method, contained in a Program class. You know, the usual:
class Program
{
static void Main(string[] args)
{
// Do something spectactular
}
}
Since I've started using StyleCop and FxCop so rigorously, I've become kind of nit-picky about making sure everyth...
What are some of the best practices for clean code, naming conventions and documentation for PHP?
I see users/people saying this is a bad practice, Example:
// Create an array to hold x values
$arr_x = array();
That this is a unnecessary comment cause the syntax alone explains the functionality. That is should be more of a header com...
I like stylecop and we use it to enforce coding standards.
I dont like the fact that there is no way to automatically fix problems. So was thinking of making a plugin. Once I realised that 2010 is better for doing this I backtracked.
I've been looking for an existing tool to help automate this process and have come across stylecop for ...
This may be a religious argument, but it has been debated ad-nauseum here at my work whether all IF statements should include an ELSE clause - even if the ELSE clause only contains a comment stating that it was 'intentionally left blank'.
I have heard arguments for both sides:
The 'For' camp - ensures that the codes has actually address...
I recently found a situation in which I had two related variables that had several permutations upon which I wanted to do an action if the two variables were one of half a dozen permutations.
As an example of what the data range the variables were:
$months = array('January', 'February', 'March', 'April', 'May', 'June', 'July',
'Aug...
I am interested in reading examples of code in C# that makes use of the Spartan Programming philosophy. Can you please provide a link to any open source project or online code sample that follows this coding style?
...
According to Apple, two to three letter prefixes should be used
when naming classes, protocols, functions, constants, and typedef structures.
Does this include classes which are not intended to be part of a framework, simply used internally in an application? I realize this is relying on other developers that develop frameworks yo...
Do you always assign null to an object after its scope has been reached?
Or do you rely on the JVM for garbage collection?
Do you do it for all sort of applications regardless of their length?
If so, is it always a good practice?
...
I have run across a bunch of code in a few C# projects that have the following constants:
const int ZERO_RECORDS = 0;
const int FIRST_ROW = 0;
const int DEFAULT_INDEX = 0;
const int STRINGS_ARE_EQUAL = 0;
Has anyone ever seen anything like this? Is there any way to rationalize using constants to represent language ...
Consider a situation where a group of developers work independently(more or less) on projects. The dept. has a published standard to ensure code quality on issues like:
no inline/embedded/dynamic SQL statements (hand coded by the developer)
naming conventions
more
Question
How would you set about enforcing the code quality rules? Ar...
I have seen some of our colleagues using _ [underscore] in front of class names [entities in JPA], and few more people using it for local variables.
Is there a standard[or atleast best practice] in java to use _ [underscore] in front of instance[private] instance variable or class name????
I have looked at the following link in SO [Sta...
I'm new to R and having a hard time piecing together information from various sources online related to what is considered a "good" practice with writing R code. I've read basic guides but I've been having a hard time finding information that is definitely up to date.
What are some examples of well written/documented S3 classes?
How a...
As part of a code standards document I wrote awhile back, I enforce "you must always use braces for loops and/or conditional code blocks, even (especially) if they're only one line."
Example:
// this is wrong
if (foo)
//bar
else
//baz
while (stuff)
//things
// This is right.
if (foo) {
// bar
} else {
// baz
}
...
Possible Duplicate:
Why does one often see null != variable instead of variable != null in C#?
Is there any advantage on using "null != object" over "object != null"?
...
I want some questions to be answered by our fellow developers regaurding coding standards.
Is it true a developer is judged by his coding standard?
What are the best practices of coding standards which could be followed in a web application?
What are the common coding standards that budding developers fail to adapt in their application...
Could someone provide a link to a good coding standard for Haskell? I've found this and this, but they are far from comprehensive. Not to mention that the HaskellWiki one includes such "gems" as "use classes with care" and "defining symbolic infix identifiers should be left to library writers only."
...
Microsoft is pretty clear that .NET "identifiers" or "parameters" should not contain abbreviations. Straight from the horse's mouth:
To avoid confusion and guarantee cross-language interoperation, follow these rules regarding the use of abbreviations:
Do not use abbreviations or contractions as parts of identifier names. For ...
I recently started working on a small CMS. I usually develop .NET applications in C#, and I'm very used to commenting my fields and methods. My friend told me earler that having comments in PHP scripts is quite bad, since PHP is dynamic and parsed when requested, so having to parse the comments will take longer.
Does this statement ap...