70 likes | 241 Views
Comparison of Batak & C++. C++ #include <iostream.h> int main() { cout << “Hello world<br>”; }. Batak Program Hello; integer main() { writeline(‘Hello world’); }. Hello world. No superficial #include directive Hello is an object of type program, explicitly exposed. C++
E N D
C++ #include <iostream.h> int main() { cout << “Hello world\n”; } Batak Program Hello; integer main() { writeline(‘Hello world’); } Hello world No superficial #include directive Hello is an object of type program, explicitly exposed.
C++ int main() { char s1[5] = “32767”; char s2[5] = “65536”; int i = atoi(s1); long l = atol(s2); s1 = itoa(i) s2 = ltoa(l); l = 32767L; float f = (float) i; i = (int) f; } Batak int main() { char[5] s1 := ‘32767’, s2 := ‘65536’; integer i := integer(s1); long l := long(s2); s1 := char[5](i) s2 := char[5](l); l := 32767; float f := float(i); i := int(f); } Conversion (type casting)
C++ uses badly named operations (atoi, atol, ltoa, itoa) Programmers have to memorize those names C++ uses different syntax to achieve that (e.g., (int) and atoi) Batak uses properly-named operations (the same name with the target type) Programmers don’t have to memorize additional names Same syntax, conversion is just like calling other operations Remarks about conversion
C++ void move_to (int old_x1, int old_y1, int new_x1, int new_y1); Batak void move_to (integer old_x1, old_y1, new_x1, new_y1); Operation prototype • In C++, programmers have to repeat the name of type in the operation prototype • In Batak, they don’t have to • C++ • void move_to (int x1, int y1, • int x2, int y2, char s1[], char s2[]); • Batak • void move_to (integer x1, y1, x2, y2; char[] s1, s2);
Operation prototype and object declaration • C++ • void move_to (int x1, int y1,int& x2, int& y2,char s1[], char s2[]) • { • int a, b; • a = x1; b = y1; • x2++; y2++; • char s3[], s4[]; • strcpy(s3, s1); • strcpy(s4, s2); • } • Batak • void move_to (integer x1, y1;integer& x2, y2; char[] s1, s2) • { • integer a, b; • a := x1; b := y1; • x2++; y2++; • char[] s3, s4; • s3 := s1; • s4 := s2; • }
C++ Programmers have to repeat the description of parameter passing for every object, even they are of the same type The syntax of objects list in the operation heading is unnecessarily different from the ones in the operation body Programmers have to memorize name of operation to assign string value; assigning string value is unlike assigning other value. Batak Programmers don’t have to repeat the description of parameter passing, if the objects are of the same type The syntax of object list in the operation heading is only necessarily different (e.g., passed-by address) Programmers don’t have to memorize name of operation to assign string value; assigning string value is just like assigning any other value Remark