Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I don't get this C/C++ Joke

Tags:

c++

c

After reading this article on thedailywtf.com, I'm not sure that I really got the joke.

It says there that some guy changed the code from

int function()  {    int x;   char data_string[15];   ...   x = 2;   strcpy(data_string,"data data data");   ... } 

to

int function()  {   int x = 2;   char data_string[15] = "data data data";   ... } 

everywhere in the code and that for some reason did inflate the size of the executable from 1 to 2 CDs (or maybe it didn't do that?).

Obviously I'm not familiar enough with C/C++ to get this joke, but what seems strangest is that the 2nd code listing seems "cleaner"—at least from what I've been told in school (that is that initializing variables is a good thing, not a bad one).

like image 359
Buttercup Avatar asked Sep 14 '09 06:09

Buttercup


1 Answers

OIC, this is a source-code-churn issue

At first glance the two forms are equivalent. The second one does look nicer but they do the same thing.

But then I read the cited page.

The problem is that the new guy churned the source tree, lots of it. It's bad form to troll through a giant source tree and make a meaningless change. Sure, perhaps one style is slightly better than another, but in practice, it should be a whole lot better before putting 1,000 deltas into a source code control system for people to wade through for eternity is justified.

I suspect that this was a source release, or some other unmentioned complexity caused the editing of that many files to expand their distribution. The contributions to that site are edited quite a bit, but basically the issue is understandable without specifics.

One of the problems with editing a zillion files for a style change is that the chance of an inadvertent error increases. This chance is greatly multiplied when a junior developer does it. Even for the experienced, there is Murphy's law to consider. If it happens right before a release it really is a hanging offense.

like image 186
DigitalRoss Avatar answered Sep 20 '22 22:09

DigitalRoss