The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Extra quotes

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
Extra quotes Posted: Jun 6, 2004 6:23 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Extra quotes
Feed Title: David Buck - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/buck-rss.xml
Feed Description: Smalltalk can do that
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From David Buck - Blog

Advertisement
I've been teaching Smalltalk since 1993 and one question I get frequently is "Why are there extra quotes in my stream?" I always have to explain that when writing to a stream, you have to use nextPut: to write characters, nextPutAll: to write strings, and print: to write other objects. On top of that, nextPutAll: is rather wordy to write. Your code starts to look like:

aStream
	nextPutAll: 'Welcome to ';
	print: city;
	nextPut: $.

Why can't we define one method that just does the right thing (assuming there's typically one right thing). For example:

aStream
	write: 'Welcome to ';
	write: city;
	write: $.

In Squeak, there is an implementation of write: that handles the string and character case but not the generic object case. Perhaps we should define it this way:

Stream
write: anObject
	anObject putOn: self

String
putOn: aStream
	aStream nextPutAll: self

Object
putOn: aStream
	aStream print: self

Character
putOn: aStream
	aStream nextPut: self

The other related problem is that printOn: produces a programmer-readable output, not something that's usable on a user interface. For UI's, though, you should really consider internationalization. In VW, you could do this by implementing putOn: for UserMessage.

Thoughts?

Read: Extra quotes

Topic: Comcast and blacklisting Previous Topic   Next Topic Topic: Re: I'm saddened and ashamed of the Java community right now

Sponsored Links



Google
  Web Artima.com   

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