New Website!

We have a new website and a new logo for our community. Go Smalltalk!

Smalltalk was designed for Kids!

Yes! Alan Kay was trying to develop an environment to be used in the education of our kids.

Did you Know that Smalltalk was created in 70's at Xerox?

The use of the mouse, the "copy and paste", the bitblt and others technologies was firstly created in Smalltalk. Steve Jobs saw those ideas at Xerox and he developed a new language, Objective-C.

Mailing List in Spanish!

Please, go to http://groups.google.com/group/clubsmalltalk and join us!

Showing posts with label VisualWorks. Show all posts
Showing posts with label VisualWorks. Show all posts

September 10, 2008

Andres Valloud: Maths, virtual machines & books

Andres Valloud was born in Buenos Aires, Argentina. He has been working as Lead technical engineer at Cincom Systems. In this interview he answered some questions about the present in his job at Cincom and some questions about his recently published books.

CS: Andrés, How did you know Smalltalk and what was your first impression?
AV: I first learned about Smalltalk while studying mathematics in college. A math instructor, Leandro Caniglia, had found that I was also programming mathematics related stuff in things like x86 assembler, and he began insisting that I should give Smalltalk a try instead. At first I basically thought "Smalltalk what's that?", and dismissed the suggestion. But eventually he convinced me to go to his place on a Saturday afternoon. We had a 3 hour session. Within an hour I knew all my work had become obsolete. The simplicity of the language was astonishing. All the inconveniences typical of other programming languages were gone and nowhere to be seen. In fact we spent more time thinking about trees and math problems rather than about Smalltalk itself. To me this was unquestionable proof that the language was designed to help people solve problems, as opposed to forcing people to solve programming language problems on top of their original issues.

CS: You have been working in the Smalltalk Industry for a long time and now you are working with virtual machines. How did you end up working on the lowest level of a Smalltalk environment?
AV: I think it has to do with the orientation with which I have gone through challenges in the past, and perhaps a sprinkle of personality traits. From the beginning I didn't feel it was acceptable to take everything at face value, and rather concentrated on figuring out how things fit together as a whole on my own. This was applied to things like x86 assembler, then to Smalltalk, and perhaps the inevitable consequence is that now the process requires knowledge of the VM in order to continue.

CS: What are the constraints when you are working at that VM level? And, what are the usual requirements?
AV: Right now I am working on a VM that runs on 15 or so different platforms. The requirements are that the same source code should compile and run correctly on all of them, and that this implementation must provide the same visible behavior to the image. This turns out to become an unintended constraint, because it is here where you begin to see that standards look great on paper, and yet practice has all sorts of oddball and exceptional cases that must be addressed.

CS: If you have code that run in so many platforms with their particular issues, how is a VM tested before been released?
AV: At Cincom we have a test suite with which we test each interim build we make, on every platform. Also, there are numerous tests that verify that image functionality works as expected. Finally there is also the Cincom Smalltalk developer program, which gives customers access to weekly builds so they can be evaluated in advance.

CS: The VM of VisualWorks has been one of the fastest in the market, what are the secrets behind this VM?
AV: The techniques used are well known. For example, the VisualWorks VM uses a JIT approach to translate Smalltalk methods into native code. These translated methods do not have to abide by the usual C stack calling conventions, and so a lot of stack traffic is eliminated. Some primitives are also translated, and so they do not need the overhead of a C stack frame either. In addition to this, the compiled methods have polymorphic inline caches which for the most part avoid costly method lookups.

CS: If we talk about performance, what are your recommendations and what kind of code should we avoid?
AV: From the point of view of a Smalltalk image, arguably the number one performance offender is ifTrue:ifFalse:. It may not be evident at first sight, and perhaps it may even seem counterintuitive. However, typically what one does with ifTrue:ifFalse: is to do things like this:

anObject hasSomeProperty
ifTrue: [anObject doSomething]
ifFalse: [anObject doSomethingElse]
But how could be ifTrue:ifFalse: be a problem? Most, if not all, Smalltalks heavily optimize ifTrue:ifFalse:, so this does not look like it can be made faster. However, there is a way. The issue here is that the program is making a run time distinction that perhaps could be made a design time. In other words, if we made two classes, one for objects that have some property, and another for objects that do not have some property, then we would be able to rewrite the code above like this:

