Be sure to clearly define "programming interface" of your function.
Writing a function is a simple part of programming in any language yet it is an essential part of programming and having good functions are very important to produce high quality software. I've seen too many pooly written functions and decided to document what not to do and what to do.
When I say, pooly written function, these are functions with no clear "interface contract". Here, I am not talking about what is inside of the function (ie. implementation). I actually don't care about implementation (well, it should work, but it is really up to programmer to implement the function however he/she sees appropriate). It is more about "interface".
There are several important rules about writing good functions
Function name should have a single action word
A function should do one thing, or a unit of things that is cohernt
Etc..
However, the issue I see most offten with pooly written functions are lack of clear documentation about its arguments.
Function arguments should have acceptable values (or domain)
For instance, if function Foo takes an integer argument, it must clearly state whether 0 is acceptable, negative value is acceptable, whether it has upper/lower limits, etc. Usually function should accompany documetation that describe these details. Amazingly, many professional progammers just don't do this...
Next, function should "enforce" these domains by using Assertions and throwing Exceptoins. I would recommend setting up both, but sometimes throwing exceptions is sufficient, but not doing either is bad. Without this enforcement, problem would occur down the code stream and it is probably more time consuming to toubleshoot. With enforcement of input values at the function entry, it is much easier to understand what went wrong.... client code deviated from "interface contract" (ie. was never supposed to pass negative value, but it did).
(I will update this entry)
3/31/09
Subscribe to:
Post Comments (Atom)
30 comments:
piglets http://sftc.communityserver.com/members/Electric-Blankets/default.aspx garages http://www.webjam.com/furnacefilters flavoursome http://www.asianave.com/vendingmachines/ hopes http://www.webjam.com/kitchencabinets pulpit http://www.webjam.com/slipcovers duvedec
I really agree with the facts that you have shared on this post. An interesting topic like this really enhances reader's mind to have more effective decisions over a certain issue.
Hi,
This is an awesome blog post.... Really its great to be visiting your blog post. Keep posting... Thanks!
You are a really intelligent person I can say, as Programming is not the easiest of jobs to do.
I am really amazed to see that you have done a lot of work on this sector. These sort of thing is tough
I think its not about what is inside of the function...
Function arguments should have acceptable values (or domain)
I have very little knowledge about programming because it is something which is hard to catch and understand.
With enforcement of input values at the function entry, it is much easier to understand what went wrong...
Thanks alot for this very helpful post. Both parts are well explained and I found them very informative. Hats off
i have zero knowledge about programming because I am a business student.
It is very effective method. programming is my favorite.I love do coding.thanks for sharing it
An interesting topic like this really enhances reader's mind, HCG Blue Drops, the Faster and Natural way to lose weight
Very useful post.Where is next part .Give the link i can't find it.
Without this enforcement, problem would occur down the code stream and it is probably more time consuming to toubleshoot.
Nice . I will be thinking about programming . I am figuring the next part .
There are several important rules about writing good functions...
This way of programming is very effective in a way.This is really a great process indeed.
Function name should have a single action word. Basically a function should do one thing, or a unit of things that is coherent.
Hello! are you a programmer? :D
i like to programming in C and C++
Name should have a single action word.
This is a very good post. This will be very helpful for programmers.
This is an awesome blog post.... Really its great to be visiting your blog post. Keep posting... Thanks!
Thanks a lot Yoshi for this article. You are really a life savior and hope that your future posts will remain the same.
Its really nice that there are still people that write about this stuff. Many thanks to you and wish you all the luck sir.
private placement memo ebook shareware trial http://audiobookscollection.co.uk/de/Addressing-the-Economics-of-Waste/p226187/ ebook nature [url=http://audiobookscollection.co.uk/PCs/c2200/?page=5]anatomy trains ebook[/url] six thinking hats ebook
[url=http://onlinemedistore.com/products/gift-kamagra-jelly.htm][img]http://onlinemedistore.com/6.jpg[/img][/url]
stickers kids pharmacy http://onlinemedistore.com/products/fosamax.htm rite aid pharmacy maryland [url=http://onlinemedistore.com/products/relafen.htm]neonatal care pharmacy presentations[/url]
prescription prices from wal mart pharmacy http://onlinemedistore.com/products/sumycin.htm phentermine usa pharmacy [url=http://onlinemedistore.com/products/sinemet.htm]sinemet[/url]
grove pharmacy montclair new jersey http://onlinemedistore.com/products/prazosin.htm tower online pharmacy [url=http://onlinemedistore.com/products/lynoral.htm]pharmacy techinician online course[/url]
canadian pharmacy use in texas http://onlinemedistore.com/products/bactrim.htm canada pharmacy celexa [url=http://onlinemedistore.com/products/maxalt.htm]maxalt[/url]
premium dating [url=http://freeinternetdating.info/relationships/types-of-human-relationships]types of human relationships[/url] amish dating websites
chinese average dating age http://freeinternetdating.info/romance/free-online-romance-ebooks moroccan american advice dating
dating m1 garand [url=http://freeinternetdating.info/matchmaker/disneys-mulan-matchmaker]best friends dating[/url] first nations dating site turtle island
john kelvin dating profile http://loveepicentre.com/ gay dating guidlines
danity kanes dawn dating q [url=http://loveepicentre.com/contact/]minor dating laws indiana[/url] local coed dating
maryland white men dating black women [url=http://loveepicentre.com/]dating is he into me[/url] chubby chick dating [url=http://loveepicentre.com/user/smith/]smith[/url] average guy dating beautiful girl
Post a Comment