Elegant Code pt 2 of 2(jordansebastian.com)
submitted by jsebast(30) 3 years, 4 months ago
The second installment of my guide to basic code elegance.
1 comment |category: Tips & Tricks |Views: 10 Tweet
tags: Tips another
Add a live kick counter to your blog >>
You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:
Simply copy and paste this HTML into your blog post.
posted by Tr3v(376) 3 years, 4 months ago 0
You could improve this further by replacing your second version: int something(int goofy, int mickey) { bool isBigger = (goofy > mickey); if(isBigger) return goofy; return mickey; } with this: int something(int goofy, int mickey) { if(goofy > mickey) return goofy; return mickey; } As there is no point caching the result of the goofy > mikey test if you are not going to use that result again within the method. You could go one step further and use the ternary operator and write the method like this: int something(int goofy, int mickey) { return (goofy > mickey) ? goofy : mickey; }
Reply
All tags Your tags
Suggest a new category
dpeterson(1831)
pwhe23(1134)
rcash(540)
vijayst(504)
bsenoff(361)
bnaya(312)
winphonegeek(260)
Matt_TCF(253)
isenthil(250)
Noldorin(235)