ObjectWithSomeProperty>>doWhatIsAppropriate
^self doSomething
ObjectWithOtherProperty>>doWhatIsAppropriate
^self doSomethingElse
Once we have these methods, we can simply replace our original ifTrue:ifFalse: with a single line of code
anObject doWhatIsAppropriate
So we have made the ifTrue:ifFalse: disappear. Where did it go? Into a cached message lookup, which in VisualWorks will resolve to a few assembler instructions to check for the class of the receiver in a polymorphic inline cache. In other words, the code will run faster, and in addition it will better express the knowledge available to developers while modeling the problem at hand.
Fast code does not have to be unreadable.

CS: If someone wants to start learning about Smalltalk's virtual machines, which books and resources would you recommend to start looking at?
AV: Personally I have found several loose resources to be useful. For example, there are presentations by people like Eliot Miranda which are available on the web. Furthermore, there are published papers that describe things like polymorphic inline caches and so on, particularly the Self papers such as the one here: http://research.sun.com/self/papers/pics.html.

CS: You wrote a book about hashing. Could you explain us what is the importance of the hashing in ourdaily work over a Smalltalk environment?
AV: Hashing is a technique to handle large amounts of data which offers O(1) access time regardless of the size of the data set. In today's world of increasingly large amounts of data that applications must handle, hashing becomes very attractive because of its O(1) behavior characteristics. Consider for example the need to detect duplicate objects. One could keep a sorted list of the unique ones seen so far, and then use binary search to determine whether any object should be added to the list or classified as a duplicate. While this could be reasonably fast for moderately sized data sets, hashing can do this in constant time for each object tested, and keep doing so regardless of the number of objects seen so far. Note that sorting is not necessary either. Compared to the sorted collection approach, hashing scales significantly better and will also execute the task in considerably less time

CS: You have written a mentoring book about Smalltalk, could you tell us a little about the motivation behind this book and who should read it?
AV: Some of us are lucky to be mentored, but most of us will not have that opportunity because there are not many mentors in the first place. My main motivation was to write down things that I have learned from my mentors, to remove the luck factor in having access to this kind of material. I have found this knowledge invaluable, so I hope it proves useful to others too.

If I said ... Would you answer

Sports?
Soccer.
Food?
I have very few dislikes, and I enjoy a variety of different cuisines from all around the world.
Computer brand?
Mac
Operative system?
*nix, Mac OS/X.
Mobile Phone?
As simple as possible.
City?
Portland, Oregon, Yosemite National Park / Mammoth Lakes, no country of preference so far.
Book?
Concrete Mathematics, by Graham, Knuth and Patashnik
Film?
Akira Kurosawa's Dreams
TV Series?
I don't watch TV anymore :).
Magazine?
None.
Car?
Honda.
Open Source?
I have no strong preference one way or the other. To me, the interesting distinction is whether software is either useful or not, where its usefulness also depends on the licenses attached to it.

August 29, 2008

New version of Chalten

It's a new version uploaded to SqueakSource (for Squeak) and to the Cincom Public Repository (for Visualworks) a new release of the project called Chalten 2.0 that is an implementation of the Time Domain (not only of the Gregorian Calendar now).

Here are some examples:

"Create some time entities"
August twentieth, 2008 --> Creates an instance of the gregorian Date for 20/08/2008
August twentieth --> Creates an instance of the gregorian DayOfMonth for 20/08
August, 2008 --> Creates an instance of the gregorian MonthOfYear for August of 2008

"But, not only gregorian entities"
Shaban seventeenth, 1429 --> Creates an instance of the islamic Date for 17/08/1429
Shaban seventeenth --> Creates an instance of the islamic DayOfMonth for 17/08
Shaban, 1429 --> Creates an instance of the islamic MonthOfYear for Shaban of 1429

JulianAugust seventh, 2008 --> Creates an instance of the julian Date for 07/08/2008
JulianAugust seventh --> Creates an instance of the julian DayOfMonth for 07/08
JulianAugust, 2008 --> Creates an instance of the julian MonthOfYear for August of 2008

Av nineteenth, 5768 --> Creates an instance of the hebrew Date for 19/05/2008
Av nineteenth --> Creates an instance of the hebrew DayOfMonth for 19/05
Av, 5768 --> Creates an instance of the hebrew MonthOfYear for Av of 5768

"Converting dates between diferents calendars"
(August twentieth, 2008) asIslamic --> Return Sha'ban 17, 1429
(August twentieth, 2008) asHebrew --> Return Av 19, 5768
(August twentieth, 2008) asJulian --> August 7, 2008 (julian)

(Shaban seventeenth, 1429) asHebrew --> Return Av 19, 5768
(JulianAugust seventh, 2008) asIslamic --> Return Sha'ban 17, 1429
(Av nineteenth, 5768) asGregorian --> August 20, 2008 (gregorian)

