02-15-2003, 10:28 AM
Quote:To all those QB programmers out there who are, like I was, terrified of the thought of having to learn a new programming language, fear not. C++ is unbelievably easy to learn.
I also used to say that C++ is long and tedious to program in, but there isn't really all that much more code to enter.
Glad to hear people branching out and getting into new languages (the more you know the better). A couple of things strike me as odd in the above quote however. Learning any language (procedural anyway) after you know one already is easy, its a matter of learning the new syntax. eg from QB to C:
Code:
FUNCTION myFunc%(x as INTEGER)
IF x > 0 THEN
myFunc% = 1
EXIT FUNCTION
ELSE
myFunc% = 2
EXIT FUNCTION
END IF
END FUNCTION
Code:
int myFunc(int x) {
if(x > 0) {
return 1;
else
return 2;
}
}
The other thing I find interesting is that you say you find you dont have to do much extra coding in C/C++. This can of course vary depending on how robust your code is. For example.
Code:
typedef struct {
int a;
int b;
char c;
} mem_t;
mem_t *x;
/* Allocate some memory for the mem_t struct */
x = malloc(5);
/* Stuff goes here */
exit(0);
Code:
if((x = malloc(sizeof(mem_t))) == NULL) {
fprintf(stderr, "Couldnt allocate memory for mem_t struct\n");
exit(1);
}
/* Stuff goes here */
free(x);
exit(0);
Note that for portability reasons errors should use fprintf(stderr, "") and memory should be explicitly freed (even though its not always necessary). These things are what makes C code longer than code from other languages such as QB and Java which provide either compiler or runtime protection against many things which C/C++ dont.
That said, C/C++ often allow to code things in very short form also, take the myFunc function above which can be coded in C as:
Code:
#define myFunc(x) ((x > 0) ? 1 : 2)
Get a good book on C/C++ from your local library (not an internet tutorial) and read it from cover to cover. C and C++ are /very/ powerful languages, but they do take a bit more learning effort than many other languages if you want to use them effectively and correctyly. Happy coding :lol:
esus saves.... Passes to Moses, shoots, he scores!