Delay for: 60 seconds vs. Delay forSeconds: 60.

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

Delay for: 60 seconds vs. Delay forSeconds: 60.

Andreas.Raab
Hi there -

I just realized how silly it is to write code like:

        (Delay forSeconds: 60) wait.
        (Delay forMilliseconds: 1000) wait.

when we have units available and might as well say:

        (Delay for: 60 seconds) wait.
        (Delay for: 5 days + 3 hours + 17 minutes) wait.

What do people think about this? Overkill or just right?

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

Re: Delay for: 60 seconds vs. Delay forSeconds: 60.

Frank Shearar
Andreas Raab wrote:

> Hi there -
>
> I just realized how silly it is to write code like:
>
>     (Delay forSeconds: 60) wait.
>     (Delay forMilliseconds: 1000) wait.
>
> when we have units available and might as well say:
>
>     (Delay for: 60 seconds) wait.
>     (Delay for: 5 days + 3 hours + 17 minutes) wait.
>
> What do people think about this? Overkill or just right?


I reckon the latter looks really nice. Just that bit easier to read.
Especially the "5 days + 3 hours" part!

frank

Reply | Threaded
Open this post in threaded view
|

Re: Delay for: 60 seconds vs. Delay forSeconds: 60.

Göran Krampe
Hi!

Frank Shearar wrote:

> Andreas Raab wrote:
>> Hi there -
>>
>> I just realized how silly it is to write code like:
>>
>>     (Delay forSeconds: 60) wait.
>>     (Delay forMilliseconds: 1000) wait.
>>
>> when we have units available and might as well say:
>>
>>     (Delay for: 60 seconds) wait.
>>     (Delay for: 5 days + 3 hours + 17 minutes) wait.
>>
>> What do people think about this? Overkill or just right?

Presuming we have no real performance issue I would say the latter is
probably what we should use - earlier we didn't have Durations in the
library, but now that we do we should probably go "all the way" to get
all the polymorphic glory.

So +1, and same probably goes for other similar situations :)

regards, Göran


Reply | Threaded
Open this post in threaded view
|

Re: Delay for: 60 seconds vs. Delay forSeconds: 60.

Frank Shearar
Göran Krampe wrote:

> Hi!
>
> Frank Shearar wrote:
>> Andreas Raab wrote:
>>> Hi there -
>>>
>>> I just realized how silly it is to write code like:
>>>
>>>     (Delay forSeconds: 60) wait.
>>>     (Delay forMilliseconds: 1000) wait.
>>>
>>> when we have units available and might as well say:
>>>
>>>     (Delay for: 60 seconds) wait.
>>>     (Delay for: 5 days + 3 hours + 17 minutes) wait.
>>>
>>> What do people think about this? Overkill or just right?
>
> Presuming we have no real performance issue I would say the latter is
> probably what we should use - earlier we didn't have Durations in the
> library, but now that we do we should probably go "all the way" to get
> all the polymorphic glory.

There are few things more annoying to me than having to constantly check
the units of that integer you need to pass in to a function: is that
Timeout parameter in milliseconds or seconds? Using Durations everywhere
solves the problem.

frank

Reply | Threaded
Open this post in threaded view
|

Re: Delay for: 60 seconds vs. Delay forSeconds: 60.

Stéphane Rollandin
In reply to this post by Andreas.Raab

I usually use the
(5 days + 3 hours + 17 minutes) asDelay wait
idiom.

Stef

> I just realized how silly it is to write code like:
>
> (Delay forSeconds: 60) wait.
> (Delay forMilliseconds: 1000) wait.
>
> when we have units available and might as well say:
>
> (Delay for: 60 seconds) wait.
> (Delay for: 5 days + 3 hours + 17 minutes) wait.
>
> What do people think about this? Overkill or just right?



Reply | Threaded
Open this post in threaded view
|

Re: Delay for: 60 seconds vs. Delay forSeconds: 60.

Stephen Pair
In reply to this post by Andreas.Raab
On Fri, Jan 8, 2010 at 2:21 AM, Andreas Raab <[hidden email]> wrote:
Hi there -

I just realized how silly it is to write code like:

       (Delay forSeconds: 60) wait.
       (Delay forMilliseconds: 1000) wait.

when we have units available and might as well say:

       (Delay for: 60 seconds) wait.
       (Delay for: 5 days + 3 hours + 17 minutes) wait.