"Measuring distances"
August twentieth, 2008 distanceTo: December thirtieth, 2008 --> Return an instance of Measure <132 days>
Shaban seventeenth, 1429 distanceTo: Muharram second, 1430 --> Return an instance of Measure <132 days>
Av nineteenth, 5768 distanceTo: Tevet third, 5769 --> Return an instance of Measure <132 days>

"Also, measuring distance expressed in diferents way (calendars)"
August twentieth, 2008 distanceTo: Tevet third, 5769 --> Return an instance of Measure <132 days>
Shaban seventeenth, 1429 distanceTo: December thirtieth, 2008 --> Return an instance of Measure <132 days>
Av nineteenth, 5768 distanceTo: Muharram second, 1430 --> Return an instance of Measure <132 days>

"Collect some entities"
(ChaltenYear number: 2008 calendar: GregorianCalendar) months
collect: [:monthOfYear | monthOfYear lastDate] --> Returns all the last dates of the 2008 months.
(ChaltenYear number: 2008 calendar: GregorianCalendar) dates select:
[:date | date is: Monday] --> Returns all Mondays of 2008
(ChaltenYear number: 5768 calendar: HebrewCalendar) dates select:
[:date | date is: YomShabbat] --> Returns all yom shabbats of 5768

"Let's create a filter for all dates..."
nonWorkingDays := TimeLineFilter named: 'Non Working Days'

"Now, we want Saturdays to be on that filter"
nonWorkingDays addDayRule: Saturday

"Now we want Sundays from January 1st of year 1000 to the end of time..."
nonWorkingDays
addRule: (nonWorkingDays dayRule: Sunday)
from: (January first, 1000)
to: TheEndOfTime

"Now we want all July 9th since 1816 because is the Independence Day in Argentina".
nonWorkingDays
addRule: (nonWorkingDays dayOfMonthRule: July ninth)
from: (July ninth, 1816)
to: TheEndOfTime

"Testing some dates..."
nonWorkingDays includes: (July ninth, 2008) --> Returns true
nonWorkingDays includes: (July eighth, 2008) --> Returns false
nonWorkingDays includes: (July twelfth, 2008) --> Returns true, it is Saturday

"But, how about to filter some like the hebrew new year day"
nonWorkingDays addDayOfMonthRule: Tishri first
nonWorkingDays includes: (Tishri first, 5769) --> Return true, it is the next hebrew new year
nonWorkingDays includes: (September thirtieth, 2008) --> Return true, it is the next hebrew new year (in gregorian)

"21/08/2008 is a Thursday"
timespan := TimeSpan from: (August twentyfirst, 2008) duration: (48 * TimeUnits hour)
settleDate := RelativeDate timespan: timespan using: nonWorkingDays negated

nonWorkingDays includes: (August twentyfifth, 2008) --> Returns false because 25/08/2008, a Monday, is a working day
settleDate absoluteDate --> Returns 25/08/2008

"Now a new non working day is added to the filter"
nonWorkingDays addDateRule: (August twentyfifth, 2008)
nonWorkingDays includes: (August twentyfifth, 2008) --> Return true.

"Now 25/08/2008, is a not working day"
settleDate absoluteDate --> Now it returns 26/08/2008 because the filter has changed

"Working with time zones"
buenosAiresDateTime := TimeZonedDateTime
dateTime: (DateTime
date: August twentieth, 2008
timeOfDay: (TimeOfDay hours: 19 minutes: 35))
zone: TimeZones buenosAires.

greenwichDateTime := TimeZonedDateTime
dateTime: (DateTime
date: August twentieth, 2008
timeOfDay: (TimeOfDay hours: 22 minutes: 35))
zone: TimeZones greenwich.

buenosAiresDateTime = greenwichDateTime --> Return true, it is the same instant but measure in diferent zone
buenosAiresDateTime distanceTo: greenwichDateTime --> Return a measure <0 days>, because it is the same instant

buenosAiresDateTime := buenosAiresDateTime next: (TimeUnits hour * 3)

buenosAiresDateTime = greenwichDateTime --> Return false, the hour is the same but the zone is different
(buenosAiresDateTime distanceTo: greenwichDateTime)
convertTo: TimeUnits hour --> Return a measure <-3 hours>, just the offset between zones

February 24, 2008

Seaside and Ruby on rails

In this video, we can see an example of a "hello world" in Ruby on rails and the same example done in Seaside. It's interesting to see how to do an example in Ruby on rails, which is a "copy" of the Seaside framework. Ruby is a language very influenced by Smalltalk, but it is still a language.
In this video the author James Robertson is using a MAC OS and VisualWorks Smalltalk.