IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesCorel ParadoxLanguage Basics  Print This     

Cross Ref > Language Basics

By Mike Prestwood

Corel Paradox versus C++: A side by side comparison between Corel Paradox and C++.

 
Language Basics
 

Language basics is kind of a catch all for absolute beginner stuff. The items (common names) I chose for language basics is a bit random and include items like case sensitivity, commenting, declaring variables, etc.

Case Sensitivity

[Other Languages] 

Languages Focus

Case sensitiviy in this case is referring to commands and variable names. For example, are "printf" and "PrintF" equivalent? Are fullname and FullName equivalent? When you create commands, operations, methods, or variables should you worry about case?

Corel Paradox:   No

ObjectPAL is not case sensitive. My preference for ObjectPAL is to follow the camel casing promoted in the examples and help files originally developed by Borland.

Syntax Example:  

All of the following are equivalent:

msgInfo "", "Hello"
MsgInfo "", "Hello"
msginfo "", "Hello"
MSGINFO "", "Hello"

Variables are not case sensitive.

Var
FullName String
endVar
fullname="Mike Prestwood"
msgInfo("", fullNAME)
C++:   Yes

C++ is case sensitive. In C and C++ commands and variable names are case sensitive.

Syntax Example:

The following first standard C++ snippet works:

printf("hello\n");
 
Printf("hello\n"); //>>>Does not work!




Code Blocks

[Other Languages] 

Languages Focus

The rules for code blocks within a language dictate where you can declare variables, how you "bracket" code, etc.

Corel Paradox:   endXxxx

ObjectPAL code blocks are surrounded by statement ending keywords that all use End with camel caps such as endMethod, endVar, endIf, endSwitch, and endTry.

Syntax Example:
method
endMethod
 
var
endVar
 
if
endIf
 
switch
endSwitch
 
try
endTry
C++:   { }

For C++, Java, JavaScript, and PHP, I will use Berkeley indent style only because I see more C++ code formatted that way.

Syntax Example:
int Dog::Bark() {
cout << "My first class method!" << endl;
return 0;
};




Comments

[Other Languages] 

Languages Focus

Commenting code generally has three purposes: to document your code, for psuedo coding prior to coding, and to embed compiler directives. Most languages support both a single line comment and a multiple line comment. Some languages also use comments to give instructions to the compiler or interpreter.

Corel Paradox:   ; and { ... }

Commenting Code
ObjectPAL uses ; for a single line comment and { } for a multiple line comment.

Syntax Example:  
;Single line comment.

{
Multiple line
comment.
}
C++:   // or /* ... */

Commenting Code
C++ uses "//" for a single line comment and /* */ for a multiple line comment.

Syntax Example:
//Single line comment in MS (not ANSI compliant so do NOT use).
/* ANSI compliant single line comment. */
/*
Multiple line
comment.
*/
  
/*
* This is another popular
* way to write multi-line
* comments.
*/




Constants

[Other Languages] 

General Info: Computer Language Constants

A constant is just like a variable (it holds a value) but, unlike a variable, you cannot change the value of a constant.

Corel Paradox:   const..endConst

In ObjectPAL, you declare one or more constant values within a const..endConst block. Optionally, you can specify the dataType by casting the value as part of the declaration.

If you do not specify the data type, the data type is inferred from the value as either a LongInt, a Number, a SmallInt, or a String.

As with variables, the const..endConst block can come within a method or procedure as the first bit of code, or in the Const window. Putting it above the method or procedure is allowed but has no significance so don't.

Syntax Example:
const
kFeetToMeter = Number(3.2808)
kMeterToFeet = Number(.3048)
kName = String("Mike")
  kCA = "California"     ;String inferred.
endConst
C++:   const

In standard C++, you use const and static const to declare constants.

Syntax Example:
//C++Builder 2009 Example:
const String kName = "Mike";
const int kAge = 35;
  
ShowMessage("Hi " + kName + ", you are " + kAge + ".");




End of Statement

[Other Languages] 

Languages Focus

In coding languages, common End of statement specifiers include a semicolon and return (others exist too). Also of concern when studying a language is can you put two statements on a single code line and can you break a single statement into two or more code lines.

Corel Paradox:   whitespace

ObjectPAL is a bit unique in that it doesn't use a semicolon nor a return to mark the end of a line, it uses whitespace which can be a return, space, or tab. This is a bit unusual but does allow for some nice formatting of code.

