new Smalltalk programmer's thoughts

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
33 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: new Smalltalk programmer's thoughts

Wolfgang Helbig-2
Hi tim,
you mentioned:
>Ultimately, Smalltalk, like all other languages, systems, cars,  
>planes, boats, foods, political parties, comics, games etc is what it  
>is. If you like it - Enjoy!

I certainly do!

But I must admit that once in a while I get most enjoyment by not accepting "it"
as it is. There are days I dare to think about adapting it to meet my needs.

Even if this means considering "mainstream" or "low level" programming idioms
like counting from zero.

Sorry about my bad habits -:)


Greetings
Wolfgang

--
Weniger, aber besser.


Reply | Threaded
Open this post in threaded view
|

Re: new Smalltalk programmer's thoughts

stéphane ducasse-2
Hi wolfgang

I think that we should change if this is important.
So Smalltalk should not be a prison or a dusty museum

Stef

On 2 mai 06, at 07:47, Wolfgang Helbig wrote:

> Hi tim,
> you mentioned:
>> Ultimately, Smalltalk, like all other languages, systems, cars,
>> planes, boats, foods, political parties, comics, games etc is what it
>> is. If you like it - Enjoy!
>
> I certainly do!
>
> But I must admit that once in a while I get most enjoyment by not  
> accepting "it"
> as it is. There are days I dare to think about adapting it to meet  
> my needs.
>
> Even if this means considering "mainstream" or "low level"  
> programming idioms
> like counting from zero.
>
> Sorry about my bad habits -:)
>
>
> Greetings
> Wolfgang
>
> --
> Weniger, aber besser.
>
>


Reply | Threaded
Open this post in threaded view
|

Re: new Smalltalk programmer's thoughts

Louis LaBrunda
In reply to this post by Wolfgang Helbig-2
Hi Wolfgang,

>But I must admit that once in a while I get most enjoyment by not accepting "it"
>as it is. There are days I dare to think about adapting it to meet my needs.

>Even if this means considering "mainstream" or "low level" programming idioms
>like counting from zero.

>Sorry about my bad habits -:)

This is not a bad habit, it is exactly what you should do with Smalltalk.
If a class does most of what you want you can and should extend or subclass
it to do exactly what you want.  In the case of arrays you can make your
own class of array that indexes any way you want.  If you want to index it
with negative numbers you can.  There may or may not be some performance
hit in doing so and you will need to decide if it is worth it.  It could be
that there is some source of the negative indexes that is out of your
control and the easiest way to handle and use them is to make your own
array class that uses them.  This is what Smalltalk is all about and not
too easy in most other languages.

Lou
-----------------------------------------------------------
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:[hidden email] http://www.Keystone-Software.com


Reply | Threaded
Open this post in threaded view
|

Re: new Smalltalk programmer's thoughts

Chris Muller
In reply to this post by Wolfgang Helbig-2
Stream positioning is *between* elements, array-indexing is *at* a particular element.
 
 I see them as two different kinds of access, both 1-based..
 
 

----- Original Message ----
From: Wolfgang Helbig <[hidden email]>
To: [hidden email]
Sent: Monday, May 1, 2006 3:45:17 PM
Subject: Re: new Smalltalk programmer's thoughts

Hi Yoshiki,
as you and others pointed out:
>  Also, in Smalltalk, Streams are 0-based as nicolas and others
>mentioned.
>  The AltoFileStream should've follow this convension, instead of
>allowing [1..size] indices.

I agree! It not only *should* follow this convention, but it *must* follow it.

After all, I programmed AltoFileStream to be used by the Hobbes Emulator, which
expects a FileStream to read the snapshot. So I subclassed FileStream and tried
to implement its protocol. Later I found out, that ReadStream suffices for this
purpose. Anyway, I had to implement the semantics of #postion and #position: as
expected by the Hobbes Emulator. Since I didn't find a specification of that
protocol, I naively assumed that position is supposed to be in [1..size]. After
all, this is the natural range of indexes in Smalltalk, isn't it?

But I was utterly wrong, which I found out when I tried to make Hobbes read the
snapshot from an AltoDisk.

The position is supposed to be in range [0..size]. Which looks very unnatural to
me. With this range, position looses the nice property of being a valid index.
So you have to make sure you never access the byte indexed by the current
position. Instead you always use current position + 1. Unix files are more
elegant in this respect. Their position is in the range [0..size), which happens
to be the range of valid "Unix indexes". And I feel much more comfortable with
[0..size) than with [0..size] or [1..size].

Thanks to everyone on this list for their answers! I've learned a lot!

Greetings
Wolfgang, a humble programmer
--
Weniger, aber besser.







Reply | Threaded
Open this post in threaded view
|

Re: new Smalltalk programmer's thoughts

Wolfgang Helbig-2
In reply to this post by Wolfgang Helbig-2
Hi Stef,
you thought:
>...that we should change if this is important.
>So Smalltalk should not be a prison or a dusty museum

It shouldn't and it isn't.

But the changes I'd need in this case are reaching too far. They'd include:
- Upper bounds of integer intervals are exclusive and lower bounds inclusive
- Index ranges start at zero
- The positions of Positionable Streams would take the same values as
  the indexed variables of their underlying collections.

With theses changes predicates involving indexes and positions get more elegant.
This in turn lessens the burden you face when formulating specifications of
methods and reasoning about methods to prove that they meet the specification.

This in turn is the only technique I know of that saves you from "off by one"
errors in particular and "bugs" in general.

So the changes *are* important.

And hard to implement in Smalltalk.

Or, viewed as biological species, Squeak and even Smalltalk-80 evolved to a
level where they lost the flexibility to meet the "new" challenge of switching
from the dark art of medieval metaphors to the scientific technique of logical
reasoning.

By the way, at
        http://people.squeakfoundation.org/article/58.html
I posted another "challenge". It is quite harmless. :-)

Greetings,
Wolfgang

--
Weniger, aber besser.


Reply | Threaded
Open this post in threaded view
|

Re: new Smalltalk programmer's thoughts

Laurence Rozier


On 5/6/06, Wolfgang Helbig <[hidden email]> wrote:

This in turn is the only technique I know of that saves you from "off by one"
errors in particular and "bugs" in general.

So the changes *are* important.

For you and those who share your POV. Others who have been coding in Smalltalk for over 30 years apparently have a different POV since it is quite possible to adapt Squeak to your POV and they haven't done so. Personally in over 20 years of Smalltalk coding, I've rarely seen any "off by one" errors. You don't have to move too far up the food chain away from machine language for that to happen.

And hard to implement in Smalltalk.

Or, viewed as biological species, Squeak and even Smalltalk-80 evolved to a
level where they lost the flexibility to meet the "new" challenge of switching
from the dark art of medieval metaphors to the scientific technique of logical
reasoning.

Squeak is very much capable of adapting to the needs you describe above. Whether or not the cost/benefit tradeoffs make sense only you can determine. A lot of work can be eliminated if you don't care about any of the existing tools. When Spoon arrives it will be much easier to do what would have to be done by hand or by judicious Monticello scripting. Squeak is so flexible that you could even have both solutions existing within the same image using some type of isolated project or island approach. The nicest thing is that you don't have to take anyone else's word for it as you've got all the source code you need to nudge Squeak's evolution in whatever direction you want. It might be good to be mindful that complex species don't evolve by optimizing their chemical bonding, let alone the  underlying quantum chemical processes. Nature it appears, agrees with Ralph - program at a high level!

Cheers,

Laurence

By the way, at
         http://people.squeakfoundation.org/article/58.html
I posted another "challenge". It is quite harmless. :-)

Greetings,
Wolfgang

--
Weniger, aber besser.





Reply | Threaded
Open this post in threaded view
|

Re: new Smalltalk programmer's thoughts

Laurence Rozier


On 5/6/06, Laurence Rozier <[hidden email]> wrote:

You don't have to move too far up the food chain away from machine language for that to happen.


I also meant to say that when we finally design machines to adapt to humans rather than the other way around, you won't have to move at all. Such machines will still have the ability to converse with anyone who prefers today's machine language idioms.


Cheers,

Laurence


Reply | Threaded
Open this post in threaded view
|

Re: new Smalltalk programmer's thoughts

Bill Spight
In reply to this post by Wolfgang Helbig-2
Dear Wolfgang,


> So the changes *are* important.
>
> And hard to implement in Smalltalk.
>
How have you tried to implement them? Have you used the debugger? Squeak
has some surprises on a low level, but you might only have to make a few
simple changes to produce a dialect of Squeak that indexes from 0
instead of 1. Also, as has been suggested, you can create a class of
zero-based arrays.


> Or, viewed as biological species, Squeak and even Smalltalk-80 evolved
> to a
> level where they lost the flexibility to meet the "new" challenge of
> switching
> from the dark art of medieval metaphors to the scientific technique of
> logical
> reasoning.

Isn't flexibility a hallmark of Smalltalk and Squeak?

And we are not talking about logical reasoning. Consider the spatial
metaphor of stacking blocks on top of each other. (For convenience I am
going to use the right direction for up.)

     | Bloc | Block | Block | ...

Here is a natural numbering for the blocks.

     | Block1 | Block2 | Block3 | ...

(You can also count top down.) Nothing illogical about that.

Now let's index the space.

     |0 Block |1 Block |2 Block |3 ...

It is natural to make the ground the origin for the up-down axis, and
give it a value of 0. Nothing illogical about that, either. Furthermore,
for more complex spatial relationships, it is convenient to have a 0. It
can simplify expressions and calculations. It may also be convenient to
identify the block on the ground as Block0, and go from there. That is
what you consider logical, but it is only one possibility.

How you assign numerals to things is a matter of convention and
convenience, not logic. A lot depends upon the domain of application.
For that reason you really want the flexibility to number collections as
you see fit. Doesn't Squeak offer that flexibility?

(I am not used to Squeak, myself, but I have some experience with an
earlier Smalltalk.)

Best wishes,

Bill


Reply | Threaded
Open this post in threaded view
|

Re: new Smalltalk programmer's thoughts

tblanchard
In reply to this post by Wolfgang Helbig-2

On May 6, 2006, at 12:21 AM, Wolfgang Helbig wrote:

But the changes I'd need in this case are reaching too far. They'd include:

- Upper bounds of integer intervals are exclusive and lower bounds inclusive

- Index ranges start at zero

- The positions of Positionable Streams would take the same values as

  the indexed variables of their underlying collections.


So the changes *are* important.

And hard to implement in Smalltalk.

Really?? I think I could implement this api in a few minutes.

Instead of 1 to: 5 do: [:n|...]

you use method

1 upTo: 5 do: [:n | ... ]

which is trivially implemented on Number as 

upTo: n do: aBlock

^self to: (n-1) do: aBlock

etc.

For collections, provide an offset wrapper that implements SequenceableCollection's interface, but shifts indices by the offset.  

Done.  You don't have to change all of Smalltalk to get what you want (and most of us would prefer you not change the code we are using, thanks).  You can certainly extend it to get the api you want.




Reply | Threaded
Open this post in threaded view
|

Re: new Smalltalk programmer's thoughts

timrowledge

On 6-May-06, at 9:26 AM, Todd Blanchard wrote:

>
> For collections, provide an offset wrapper that implements  
> SequenceableCollection's interface, but shifts indices by the offset.
>
> Done.  You don't have to change all of Smalltalk to get what you  
> want (and most of us would prefer you not change the code we are  
> using, thanks).  You can certainly extend it to get the api you want.
CArray. Or CArrayAccessor or something similar. Used in some of the  
vm/plugin simulation stuff in the VMMaker package.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Useful random insult:- Been playing with the pharmacy section again.



Reply | Threaded
Open this post in threaded view
|

Re: new Smalltalk programmer's thoughts

Wolfgang Helbig-2
In reply to this post by Wolfgang Helbig-2
Hi Bill,

thanks for your reply!

You asked:

>How have you tried to implement them?

Nope. I decided it is easier to implement the protocol of my class as expected
by the client, the Hobbes Emulator, than to implement a novice protocol and
to adapt the client to the new protocol. And this decision turned out
to be right -- after I learned to cope with the ranges of indexes and positions.
 
>Have you used the debugger?

No. I prefer logical reasoning. :-)

>Isn't flexibility a hallmark of Smalltalk and Squeak?

It is.

>And we are not talking about logical reasoning. Consider the spatial

Hmm? I intended to talk just about logical reasoning. And how some deep
design decisions regarding the range of indexes in sequenceable collections
and positionable streams made it hard for me to prove my implementation correct
while writing it. That's all.

>metaphor of stacking blocks on top of each other. (For convenience I am
>going to use the right direction for up.)
>
>     | Bloc | Block | Block | ...
>
>Here is a natural numbering for the blocks.
>
>     | Block1 | Block2 | Block3 | ...
>
>(You can also count top down.) Nothing illogical about that.

Your are right!

>
>Now let's index the space.
>
>     |0 Block |1 Block |2 Block |3 ...
>
>It is natural to make the ground the origin for the up-down axis, and
>give it a value of 0. Nothing illogical about that, either.

Again, you are right!

>for more complex spatial relationships, it is convenient to have a 0. It
>How you assign numerals to things is a matter of convention and
>convenience, not logic.

Right!

>A lot depends upon the domain of application.
>For that reason you really want the flexibility to number collections as
>you see fit. Doesn't Squeak offer that flexibility?

It sure does!

Greetings
Wolfgang

--
Weniger, aber besser.


Reply | Threaded
Open this post in threaded view
|

Re: new Smalltalk programmer's thoughts

stéphane ducasse-2
In reply to this post by Wolfgang Helbig-2
> But the changes I'd need in this case are reaching too far.

Indeed :)

> They'd include:
> - Upper bounds of integer intervals are exclusive and lower bounds  
> inclusive
> - Index ranges start at zero
> - The positions of Positionable Streams would take the same values as
>   the indexed variables of their underlying collections.
>
> With theses changes predicates involving indexes and positions get  
> more elegant.
> This in turn lessens the burden you face when formulating  
> specifications of
> methods and reasoning about methods to prove that they meet the  
> specification.
>
> This in turn is the only technique I know of that saves you from  
> "off by one"
> errors in particular and "bugs" in general.
>
> So the changes *are* important.
>
> And hard to implement in Smalltalk.

Indeed.

> Or, viewed as biological species, Squeak and even Smalltalk-80  
> evolved to a
> level where they lost the flexibility to meet the "new" challenge  
> of switching
> from the dark art of medieval metaphors to the scientific technique  
> of logical
> reasoning.

This is clear that I was thinking about gemstone possibility of  
having multiple
versions at the same time as a way to support a muc smoother evolution.

Stef

Reply | Threaded
Open this post in threaded view
|

Re: new Smalltalk programmer's thoughts

Wolfgang Helbig-2
In reply to this post by Wolfgang Helbig-2
Hi Bill,

You asked me:

>> >Have you used the debugger?
>>
and I answered:

>> No. I prefer logical reasoning. :-)
>>
>I have found the debugger to be quite valuable in Smalltalk to find out
>what is actually going on. Smalltalk, like probably most computer
>programs, is not very well documented.

You are right! And I prefer you weren't. :-)

On the other hand, Smalltalk-80 is quite well documented in the Colored Books.

Greetings,
Wolfgang
--
Weniger, aber besser.


12