Smalltalk Simplicity and Consistency
One of the nicer things about Smalltalk is the consistency of the object model. A fair amount of that is due to the fact that everything is an object, and that dynamic typing allows for developers to just "do what works". I have a pretty simple example of this - let's look at the method #factorial
result := 10 factorial.
result inspect.
That gives us:

Ok, that doesn't seem exciting - we ended up with a SmallInteger object. However, now let's try this one:
result := 100 factorial.
result inspect

The nice thing here is that we didn't have to do anything special - in the process of getting the answer to the second question, the SmallInteger object got promoted up to a LargePositiveInteger, and I didn't need to do anything - no setting up of interfaces, no casting, no need to ensure that all factorials produce LargePositiveInteger objects - they get created when they are needed. Developers can do that themselves, btw - the library does this kind of thing with numbers, you can do similar things with your own objects as needed.
The bottom line - Smalltalk stays out of your way, and lets you solve the problem at hand. Instead of having the satisfy the anal retentive needs of the compiler.


Comments
coercion
[ Troy Brumley] April 18, 2006 14:12:37.698
Comment by Troy Brumley
At this level, you're not explaing it enough to make it understandable from magic. Sometimes it helps to understand those underlying mechanics even if we don't want to code them ourselves. Does anyone know of a good example explanation of Smalltalk numeric type coercion that includes enough of the double dispatch stuff to get the point across without sounding too much like "inside baseball"?
But the point that at the level of "my code" I don't have to worry about this is very important. I don't have to worry about what type of numeric variable to use, I just give the variable a name and run with it.
a pretty simple example
[Isaac Gouy] April 18, 2006 15:35:12.773
Developers can do that themselves
a pretty simple exampleiirc unlike other objects, SmallIntegers are tagged integers, encoded directly in the object pointer - how can developers do that themselves, with their own objects?
we didn't have to do anything special
afaict this is an example of arbitrary precision arithmetic and has little to do with "everything is an object" or "dynamic typing". A statically-type-checked functional programming language like SML can provide the same functionality. (Unlike most Smalltalk implementations, SML additionally provides fixed-precision integer representations.)
Re: Smalltalk Simplicity and Consistency
[ James Robertson] April 18, 2006 18:10:43.022
Comment by James Robertson
Isaac
You might want to look at how collections grow.
[Isaac Gouy] April 18, 2006 19:30:07.749
James, why might I want to look at how collections grow?
A little effort...
[ James Robertson] April 18, 2006 21:05:23.430
Comment by James Robertson
Expend the effort and you'll see.
[Isaac Gouy] April 18, 2006 22:53:06.993
James, my guess is that you think the code illustrates a point you wish to make, but I'm afraid looking at the code does not tell me what point you wish to make - you need to do that.
The point is clear
[Ravi Venkataraman] April 19, 2006 3:00:49.268
Isaac, the point that James was making was clear: Smalltalk code is much simpler than comparable mainstream languages code like that in Java or C++ or C#. One of the reasons why this is so is that one does not have to specify the type of the variable/result.
This also happens to be the way humans think - we think of the factorial of a number as another much larger number, not as a BigInteger. The fact that statically typed languages force you to specify sub-types such as integer, large integer, etc., causes code bloat.
This incidentally is a feature of all dynamically typed languages, not Smalltalk in particular.
Ravi
You're wasting your keystrokes, Ravi
[ John Rubier] April 19, 2006 3:17:59.915
Comment by John Rubier
He doesn't care. He never will care. He lost a Smalltalk job and ended up having to be a Java flunkie. Now whenever he doesn't take his meds, he gets upset and defensive and has to justify his existence on James blog and anywhere else ST is mentioned.
Anyone who has used Java and tries Smalltalk will see that it's more efficient and elegant and is true freedom in comparison (not perfect, but what is?)
name calling is failure
[Isaac Gouy] April 19, 2006 12:49:05.730
John Rubier, name calling is not going to make Smalltalk more popular.
speak for himself
[Isaac Gouy] April 19, 2006 12:57:28.220
Ravi, we can make all kinds of guesses about what James might mean but I'd prefer not to put words in his mouth.
The title says it all
[Ravi ] April 19, 2006 14:40:31.421
Isaac, the title of the article conveys the essence - that Smalltalk is simple. James elaborated on it by giving an example that showed that the developer can focus on solving the problem, while the VM takes care of routine things like scale and precision of numbers, data types, etc. He contrasted this with mainstream languages by asking if it could be done so easily in them. I gave my understanding/interpretation of his words.
Words are the only means we have on conveying meaning, and so we are restricted to using them. So, I do not think I am putting words into his mouth when I give my interpretation.
[Isaac Gouy] April 19, 2006 15:13:00.637
He contrasted this with mainstream languages by asking if it could be done so easily in them.
No Ravi, you were the first person to mention "mainstream languages code like that in Java or C++ or C#".
And I asked for clarification about James' comment "You might want to look at how collections grow" not about the blog entry.
[Ravi] April 19, 2006 15:47:29.160
Here are some words from the article, "The bottom line - Smalltalk stays out of your way, and lets you solve the problem at hand."
Given James's known feelings about the mainstream languages, it is clear that he is implicitly referring to mainstream languages that get in your way.
Anyway, it is not that important who said it explicitly or implicitly, so I won't comment on this anymore.
Re: Smalltalk Simplicity and Consistency
[ John Rubier] April 19, 2006 23:12:53.247
Comment by John Rubier
I wasn't name calling. And I dare say that you aren't helping make Smalltalk popular either.
I know that you realize Smalltalk is better in many, many way than Java. Perhaps my guess as to the reason that you perform Troll duty on all Smalltalk related discussions is off base. The impression however, stands.
About Isaac Gouy
[Dick Ford] April 20, 2006 2:08:27.012
He's a know programming forums troll. Just call him question boy. He normally doesn't have the courage to actually make an assertion, but meeks around with his troll questions. This guy is just a scumbag, plain and simple. Google his name you'll see what he's all about.
sticks & stones
[Isaac Gouy] April 20, 2006 12:19:57.019
Why the bad blood?
[Avi Bryant] April 21, 2006 0:58:38.266
[Isaac Gouy] April 21, 2006 11:59:18.927
Some folk find questions threatening, some folk enjoy name-calling.