Syntax Example:  
msgInfo("", "Hello1")
msgInfo("", "Hello2")
msgInfo("", "Hello3")

;The following single line of code also works.
msgInfo("", "Hello4") msgInfo("", "Hello5")

;Two or more works too:
msgInfo
("", "Hello6")
C++:   ;

C++ uses a semicolon ";" as an end of statement specifier and you can put multiple statements on a single line of code if you wish as well as split a single statement into two or more code lines.

Syntax Example:
printf("Hello1");
printf("Hello2");
  
printf("Hello3"); printf("Hello4");
  
printf
   ("Hello5");




Literals

[Other Languages] 

General Info: Programming Literals

A value directly written into the source code of a computer program (as opposed to an identifier like a variable or constant). Literals cannot be changed. Common types of literals include string literals, floating point literals, integer literals, and hexidemal literals. Literal strings are usually either quoted (") or use an apostrophe (') which is often referred to as a single quote. Sometimes quotes are inaccurately referred to as double quotes.

Languages Focus

In addition to understanding whether to use a quote or apostrophe for string literals, you also want to know how to specify and work with other types of literals including floating point literals. Some compilers allow leading and trailing decimals (.1 + .1), while some require a leading or trailing 0 as in (0.1 + 0.1). Also, because floating point literals are difficult for compilers to represent accurately, you need to understand how the compiler handles them and how to use rounding and trimming commands correctly for the nature of the project your are coding.

Corel Paradox:   quote

String literals are quoted as in "Prestwood". If you need to embed a quote use a slash in front of the quote as in \".

In ObjectPAL, string literals are limited to 255 characters but there's nothing preventing you from using multiple string literals together as in:

msgInfo("", "You can " + " add literals together in ObjectPAL") 

To specify a floating point literal between 1 and -1, you can preceed the decimal with a 0 or not (both work). In other words, preceding and following decimals are allowed (both .1 and 0.1). Trailing decimals are also allowed (1, 1., and 1.0 are all equivalent and allowed).

Syntax Example:  
msgInfo("", "Hello")
msgInfo("", "Hello \"Mike\".")
  
;Does ObjectPAL evaluate this simple
;floating point math correctly? No!
If (.1 + .1 + .1) = .3 Then
 msgInfo("", "Correct")
Else
 msgInfo("", "Not correct")
EndIf
C++:   quote

String literals are quoted as in "Prestwood". If you need to embed a quote use a slash in front of the quote as in \".

Syntax Example:
printf("Hello\n");
printf("Hello \"Mike\".\n");
 
cout << "Hello" << endl;
cout << "Hello \"Mike\".\n";




Variables

[Other Languages] 

Languages Focus

A variable holds a value that you can use and change throughout your code so long as the variable is within scope. With variable declaration, you not only want to know the syntax of how you declare a variable but you also want to know where. Are you allowed to declare a variable inline? What are the available scopes: local vs. global. Can you assign a value at the same time you declare a variable?

Corel Paradox:   var x SmallInt endVar

Declaring variables is optional unless you click Program | Compiler Warnings while in the ObjectPAL editor for every form, script, and library you create. Using Compiler Warnings is strongly recommended to avoid incorrectly typing an existing variable and to avoid any confusion about variable scope. Also recommended is turning on Compile with Debug for every form, script, and library too for tighter, cleaner code.

Undeclared variables are AnyType variables. Common data types include Currency, Date, Datetime, Logical, LongInt, Number, SmallInt, String, and Time.

Syntax Example:
var
    FullName String
    Age SmallInt
    Weight Number
endVar
 
FullName = "Mike Prestwood"
Age = 32
Weight =154.4
msgInfo("", FullName + ", age=" + String(Age) 
             + ", weight=" + String(Weight))
C++:   int x=0;

Variable names are case sensitive.

The fundamental variable types in C++ are char, short int, int, long int, bool, float, double, long double, and wchar_t. The integer data types char, short, long and int can be either signed or unsigned. Signed variables are positive and negative. Unsigned variables are positive only.

Syntax Example:

C++, Java, and C# all use C-like variable declaration.

int Age;
int Age = 43;
float a, b, c;
string FullName; //#include 
unsigned short int FamilyMemberCount;




Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]