The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Less Arguments. More From Your Code.

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Less Arguments. More From Your Code. Posted: Dec 13, 2006 12:29 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Less Arguments. More From Your Code.
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement

Along time ago, I was introduced to the "demeter metric." At the time it was summed up to me as chained message sends. For example:

(self components at: 4) container container topComponent model keyboardProcessor actions first id
No, it's not a real code example. It doesn't work. Just something I cooked up. But it's reminiscient of fragments we've all seen from time to time. In general, this kind of thing is not good. It's like a long chain, and with so many links, the likelihood that a change in one of them will cause it to all crash down increases. In short, too much coupling.

Of late, I've come to appreciate another form of coupling. Messages with too many arguments. When we concoct a message with multiple arguments, we're saying this object needs this arguments all at the same time. Often, it's just shortcut stuff. The problem is that when you want to change the interface to that object, you have to weave your new argument in with all of these big many argument message. Try refactoring or enhancing the interface to Dialog and you'll discover just what a pain this is. IMO, it's far better when possible to break all of this setters up into separate pieces and invoke them separately as needed. When we do this, we're able to actually make more and richer use fo the objects we interface with.

For fun, I put together a script that finds the highest number of arguments in an image:

| count winners |
count := 0.
winners := Set new.
Smalltalk allBehaviorsDo: 
		[:eachBehav | 
		eachBehav selectors do: 
				[:each | 
				myCount := each numArgs.
				myCount = count ifTrue: [winners add: each].
				myCount > count 
					ifTrue: 
						[count := myCount.
						winners := Set with: each]]].
winners
The winner in the VisualWorks development image appears to be this monster:
	IndentedLabelAndIcon>>
		newIndentLevel:
		hasChildren:
		hasParent:
		isExpanded:
		isFirst:
		isLast:
		rootIcon:
		trailingIcon:
		icon:
		offset:
		withTextOrString:
		withAttibutes:
		displayableIndents:
		view:
		index:
		lookType:

Can anyone beat that?

Read: Less Arguments. More From Your Code.

Topic: XPDAY2006: Joshua Kerievsky's keynote speech Previous Topic   Next Topic Topic: More Conference Photos

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use