Ramine
2/26/2015 12:37:00 AM
Hello,
I have tried to look at the C++ language and compare it to
Object Pascal, because i am also a Delphi and FreePascal develloper
that is using Object Pascal(i mean object pascal that is more powerful,
not pascal), so i have tried to look at the syntax of C++ patiently
to feel more what is C++ and C , and i have come to the follwing conclusion:
If you look at the "for" statement:
In Object Pascal we write this:
for i := 0 to 6 do
But in C and C++ we write this:
for (i = 0; i < 7; i++)
So as you have noticed there is an "i++" that we must add in C and C++,
so Object Pascal is more beautiful and easier here...
Other than that there is also the "case" statement:
In Object Pascal we write this:
case n of
0: str := 'alpha';
1: str := 'beta';
2: str := 'gamma';
else
str := 'invalid';
end; // case
but in C and C++ we write this:
switch (n)
{
case 0 : str = "alpha";
break;
case 1 : str = "beta";
break;
case 2 : str = "gamma";
break;
default: str = "invalid";
} // switch
So notice with me that in C++ and C you have to write
the "switch" word and you have to write all over again many times
the "case" word, but in Object pascal you write only one time
the "case" word, so Object Pascal is beautiful and easier here...
Other than that i was amazed to not find in C and C++ the data type that
we call "sets" in Object Pascal...
For example in Object Pascal we can do this with the "sets" type:
type
col_t = (red, blu, grn); // enum.
MySetType := set of col_t;
var
a, b, c : MySetType;
begin
a := []; // empty set
a := a + [red]; // union
b := a - [blu]; // difference
c := a * b; // intersection
if [red] in a then ...
(* Note that sets are generally used to handle non-exclusive flags in
Object Pascal. *)
But in C and C++ there is no equivalent type of the "sets" of Object
Pascal, so Object Pascal is beautiful and simple easier here again...
Also in Object Pascal, i have noticed that it's much easier to work with
strings than in C and C++... so Object pascal is more beautiful and
easier here also...
Also i have noticed that it's much easier to create a dynamic link
library(so or dll) with Delphi or FreePascal than with C++ or C compilers...
I think also that i don't need to speak about the macros in C++ or C,
because macros can become easily "cryptic" in C++ or C and that's bad...
And i have noticed that it's much easier to work with dynamic arrays
with Object Pascal than with C++ or C.
So i think i will not continu this comparison between Object Pascal
an C++ and C, because i think C++ and C are a mess.
So i think overall Object Pascal is more "beautiful" and easier than C++
and C, and i think that's the strenght of Object Pascal.
Thank you,
Amine Moulay Ramdane.