The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Speaking of dangerous power

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
Speaking of dangerous power Posted: Nov 23, 2004 5:20 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Speaking of dangerous power
Feed Title: Cincom Smalltalk Blog - Smalltalk with Rants
Feed URL: http://www.cincomsmalltalk.com/rssBlog/rssBlogView.xml
Feed Description: James Robertson comments on Cincom Smalltalk, the Smalltalk development community, and IT trends and issues in general.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Cincom Smalltalk Blog - Smalltalk with Rants

Advertisement

I was talking about dangerous power in this post, and I got an email comment on another doozy you can get enamored of - #doesNotUnderstand:

The first time you realize that you can implement #doesNotUnderstand: in your own classes (or in any class), it can lead to some truly dangerous (and hard to follow) Smalltalk code. Here's an example - something I used to do a lot of when I first learned Smalltalk:


update: anAspect with: aValue from: aModel

	[anAspect  isKeyword
		ifTrue: [self perform: anAspect with: aValue]
		ifFalse: [self perform: anAspect]]
	on: MessageNotUnderstood
	do: [:ex | ex return]

The intent here is to handle an inbound event (sent via dependency) - and let events we get (but don't care about) fall on the floor. Why is this dangerous? Well, notice that the "let the events we don't care about fall" mechanism is a MessageNotUnderstood handler. That means that if any MNU is raised downstream from the #perform: (i.e., not in trying to perform the event, but in trying to handle it) - it will get swallowed. This leads to errors that are nearly impossible to diagnose (trust me - I've written myself into this corner). In general, you want to think twice (or more!) before you decide to handle an MNU in "normal" code....

Read: Speaking of dangerous power

Topic: Bryce Kampjes - Exupery Previous Topic   Next Topic Topic: e-gov, syndicated

Sponsored Links



Google
  Web Artima.com   

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