What do people think about this? Overkill or just right?

Cheers,
 - Andreas

I think it is great and I think what is needed is a standardized units implementation in the base squeak.  There are plenty of units implementations that have been around for years (some that are very well designed and thought out) and I think the main barrier to wide adoption has been the simple fact that none of them have been included in a base smalltalk distribution. 

- Stephen


Reply | Threaded
Open this post in threaded view
|

Re: Delay for: 60 seconds vs. Delay forSeconds: 60.

K. K. Subramaniam
In reply to this post by Andreas.Raab
On Friday 08 January 2010 12:51:19 pm Andreas Raab wrote:
> when we have units available and might as well say:
>
>         (Delay for: 60 seconds) wait.
>         (Delay for: 5 days + 3 hours + 17 minutes) wait.
>
> What do people think about this? Overkill or just right?
I prefer
   60 seconds wait.

;-) .. Subbu

Reply | Threaded
Open this post in threaded view
|

Re: Delay for: 60 seconds vs. Delay forSeconds: 60.

Stephen Pair
In reply to this post by Stephen Pair


On Fri, Jan 8, 2010 at 9:58 AM, Stephen Pair <[hidden email]> wrote:
On Fri, Jan 8, 2010 at 2:21 AM, Andreas Raab <[hidden email]> wrote:
Hi there -

I just realized how silly it is to write code like:

       (Delay forSeconds: 60) wait.
       (Delay forMilliseconds: 1000) wait.

when we have units available and might as well say:

       (Delay for: 60 seconds) wait.
       (Delay for: 5 days + 3 hours + 17 minutes) wait.

What do people think about this? Overkill or just right?

Cheers,
 - Andreas

I think it is great and I think what is needed is a standardized units implementation in the base squeak.  There are plenty of units implementations that have been around for years (some that are very well designed and thought out) and I think the main barrier to wide adoption has been the simple fact that none of them have been included in a base smalltalk distribution. 

- Stephen

Never mind...I just realized that you weren't talking about units in general, but just about the Delay protocol.  But, I do think putting a generalized units framework in the base squeak to encourage adoption would be a good idea.

- Stephen 



Reply | Threaded
Open this post in threaded view
|

Re: Delay for: 60 seconds vs. Delay forSeconds: 60.

Bert Freudenberg
In reply to this post by K. K. Subramaniam
On 08.01.2010, at 15:58, K. K. Subramaniam wrote:

>
> On Friday 08 January 2010 12:51:19 pm Andreas Raab wrote:
>> when we have units available and might as well say:
>>
>>        (Delay for: 60 seconds) wait.
>>        (Delay for: 5 days + 3 hours + 17 minutes) wait.
>>
>> What do people think about this? Overkill or just right?
> I prefer
>   60 seconds wait.
>
> ;-) .. Subbu
>

+1

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: Delay for: 60 seconds vs. Delay forSeconds: 60.

Levente Uzonyi-2
In reply to this post by K. K. Subramaniam
On Fri, 8 Jan 2010, K. K. Subramaniam wrote:

> On Friday 08 January 2010 12:51:19 pm Andreas Raab wrote:
>> when we have units available and might as well say:
>>
>>         (Delay for: 60 seconds) wait.
>>         (Delay for: 5 days + 3 hours + 17 minutes) wait.
>>
>> What do people think about this? Overkill or just right?
> I prefer
>   60 seconds wait.

An #asDelay send doesn't make much difference IMO, and it just works:
60 seconds asDelay wait.
Though #wait can be added to Duration as self asDelay wait.


Levente

>
> ;-) .. Subbu
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Delay for: 60 seconds vs. Delay forSeconds: 60.

K. K. Subramaniam
On Friday 08 January 2010 09:03:19 pm Levente Uzonyi wrote:
> An #asDelay send doesn't make much difference IMO, and it just works:
> 60 seconds asDelay wait.
> Though #wait can be added to Duration as self asDelay wait.
All senders of asDelay use it for wait, so why spread it all over?

Subbu

Reply | Threaded
Open this post in threaded view
|

Re: Delay for: 60 seconds vs. Delay forSeconds: 60.

Stéphane Rollandin
In reply to this post by Levente Uzonyi-2
> Though #wait can be added to Duration as self asDelay wait.

+1

Stef



Reply | Threaded
Open this post in threaded view
|

Re: Delay for: 60 seconds vs. Delay forSeconds: 60.

