toggle quoted messageShow quoted text
No, I realize that. Programming is very much a personal endeavor and much of my predilection comes from teaching this stuff while I was at Purdue. You would not believe the variance you see in coding style even when the assignment is the same for all of the students. The best I could do was point out the options.
On Saturday, November 30, 2019, 11:52:51 AM EST, Roger Hill <rhill@...> wrote:
Cheers Jack. Not grumbling at all...to each his own.
On 30 Nov 2019, at 16:50, "jjpurdum via Groups.Io" <yahoo.com
I think it depends on what you're used to seeing. If I see a
memset() call, I can figure out what it's doing
much faster than I can if I have to read the 3
for loop expressions, and the statements controlled by that loop. To me, this is not "enhanced" or "elegant" code at all. It simply reflects familiarity with the System V Standard C library, of which the
mem*() family of functions have been a part of for about 40 years. Indeed, a good part of becoming a C programmer is knowing what's available in the vast selection of libraries. As far as performance, some of those frequently-used library functions are written in hand-tweaked assembler and I know I cannot write it more efficiently. Given that, why waste time writing, testing, and debugging a section of code when you know it's already been done for you?
So, where you need to study what
memset() does, I have to study what a multi-line
for loop does. If you had been using
memset() for 40 years, I think you, too, would find it takes more time to understand the
for loop code than the lone
memset() call, especially when you know the third parameter simply sets the byte limit for the initialization.
On Saturday, November 30, 2019, 11:12:09 AM EST, Roger Hill <rhill@...> wrote:
Yeah. After 50 years of coding in many languages, I still would prefer to have to maintain the 'less good' for loop.. it much more obvious what it is doing.
The fancy version might be more elegant or whatever but I would have to read it several times to decide what it was doing.
On 30 Nov 2019, at 16:07, Michael Welle <
"jjpurdum via Groups.Io" <email@example.com> writes:
Opps! Forgot to multiple the elements by the size:
memset(myArray, 0, ELEMENTS(myArray) * sizeof(myArray) );
with the macro expanded this results in
memset(myArray, 0, (sizeof(myArray) / sizeof(myArray))*sizeof(myArray));
Well, with optimisation enabled, the compiler can generate compact machine
code out of that. But as a human code reviewer I would question that and
would expect to find other interesting things in the code ;). I think
producing correct code is a complicated task and we should strive for
correct code first and then for beautiful or otherwise 'enhanced' code.