This post originated from an RSS feed registered with Agile Buzz
by James Robertson.
Original Post: A Comment on Arguments
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
One of the fragments that started in Have Compiler Will Travel the other day was this thing about reflectively documenting code. Lots of things to lots of people. And a whole holy war waiting in the wings as to how to do it and what worth it is. Let's avoid that here.
What it caused me to think about was method argument names. I sat and pondered what kinds of things a tool could infer from argument names. Kind of like how the class reporter used to use the class comment to figure things out about the use of its ivars IF you adhered to a certain syntax in your class comment. I realized I might be able to write a simple tool that extracted info from 90% of my method argument names if I so desired (no clue what I'd do with the information, but that's beside the point).
I write nearly all of my method argument names with a leading indefinite article (either "a" or "an"). And at the end, I almost always put a type. For example:
name: aString
name := aString
or
getPngOr: aBlock
^[self getPng] on: Error do: [:ex | ex returnWith: aBlock value]
Sometimes, I'm presented with a two arg method where the type is the same. So if I can, I might squeeze an "intent" word in there. Such as:
I've been known to be lazy and use A, B, C in place of the "intent" inserts too. Finally there's things where the arugment is a Collection of somethings. Usually in that I case I do something like:
How do you name your arguments? Do you do something similiar? What--if any--value would be derived from being able to suck this information out? To me it seems that the variable is self documenting, but maybe someone's grand documentation unification schemes could benefit from something like this.