18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

VISUAL C++<br />

Here are some suggestions for a naming<br />

convention. These help identify the variables’<br />

usage and type and so reduce coding errors. This<br />

is an abridged Hungarian notation:<br />

Prefix<br />

m<br />

c<br />

g<br />

<br />

Prefix<br />

b<br />

by<br />

cx/cy<br />

d<br />

dw<br />

f<br />

fn<br />

h<br />

i<br />

ip<br />

l<br />

p<br />

s<br />

sz<br />

w<br />

x, y<br />

[_]<br />

Variable scope<br />

Instance class members<br />

Static class member (including constants)<br />

Globally static variable<br />

local variable or struct or public class<br />

member<br />

<br />

Data Type<br />

Boolean<br />

byte or unsigned char<br />

short used as size<br />

double<br />

DWORD, double word or unsigned long<br />

float<br />

function<br />

handle<br />

int (integer)<br />

smart pointer<br />

long<br />

a pointer<br />

string<br />

ASCIIZ null-terminated string<br />

WORD unsigned int<br />

short used as coordinates<br />

describes how the variable is used or<br />

what it contains. The and <br />

portions should always be lowercase, and the<br />

should use mixed case:<br />

• For state functions, use Set and Is or Can:<br />

bool IsFileDirty();<br />

void SetFileDirty(bool dirty);<br />

bool CanConnect();<br />

• Where the semantics of an operation are obvious from the types of arguments,<br />

leave type names out of the function names.<br />

Instead of:<br />

AddDatabase(Database& db);<br />

consider using:<br />

Add(Database& db);<br />

Instead of:<br />

ConvertFoo2Bar(Foo* foo, Bar* bar);<br />

consider using:<br />

Convert(Foo* foo, Bar* bar)<br />

• If a client relinquishes ownership of some data to an object, use<br />

Give. If an object relinquishes ownership of some data to a<br />

client, use Take:<br />

void GiveGraphic(Graphic* graphic);<br />

Graphic* TakeGraphic(int itemNum);<br />

• Use function overloading when a particular operation works with different<br />

argument types:<br />

void Append(const CString& text);<br />

void Append(int number);<br />

Argument names<br />

Use descriptive argument names in function declarations. The argument name<br />

should clearly indicate what purpose the argument serves:<br />

bool Send(int messageID, const char* address, const char* message);<br />

Variable Name<br />

m_hWnd<br />

ipEnvelope<br />

m_pUnkOuter<br />

c_isLoaded<br />

g_pWindowList<br />

Description<br />

a handle to HWND<br />

a smart pointer to a COM interface<br />

a pointer to an object<br />

a static class member<br />

a global pointer to an object<br />

DEBUGGING TIPS IN DEVELOPER STUDIO<br />

Visual C++ comes with a feature-rich debugger. These tips will help you get the<br />

most from your debugging session.<br />

Backing up after failure<br />

When a function call has failed and you’d like to know why (by stepping into<br />

it), you don’t have to restart the application. Use the Set Next Statement<br />

command to reposition the program cursor back to the statement that failed<br />

(right-click the statement to bring up the debugging context menu). Then step<br />

into the function.<br />

Edit and Continue<br />

Visual Studio 6 allows changes to source code to be made during a debugging<br />

session. The changes can be recompiled and incorporated into the executing code<br />

without stopping the debugger. There are some limitations to the type of changes<br />

that can be made; in this case, the debug session must be restarted. This feature is<br />

116 • <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> <strong>Guide</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!