This is a series of posts where we take a code snippet, analyse it's cleanliness and produce a simplified version of the code. The metric for cleanliness is arbitrary, but I hope most readers will agree that the modified code is simpler to deal with. This is optimizing code for the human brain.
Let's look at our first snippet, randomly selected from a moderate-sized C++ codebase.
This is a chunk of a C++ function called from a scripting language. It extracts parameters and builds a string from them.
What are the aesthetic issues? Same line declarations, single line complexity, repeated code, old C scoping for loops.
Cleaning up always gives the same benefits. Faster mental parsing. easier debugging/stepping, minimize surprises, canonical code shapes, easier rearranging. The tradeoff is increased verbosity, but text input is not a significant time expense comparatively.
Let's see the change-by-change commented version:
And the final version without comments:
Feel free to send in snippets for the next post! The messier the better!
This is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses. thetopcleaner.com
ReplyDeleteHello It’s really a nice and helpful piece of info. I am happy that you shared this helpful info with us. Please stay us informed like this. Thank you for sharing. bye
DeleteTangki Panel
Tangki Fiberglass
Jual Septic Tank
Great Article IoT Projects for Students
DeleteDeep Learning Projects for Final Year
JavaScript Training in Chennai
JavaScript Training in Chennai
The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training
That appears to be excellent however i am still not too sure that I like it. At any rate will look far more into it and decide personally! Greenworks GPW2001 2000 PSI
ReplyDeleteTook me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! Mop
ReplyDeleteClearly, is the actual advisory article, all advice is familiar real. Thank you for this administration with us. I start interesting and adviser it. Looking for Advanced updates that have been added. biosafety cabinet
ReplyDeleteGreat post. It’s a fact that your blog posts are so unique and interesting. I have always admired your site. Thanks for the great tips and work. filter papers
ReplyDeleteThis a good way to appreciate the teacher as they put their efforts to train students. UK dissertation Writers appreciates the teachers. cheap carpet cleaning fayetteville nc
ReplyDeleteGreat info! I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have. Best Hospital in Hyderabad
ReplyDeleteThank you very much for this wonderful site well written and informative content you have.
ReplyDeletepest control services in Delhi
pest control Gurgaon
Great post. I came here while searching for Generate Press reviews & impressed with the features you explained here. It looks promising and going to buy this. End of Lease Cleaning Melbourne
ReplyDeleteGreat Information sharing I am very happy to read this article. Thanks for giving us go through info. I appreciate this post.
ReplyDeleteBest Hospital in Hyderabad
Thank you for sharing of some of the articles we read this one article is very interesting for us, I like it. best hospitals in Hyderabad
ReplyDeleteThis really is additionally an excellent publish that we truly loved reading through. It's not daily which i possesses the likelihood to determine something. Best Fertility Centre In Hyderabad
ReplyDeleteVery well written post. You have shared a wonderful article which is very helpful. Thanks for sharing, have a good day.
ReplyDeleteBest Bluetooth speakers under 2000
This is very educational content and written well for a change. It's nice to see that some people still understand how to write a quality post.
ReplyDeleteStudent Visa Australia
Skilled Visa Australia
482 Visa Australia
For Cleaning services in melbourne visit : vacate cleaning serivces in melbourne
ReplyDeleteAll the contents you mentioned in post is too good and can be very useful. I will keep it in mind, thanks for sharing the information keep updating, looking forward for more posts.Thanks deep cleaning uk
ReplyDeleteGreat Information sharing I am very happy to read this article. Thanks for giving us go through info. I appreciate this post.
ReplyDeletenitrocellulose membrane