This is a style question:
Because Apple reserves the "_" privatization for its keywords, I was thinking of something along the lines of the following:
#import <Cocoa/Cocoa.h>
#define _(name) pvt_##name
@interface SFMeasureViewController : NSViewController {
@private
NSTextField *_(label);
}
@property (retain) IBOutlet NSTex...
I am wondering if there's a "best" approach to having a space before and after the equal sign in a HTML page when you write it down. It seems like no one is using this, but for me it seems fairly natural coming from programming languages that have this printed in their basic code style. So, is there any standard that you have to not use ...
I thought I knew how to declare version numbers for modules. But after reading the article "$VERSION Confusion" at Modern Perl Books, a Modern Perl Blog; I'm now more confused than I started. (Ignorance was indeed bliss.) Not that I have hangups about "perfect" code but I'm just really curious why such a trivial matter apparently has no ...
What is the best and cleanest way to do this? Specifically, I need some code in a static initializer block to run in that class, but I'd like to make this as clean-looking as possible.
...
Possible Duplicate:
Should else be kept or dropped in cases where its not needed?
When
a = 0
This:
var foo = function() {
if (a != 0) return true
return false
}
Or this:
var bar = function() {
if (a != 0) return true
else return false
}
...
I'd like to know if there is any consensus on what is better practice in this general statement type.
if(CouldDoSomething())
DoThatThing();
else
WriteErrors(GetTheErrorsThatWouldHaveResulted());
This may require twice as much work .as you have to check for potential problems, then either do the thing you wanted to do or go b...
Hello everyone,
I'm trying to go oop with one of my scripts. It's a contact script which deals with encodings when sending an email through jQuery's ajax function.
I wanted to make the user able to use the same script with two forms in the same page and making it an easy job.
Now I've made a prototype of how it's going to be rewritte...
For simple getters/setters, like the one below, what's the best way to document it?
public float getPrice()
{
return price;
}
I'm pretty strict about coding standards, so my IDE warns me about any undocumented public/protected methods.
Option 1:
/**
* Get the price field.
*
* @return
*/
Option 2:
/**
* @return Price
*/...
Possible Duplicate:
What is the preferred way to write boolean expressions in Java
Today, me and my colleague raked up an argument.
Which is a better way to use the boolean variables in Java code along with if statements.
boolean foo=true
//1.
if(foo == false)
// do something
else
// do something else
//2.
if(!fo...
I have to extract values from a variable that may be None, with some defaults in mind. I first wrote this code:
if self.maxTiles is None:
maxX, maxY = 2, 2
else:
maxX, maxY = self.maxTiles
Then I realized I could shorten it to:
maxX, maxY = self.maxTiles if self.maxTiles is not None else (2, 2)
But then I realized this migh...
Lets say I have the following code
public static string GetXMLValue()
{
XDocument settingsFile = XDocument.Load("Settings.xml");
return settingsFile.Element("Settings").Element("GenericValue").Value;
}
It simply reads an XML Settings file and returns the GenericValue value. It can't be any simpler than that. Now my question ...
Consider the following (nasty) code:
/// <summary>
/// Calls matching process error code on response.Code
/// </summary>
/// <param name="response">Actually will be of type Response or extend it</param>
/// <returns>true for successful response, false otherwise</returns>
private static bool ProcessErrorCode(objec...
Why is it convention to place getters and setters after constructors within classes?
I would rather see them placed immediately after class fields, before the constructors, in order to see which of the private fields are accessible via getter & setter methods. Especially if the methods' bodies are single return or assignment statements...
When I find myself calling the same getter method multiple times, should this be considered a problem? Is it better to [always] assign to a local variable and call only once?
I'm sure the answer of course is "it depends".
I'm more concerned about the simpler case where the getter is simply a "pass-along-the-value-of-a-private-variable...
In my form I have 3 styles of text: styleA (size 16 and bold, more like a header) styleB (size 16, normal weight, the normal text) and styleC (size 14 and italic, a note at the end).
Should styleA and styleB use <h?> tags and styleC use a <p> tag? Or should styleA use an <h?> tag, styleB use a <p> tag, and styleC use a <small> tag? Or i...
I have read tutorials all over the web with different kinds of tutorials specified on game (however, this turns out to be pretty general).
Are there any reasons to why many developers name their variables like:
mContext
For me it is default to just name it "context" or something similar.
Are there any reasons why the "m" are before?...
I have been writing code like the following enough a lot lately.
I don't like the duplicate code in the else block.
Is there some obvious thing I'm missing? I pondered 'goto' but abandoned it when I saw an infinite loop possibility.
I know the obvious thing to do is create a separate function. The reason I hesitate is because, like ...
I just had a discussion with a colleague where we disagreed about which of the following snippets was simpler:
public boolean foo(int x, int y) {
if (x < 0)
return false;
if (y < 0)
return false;
// more stuff below
}
OR
public boolean foo(int x, int y) {
if (x < 0 || y < 0)
return false;
/...
I was reverse engineering some code and came across this...
/************************************************************************/
/* */
/* MACRO CHECK_FREAD */
/* ...
1) I know how if…else if statements work, but in the next example both methods are identical as far as the resulting value is concerned. So does it matter which of the two methods I use or should I always go for one that is semantically closest to what the code is trying to do ( here I’m guessing that semantically the two methods are qui...