Levente Uzonyi-2
In reply to this post by K. K. Subramaniam
On Fri, 8 Jan 2010, K. K. Subramaniam wrote:

> On Friday 08 January 2010 09:03:19 pm Levente Uzonyi wrote:
>> An #asDelay send doesn't make much difference IMO, and it just works:
>> 60 seconds asDelay wait.
>> Though #wait can be added to Duration as self asDelay wait.
> All senders of asDelay use it for wait, so why spread it all over?

#asDelay is more general, since it can convert a Duration to a Delay. You
can store the delay an send #wait later to it. And it's compatible across
forks and versions.


Levente

>
> Subbu
>

Reply | Threaded
Open this post in threaded view
|

Re: Delay for: 60 seconds vs. Delay forSeconds: 60.

Julian Fitzell-2
On Fri, Jan 8, 2010 at 8:22 AM, Levente Uzonyi <[hidden email]> wrote:
On Fri, 8 Jan 2010, K. K. Subramaniam wrote:

On Friday 08 January 2010 09:03:19 pm Levente Uzonyi wrote:
An #asDelay send doesn't make much difference IMO, and it just works:
60 seconds asDelay wait.
Though #wait can be added to Duration as self asDelay wait.
All senders of asDelay use it for wait, so why spread it all over?

#asDelay is more general, since it can convert a Duration to a Delay. You can store the delay an send #wait later to it. And it's compatible across forks and versions.

<rant>
Yes, Squeak loves creating protocol explosion by duplicating the protocol of one class all over the place to where it "might be useful". This makes it more difficult to write portable or consistent code, makes namespace collisions more likely, and means you have to wade through way more protocol on each class looking for what you want.

There are many, many things that might happen over a particular duration. Let's take the JQuery support in Seaside as an example. There are dozens of effects, all of which can run over a certain number of milliseconds. Should we add #hide, #slideUp, #slideDown, #toggle, #fadeIn, etc. to Duration? Just because something *uses* Durations, does not mean its protocol should be duplicated on Duration.

Also, what happens if another, better implementation of a Delay-like class comes along. Now we'd want *that* to be used by Duration>>wait, but it has slightly different behaviour, so now we'd have to add #wait2 or #waitNew or something. It's a mess.

Writing "5 seconds asDelay wait" is neither arduous nor unclear.

To be honest, even #asDelay is slightly (though less) suspect to me unless you are implementing it for polymorphism across multiple classes. I realize #asDelay already exists (with only one implementation!), so it's probably not worth talking about in this case, but "(Delay for: 5 seconds) wait" just isn't that bad.

And while I'm ranting around this area, I just noticed Time>>asDuration and DateAndTime>>asDuration. What the heck is up with those? The logical duration of both those classes is zero (as already implemented by #duration). If you're going to implement #asDuration for polymorphism (and why would you, honestly, given that they have a duration of zero?), why wouldn't you implement them to call #duration? It makes no sense for a time of 1:33pm to have a duration of 13 hours and 33 minutes. Several internal methods want to know the duration between midnight and the specified time; fine, so add a private method #durationFromMidnight or something. I'm guessing we thought it was cute to be able to do "3 days + (Time hour: 13 minute: 33 second: 0)" but as a result "(Delay for: Time noon) wait" would wait for 12 hours. It makes no sense (except possibly if it is exactly midnight when you run that).

Please, let's try to keep classes' protocols directly related to their responsibilities.
</rant>

Julian


Reply | Threaded
Open this post in threaded view
|

Re: Delay for: 60 seconds vs. Delay forSeconds: 60.

Colin Putney

On 2010-01-08, at 10:37 AM, Julian Fitzell wrote:

> Yes, Squeak loves creating protocol explosion by duplicating the protocol of one class all over the place to where it "might be useful". This makes it more difficult to write portable or consistent code, makes namespace collisions more likely, and means you have to wade through way more protocol on each class looking for what you want.
>
> There are many, many things that might happen over a particular duration. Let's take the JQuery support in Seaside as an example. There are dozens of effects, all of which can run over a certain number of milliseconds. Should we add #hide, #slideUp, #slideDown, #toggle, #fadeIn, etc. to Duration? Just because something *uses* Durations, does not mean its protocol should be duplicated on Duration.

+1.
 
This kind of thing makes it harder to carve the image into packages. I think "(Delay for: 5 seconds) wait" is fine.

Colin