Newbies question: Advisability of using reserved words and terms for variables?

 

I've been using reserved and designated words and terms in EAs as variables. For instance: I am just using the term 'spread' as a designated varaible within the code as opposed to making it something like 'Spread' or 'SpreadMax'.

Good idea or bad?

 
if you like it to write confusing codes, its real a great idea !
 

Thanks Meikel,

At first it seemed like a natural and a good idea, but in the back of my mind......

 

tip:

use a prefix for your variables and you can distinguish them from predefined variable

example:

int FX_spread=0;

double FX_orderprofit=0;

 
There's no predefined or reserved variable/word spread. What's the problem?
 

Good practice in order to make maintenance of your code easier is to include the variable type in the name.


eg.

bValidParameters is a bool

sParameterName is a string

iParamaterNumber is an int

dParameterValue is a double


CB

 

Good or Bad is a mere perception. What works for one person may not work for another.

If you are an average Joe, then whatever works for the majority should work for you.


Anyway, this is how I do it.


For global variables:

version 1: Capitalize the first letter of the variable name, such as "Acceptable_loss".

version 2: Put a "g" in front of the variable name, such as "gAcceptable_loss".


For local variables:

version 1: Lowercase all the letters, such as "acceptable_loss".


For parameter variables through functions:

version 1: Put a "p" in front of the variable name, such as "pAcceptable_loss".


If you are afraid of conflicts with reserved words, then personalized your variables.

My name is Charly King Her. Thus, I put my initial in front of my variables.

For example, CKHacceptable_loss or ckh_acceptable_loss. If my codes are stolen,

I at least know that my initials are there. The evidence is quite clear about the owner of the code.

 
ckingher:

If you are afraid of conflicts with reserved words, then personalized your variables.

It's good tips ckingher. but reserved words automatically 'colorized' in metaeditor anyways, unless you mess with text colors in Options.

Also, if I were to stole your code and made it public, I would make use of the Ctrl+H .. :)


cheers

 
gordon:
There's no predefined or reserved variable/word spread. What's the problem?

It is used in iMA for example, though it's not a 'reserved word' per say. But it is used is used as a designated term for a specific usage and I have been using it as a variable instead of something like SpreadMax. As I said, it seems like a natural, but I have this little niggling feeling in the back of my mind about the advisability of it and possible limitations, confusion and conflicts.

Like reusing the letter 'i' all over the place as a local variable. In this case it seems less confusing to use a different local variable other than the same letter repeatedly.

I'm trying to use terms tha aer descriptive of there meaning, which only makes sense (to me).

My ISP does this and I have to credit them for it as the terms are self explanatory. For instance there proxy server is just called 'proxy'. Their WebMail server is just called 'WebMail': to easy.

 
cameofx wrote >>

It's good tips ckingher. but reserved words automatically 'colorized' in metaeditor anyways, unless you mess with text colors in Options.

Also, if I were to stole your code and made it public, I would make use of the Ctrl+H .. :)

cheers

Thanks for the flattery. However, people can do things differently from us.


I don't like assuming that all people are using MetaEditor as their sole editor.

It's weird and for whatever reasons, all kinds of IDE do exist out there.

And some editors don't have function and reserved word highlights.


They may compile their programs with MetaEditor.

Reason: