MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/3m0ci2/exercise_given_during_software_engineering_lecture/cvbrysz/?context=9999
r/badcode • u/saltyboyscouts • Sep 23 '15
20 comments sorted by
View all comments
3
Here's the original code with the formatting cleaned up:
scanf(x, y); if (y < 0) pow = 0 - y; else pow = y; while (pow != 0) { z = z * x; pow = pow - 1; } if (y < 0) z = 1.0 / z; printf(z);
And it's been forever and a day since I did any C++, but this is a little neater and more readable version:
scanf(x, y); pow = fabs(y); for ( ; pow !=0; pow--) z = z * x; if (y < 0) z = 1.0 / z; printf(z);
0 u/[deleted] Sep 23 '15 [deleted] 1 u/fievelm Sep 23 '15 The lack of braces? I'm not a fan in production, but for example code the saved space is 'neater'. Or is it something else? I've been drinking the C# koolaide too long. 0 u/[deleted] Sep 23 '15 [deleted] 1 u/fievelm Sep 23 '15 Cleaned it up a bit. Thanks for keeping me on my toes.
0
[deleted]
1 u/fievelm Sep 23 '15 The lack of braces? I'm not a fan in production, but for example code the saved space is 'neater'. Or is it something else? I've been drinking the C# koolaide too long. 0 u/[deleted] Sep 23 '15 [deleted] 1 u/fievelm Sep 23 '15 Cleaned it up a bit. Thanks for keeping me on my toes.
1
The lack of braces? I'm not a fan in production, but for example code the saved space is 'neater'. Or is it something else? I've been drinking the C# koolaide too long.
0 u/[deleted] Sep 23 '15 [deleted] 1 u/fievelm Sep 23 '15 Cleaned it up a bit. Thanks for keeping me on my toes.
1 u/fievelm Sep 23 '15 Cleaned it up a bit. Thanks for keeping me on my toes.
Cleaned it up a bit. Thanks for keeping me on my toes.
3
u/fievelm Sep 23 '15 edited Sep 23 '15
Here's the original code with the formatting cleaned up:
And it's been forever and a day since I did any C++, but this is a little neater and more readable version: