Upload
amol-pujari
View
917
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
Writing Code For Others
http://www.codinghorror.com/blog/
why do we write code?
• to get it executed by a machine• the machine understands 0s and 1s only• then why do we use high level languages like c,
java, or ruby• did the machine request us to use c or ruby?
http://sourcemaking.com/
we use high level languages so humans can understand code by
reading it
http://www.makinggoodsoftware.com/2009/07/07/5-top-non-technical-mistakes-made-by-programmers/
how do others find reading your code?
• do they find it helpful in understanding your program–the optimizations you’ve done–your naming conventions, your coding style–how long they should take to do it–more importantly, would they like looking at your
code–would they love the way you code• or do they simply find it quite boring
http://stackoverflow.com/questions/1711/what-is-the-single-most-influential-book-every-programmer-should-read
you can help others to quickly read your code and understand it
http://www.joelonsoftware.com/articles/Wrong.html
characteristics of good code
• easy to read• easy to use• clean, simple, straight forward• easy to make any changes• self explanatory• short methods, clear names• consistent coding standards
http://www.thoughtclusters.com/2010/09/characteristics-of-great-programmers/
writing necessary comments
http://www.makinggoodsoftware.com/2009/09/01/programmers-top-10-sentences/
writing necessary comments
• let’s define “necessary” comments
http://en.wikipedia.org/wiki/Code_smell
writing necessary comments
• should not tell us how code works• but why code works• convert your comments into variable names or
function names, constants
http://en.wikipedia.org/wiki/Anti-pattern#Programming_anti-patterns
follow same indentations
• different people love different editors• tab is treated differently by different editors• define tab = 2 or 4 spaces• good if entire team follows same definition of
tab
http://www.makinggoodsoftware.com/2011/05/23/top-7-programmers-bad-habits/
more than indentations
http://www.makinggoodsoftware.com/2010/05/27/10-things-they-never-teach-in-college-about-programming/
more than indentations
http://www.makinggoodsoftware.com/2010/03/13/my-ten-development-principles/
write working pseudo code
•write a program• given a number• print “divisible by 3” if it is divisible by 3• print “divisible by 5 if it is divisible by 5• print “divisible by 15” if it is divisible by 15
http://www.codinghorror.com/blog/2009/05/pseudocode-or-code.html
write working pseudo code
•write a program• given a number• print “divisible by 3” if it is divisible by 3• print “divisible by 5 if it is divisible by 5• print “divisible by 15” if it is divisible by 15
http://www.codinghorror.com/blog/2009/05/pseudocode-or-code.html
write working pseudo code
• you might have simply optimized• reducing one divide operation
write working pseudo code
•write a program• given a number• print “divisible by 3” if it is divisible by 3• print “divisible by 5 if it is divisible by 5- a change requestprint “divisible by 15” if it is divisible by 15print “divisible by 17” if it is divisible by 17
http://stackoverflow.com/questions/84556/whats-your-favorite-programmer-cartoon
write working pseudo code
• If pseudo code would have been followed•without optimizations
nested if-else
• avoid nested if-else chain• use switch or multiple returns• same follows for iterators while, for
http://inter-sections.net/2007/11/13/how-to-recognise-a-good-programmer
god class
• a file or class or a module• knows too much or does too much• contains more than 1000 or 5000 loc• class with a large number of attributes,
operations, or both• uses heavy encapsulation
http://www.dehora.net/journal/2005/06/writing_code_for_others_that_use_it.html
long methods
•would you like to read and understand a function which is of 300 lines or say 1000 lines
• or would you like to understand functions with 10 lines, 20, say 30 lines at the most
http://www.dmst.aueb.gr/dds/pubs/jrnl/2003-ACMQ-CR/html/article.html
one function one responsibility
http://www.skorks.com/2010/05/why-i-love-reading-other-peoples-code-and-you-should-too/
one function one responsibility
http://rubylearning.com/blog/2010/11/08/how-does-your-code-smell/
long parameters list
http://www.codinghorror.com/blog/2006/05/code-smells.html
more coding horrors
• uncommunicative name - naming functions and variables•magic numbers, hardcoded values• data clumps• feature Envy•middle man …and more
http://www.codinghorror.com/blog/2006/05/code-smells.html
characteristics of a good code
• easy to read• easy to understand• easy to make any changes• clean, simple• looks straight forward• self explanatory• short methods, clear names
http://www.perlmonks.org/?node_id=592616
characteristics of good code
• easy to read• easy to use• clean, simple, straight forward• easy to make any changes• self explanatory• short methods, clear names• consistent coding standards
http://www.thoughtclusters.com/2010/09/characteristics-of-great-programmers/
characteristics of a good coder
• likes to read code written by well known programmers• likes to do code review of junior or senior
colleagues• participates in pair programming• learns new things weekly w.r.t. coding• does not make unnecessary complex
optimizations• does not refractor working code again and
again
and what else would you like to suggest?
http://sourcemaking.com/refactoring