It’s come to my attention that my code example for C in my October 17th post is wildly unfair.
I’m not going to deny that.
I wrote it in C instead of C++, because C looks more complicated than C++.
In the interest of fairness, here’s the same code in C++.
char* Noun; char* Adjective; char* Compliment; unsigned int ComplimentBufferSize; Noun=new char[4]; Adjective=new char[5]; strcpy(Noun, "dog"); strcpy(Adjective, "good"); ComplimentBufferSize=sizeof(char)*(strlen(Noun)+strlen(Adjective))+2; Compliment=new char[ComplimentBufferSize]; _snprintf(Compliment, ComplimentBufferSize, "%s %s", Adjective, Noun); delete []Noun; delete []Adjective; delete []Compliment;
That code is a lot easier to read than its’ C counterpart. My point holds true — it’s still more complicated than the high level version. But, these also hold true:
- I didn’t use any string classes.
- I’m using no libraries or helpers of any kind (aside from the obvious.)
- I picked string manipulation for my example because it’s harder in C/C++ than it is in C# or Java.
So, I still declare myself teh winnar. (ha! right.)
But, I’m being more fair about it.
Tags: Rants