The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Why keyword messages are good

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
Why keyword messages are good Posted: Jun 13, 2006 8:31 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Why keyword messages are good
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

Elliotte Rusty Harold is talking about a common bug you get when using C style languages:

I’ve probably wasted two hours over the last couple of days trying to debug this line of code:

 
 

private static final QName name = new QName("valid-isbn",
"http://www.example.org/books");


Do you see the bug? I’ve even made it easier for you by showing you just the line that contains the bug. Originally, of course, I didn’t know this was the buggy line. The exception was thrown somewhere completely different in the code base, but this is indeed the buggy line.

The bug is, of course, non-obvious - the arguments are swapped. His answer to that?

This is an example of poor API design. A method should not have two arguments of the same type that can be confused for each other if you can avoid it. If you can’t avoid it, then the method should check its arguments to make sure that the right one is in the right place; and throw an exception if it isn’t.

Actually, not so much. In this case, it's a fair cop to blame the tools . Here's how that same method would be written in Smalltalk:

 

getISBNNumber: isbnString fromUrl: urlString


Which would lead to the calling method looking like:

 

bookName := self getISBNNumber: isbnString fromUrl: urlString


Now, given that code, what's the liklihood that the user of the method would swap the arguments? Approximately zero, but only for your larger values of zero. Showing that he anticipates (but does not fully grasp why) a complaint from Smalltalkers, he says:

Interestingly this a case where even stronger typing would have helped, a lot; though doubtless the Smalltalk enthusiasts will explain to me exactly how this could never have possibly happened in their playpen; and if it did, they would have debugged it at runtime using a piece of chewing gum, a boby pin, and a pocketknife they got out of a Crackerjack box.

The problem has absolutely nothing to do with the type system. Stronger typing wouldn't help. Grabbing a better language, that makes it easy to describe the arguments? That would help.

Read: Why keyword messages are good

Topic: The tropical weather begins Previous Topic   Next Topic Topic: Weekly Log Analysis: 6/10/06

Sponsored Links



Google
  Web Artima.com   

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