Determining dialect programmatically

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

Determining dialect programmatically

Casey Ransberger-2
I'm thinking I might want to do some stuff conditionally based on platform, is the best way to find out whether I'm on Pharo/Squeak/Cuis?

(SystemVersion current version beginsWith: 'Cuis') ifTrue: [ #foo ]
(SystemVersion current version beginsWith: 'Squeak') ifTrue: [ #bar ]
(SystemVersion current version beginsWith: 'Pharo') ifTrue: [ #baz ]

--
Casey Ransberger

_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
Reply | Threaded
Open this post in threaded view
|

Re: Determining dialect programmatically

Juan Vuletich-4
Hi Casey,

Casey Ransberger wrote:
> I'm thinking I might want to do some stuff conditionally based on
> platform, is the best way to find out whether I'm on Pharo/Squeak/Cuis?
>
> (SystemVersion current version beginsWith: 'Cuis') ifTrue: [ #foo ]
> (SystemVersion current version beginsWith: 'Squeak') ifTrue: [ #bar ]
> (SystemVersion current version beginsWith: 'Pharo') ifTrue: [ #baz ]
>
> --
> Casey Ransberger

This sounds right to me. But if you want to add #isCuis, #isSqueak,
#isPharo, etc to SystemDictionary or some base class, that would be ok
too. You'd need to convince the Squeak and Pharo folks to add them too.
It looks like they would agree.

Cheers,
Juan Vuletich

_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
Reply | Threaded
Open this post in threaded view
|

Re: Determining dialect programmatically

David T. Lewis
On Sun, Jan 27, 2013 at 12:22:45PM -0300, Juan Vuletich wrote:

> Hi Casey,
>
> Casey Ransberger wrote:
> >I'm thinking I might want to do some stuff conditionally based on
> >platform, is the best way to find out whether I'm on Pharo/Squeak/Cuis?
> >
> >(SystemVersion current version beginsWith: 'Cuis') ifTrue: [ #foo ]
> >(SystemVersion current version beginsWith: 'Squeak') ifTrue: [ #bar ]
> >(SystemVersion current version beginsWith: 'Pharo') ifTrue: [ #baz ]
> >
> >--
> >Casey Ransberger
>
> This sounds right to me. But if you want to add #isCuis, #isSqueak,
> #isPharo, etc to SystemDictionary or some base class, that would be ok
> too. You'd need to convince the Squeak and Pharo folks to add them too.
> It looks like they would agree.

Just a note of caution - keeping up with these differences can be a real
pain. Pharo is particularly challenging, because there are multiple incompatible
versions of Pharo, and some versions raise deprecation warnings about the
previously correct usage in another version. This means that testing for
#isPharo is usually not sufficient, because Pharo 1.4 is very different from
Pharo 2.0. The same would be true for Squeak but to a much lesser degree.

Here are a couple of compatibility methods from OSProcess to illustrate:

   OSProcess class>>directoryEntryNames: path
      "Use FileReference if available, otherwise use traditional FileDirectory"
   
      ^ (path respondsTo: #asFileReference)
         ifTrue: [ (path perform: #asFileReference) children collect: [:e | e perform: #basename] ]
         ifFalse: [ ((Smalltalk at: #FileDirectory) on: path) entries collect: [:e | e name] ]
   
   
   OSProcess class>>osVersion
      "After Squeak version 3.6, #osVersion was moved to SmalltalkImage. Some
      versions of Pharo move this to OSPlatform and issue deprecation warnings
      about the other usages."
   
      ^ (((Smalltalk hasClassNamed: #OSPlatform)
            and: [(Smalltalk at: #OSPlatform)
                  respondsTo: #osVersion])
         ifTrue: [Smalltalk at: #OSPlatform]
         ifFalse: [((Smalltalk classNamed: 'SmalltalkImage')
               ifNil: [^ Smalltalk osVersion]) current]) osVersion

I'm sure there are better ways to do this, but keeping up with multiple image
versions can be a lot of work and the code can get quite ugly.

(I have not yet tried updating OSProcess for Cuis, but I do want to do so).

Dave


_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
Reply | Threaded
Open this post in threaded view
|

Re: Determining dialect programmatically

Hannes Hirzel
Casey

(SystemVersion current version beginsWith: 'Cuis') ifTrue: [ #cuis ]
"Cuis 4.1"

(SystemVersion current version beginsWith: 'Squeak') ifTrue: [ #squeak
]  "Squeak 4.4"

(SystemVersion current version beginsWith: 'Pharo') ifTrue: [ #pharo ]
 "Pharo 2.0"

works fine in every variant. So this solution is preferable as it does
not involve any change on any Squeak variant. You can go ahead an do
not need any change from Squeak or Pharo.

My assumption is that only the GUI is a problem in the comparatively
simple HelpSystem of Torsten Bergmann and that this might give enough
clues to do the right thing? That means choosing the right
hierarchical list morph for the display of help topics.

--Hannes

On 1/27/13, David T. Lewis <[hidden email]> wrote:

> On Sun, Jan 27, 2013 at 12:22:45PM -0300, Juan Vuletich wrote:
>> Hi Casey,
>>
>> Casey Ransberger wrote:
>> >I'm thinking I might want to do some stuff conditionally based on
>> >platform, is the best way to find out whether I'm on Pharo/Squeak/Cuis?
>> >
>> >(SystemVersion current version beginsWith: 'Cuis') ifTrue: [ #foo ]
>> >(SystemVersion current version beginsWith: 'Squeak') ifTrue: [ #bar ]
>> >(SystemVersion current version beginsWith: 'Pharo') ifTrue: [ #baz ]
>> >
>> >--
>> >Casey Ransberger
>>
>> This sounds right to me. But if you want to add #isCuis, #isSqueak,
>> #isPharo, etc to SystemDictionary or some base class, that would be ok
>> too. You'd need to convince the Squeak and Pharo folks to add them too.
>> It looks like they would agree.
>
> Just a note of caution - keeping up with these differences can be a real
> pain. Pharo is particularly challenging, because there are multiple
> incompatible
> versions of Pharo, and some versions raise deprecation warnings about the
> previously correct usage in another version. This means that testing for
> #isPharo is usually not sufficient, because Pharo 1.4 is very different
> from
> Pharo 2.0. The same would be true for Squeak but to a much lesser degree.
>
> Here are a couple of compatibility methods from OSProcess to illustrate:
>
>    OSProcess class>>directoryEntryNames: path
>       "Use FileReference if available, otherwise use traditional
> FileDirectory"
>
>       ^ (path respondsTo: #asFileReference)
>          ifTrue: [ (path perform: #asFileReference) children collect: [:e |
> e perform: #basename] ]
>          ifFalse: [ ((Smalltalk at: #FileDirectory) on: path) entries
> collect: [:e | e name] ]
>
>
>    OSProcess class>>osVersion
>       "After Squeak version 3.6, #osVersion was moved to SmalltalkImage.
> Some
>       versions of Pharo move this to OSPlatform and issue deprecation
> warnings
>       about the other usages."
>
>       ^ (((Smalltalk hasClassNamed: #OSPlatform)
>             and: [(Smalltalk at: #OSPlatform)
>                   respondsTo: #osVersion])
>          ifTrue: [Smalltalk at: #OSPlatform]
>          ifFalse: [((Smalltalk classNamed: 'SmalltalkImage')
>                ifNil: [^ Smalltalk osVersion]) current]) osVersion
>
> I'm sure there are better ways to do this, but keeping up with multiple
> image
> versions can be a lot of work and the code can get quite ugly.
>
> (I have not yet tried updating OSProcess for Cuis, but I do want to do so).
>
> Dave
>
>
> _______________________________________________
> Cuis mailing list
> [hidden email]
> http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
>

_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
Reply | Threaded
Open this post in threaded view
|

Re: Determining dialect programmatically

Hannes Hirzel
In reply to this post by David T. Lewis
On 1/27/13, David T. Lewis <[hidden email]> wrote:

> On Sun, Jan 27, 2013 at 12:22:45PM -0300, Juan Vuletich wrote:
>> Hi Casey,
>>
>> Casey Ransberger wrote:
>> >I'm thinking I might want to do some stuff conditionally based on
>> >platform, is the best way to find out whether I'm on Pharo/Squeak/Cuis?
>> >
>> >(SystemVersion current version beginsWith: 'Cuis') ifTrue: [ #foo ]
>> >(SystemVersion current version beginsWith: 'Squeak') ifTrue: [ #bar ]
>> >(SystemVersion current version beginsWith: 'Pharo') ifTrue: [ #baz ]
>> >
>> >--
>> >Casey Ransberger
>>
>> This sounds right to me. But if you want to add #isCuis, #isSqueak,
>> #isPharo, etc to SystemDictionary or some base class, that would be ok
>> too. You'd need to convince the Squeak and Pharo folks to add them too.
>> It looks like they would agree.
>
> Just a note of caution - keeping up with these differences can be a real
> pain. Pharo is particularly challenging, because there are multiple
> incompatible
> versions of Pharo, and some versions raise deprecation warnings about the
> previously correct usage in another version. This means that testing for
> #isPharo is usually not sufficient, because Pharo 1.4 is very different
> from
> Pharo 2.0. The same would be true for Squeak but to a much lesser degree.
>
> Here are a couple of compatibility methods from OSProcess to illustrate:
>
>    OSProcess class>>directoryEntryNames: path
>       "Use FileReference if available, otherwise use traditional
> FileDirectory"
>
>       ^ (path respondsTo: #asFileReference)
>          ifTrue: [ (path perform: #asFileReference) children collect: [:e |
> e perform: #basename] ]
>          ifFalse: [ ((Smalltalk at: #FileDirectory) on: path) entries
> collect: [:e | e name] ]
>
>
>    OSProcess class>>osVersion
>       "After Squeak version 3.6, #osVersion was moved to SmalltalkImage.
> Some
>       versions of Pharo move this to OSPlatform and issue deprecation
> warnings
>       about the other usages."
>
>       ^ (((Smalltalk hasClassNamed: #OSPlatform)
>             and: [(Smalltalk at: #OSPlatform)
>                   respondsTo: #osVersion])
>          ifTrue: [Smalltalk at: #OSPlatform]
>          ifFalse: [((Smalltalk classNamed: 'SmalltalkImage')
>                ifNil: [^ Smalltalk osVersion]) current]) osVersion

Thank you David for these examples, they are illustrative. In which
repository do you keep the head (or upstream) of OSProcess. I'd like
to have a look at the other compatibility methods you have written.

--Hannes


> I'm sure there are better ways to do this, but keeping up with multiple
> image
> versions can be a lot of work and the code can get quite ugly.
>
> (I have not yet tried updating OSProcess for Cuis, but I do want to do so).
>
> Dave
>
>
> _______________________________________________
> Cuis mailing list
> [hidden email]
> http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
>

_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
Reply | Threaded
Open this post in threaded view
|

Re: Determining dialect programmatically

David T. Lewis
On Sun, Jan 27, 2013 at 06:57:24PM +0000, H. Hirzel wrote:
>
> Thank you David for these examples, they are illustrative. In which
> repository do you keep the head (or upstream) of OSProcess. I'd like
> to have a look at the other compatibility methods you have written.
>
> --Hannes
>

OSProcess is at http://www.squeaksource.com/OSProcess. The latest version
is OSProcess-dtl.76.mcz, and the methods are on the class side of class
OSProcess in category 'version dependent'.

I am working now to make CommandShell (http://www.squeaksource.com/OSProcess)
work on Pharo 2.0. This will have more compatibility methods related to
file system differences, but the approach will be similar to what I did
with OSProcess.

In both cases, I am putting the version-dependent methods for the package
into a single class (either OSProcess or CommandShell) so that I can locate
them easily and find senders of version dependent methods. Hopefully the
updates for Cuis will mainly just require updates to these methods in the
'version dependent' category of OSProcess class.

Dave


_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
Reply | Threaded
Open this post in threaded view
|

Re: Determining dialect programmatically

Hannes Hirzel
Thank you  David, for the reference to the main repository of OSProcess,
http://www.squeaksource.com/OSProcess/

The 13 compatibility methods on the class side of OSProcess will help
us to port other libraries more easily.

A good example of the principle of  'feature detection' as all the
JavaScript libraries do.

Regards
Hannes


On 1/27/13, David T. Lewis <[hidden email]> wrote:

> On Sun, Jan 27, 2013 at 06:57:24PM +0000, H. Hirzel wrote:
>>
>> Thank you David for these examples, they are illustrative. In which
>> repository do you keep the head (or upstream) of OSProcess. I'd like
>> to have a look at the other compatibility methods you have written.
>>
>> --Hannes
>>
>
> OSProcess is at http://www.squeaksource.com/OSProcess. The latest version
> is OSProcess-dtl.76.mcz, and the methods are on the class side of class
> OSProcess in category 'version dependent'.
>
> I am working now to make CommandShell
> (http://www.squeaksource.com/OSProcess)
> work on Pharo 2.0. This will have more compatibility methods related to
> file system differences, but the approach will be similar to what I did
> with OSProcess.
>
> In both cases, I am putting the version-dependent methods for the package
> into a single class (either OSProcess or CommandShell) so that I can locate
> them easily and find senders of version dependent methods. Hopefully the
> updates for Cuis will mainly just require updates to these methods in the
> 'version dependent' category of OSProcess class.
>
> Dave
>
>
> _______________________________________________
> Cuis mailing list
> [hidden email]
> http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
>

_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org

CompatibilityMethodsInOSProcessByDavidLewis.png (138K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Determining dialect programmatically

Juan Vuletich-4
In reply to this post by David T. Lewis
Hi David.

I agree. I'm adding a comment on them, warning about their use.

Cheers,
Juan Vuletich

David T. Lewis wrote:

> On Sun, Jan 27, 2013 at 12:22:45PM -0300, Juan Vuletich wrote:
>  
>> Hi Casey,
>>
>> Casey Ransberger wrote:
>>    
>>> I'm thinking I might want to do some stuff conditionally based on
>>> platform, is the best way to find out whether I'm on Pharo/Squeak/Cuis?
>>>
>>> (SystemVersion current version beginsWith: 'Cuis') ifTrue: [ #foo ]
>>> (SystemVersion current version beginsWith: 'Squeak') ifTrue: [ #bar ]
>>> (SystemVersion current version beginsWith: 'Pharo') ifTrue: [ #baz ]
>>>
>>> --
>>> Casey Ransberger
>>>      
>> This sounds right to me. But if you want to add #isCuis, #isSqueak,
>> #isPharo, etc to SystemDictionary or some base class, that would be ok
>> too. You'd need to convince the Squeak and Pharo folks to add them too.
>> It looks like they would agree.
>>    
>
> Just a note of caution - keeping up with these differences can be a real
> pain. Pharo is particularly challenging, because there are multiple incompatible
> versions of Pharo, and some versions raise deprecation warnings about the
> previously correct usage in another version. This means that testing for
> #isPharo is usually not sufficient, because Pharo 1.4 is very different from
> Pharo 2.0. The same would be true for Squeak but to a much lesser degree.
>
> Here are a couple of compatibility methods from OSProcess to illustrate:
>
>    OSProcess class>>directoryEntryNames: path
>       "Use FileReference if available, otherwise use traditional FileDirectory"
>    
>       ^ (path respondsTo: #asFileReference)
>          ifTrue: [ (path perform: #asFileReference) children collect: [:e | e perform: #basename] ]
>          ifFalse: [ ((Smalltalk at: #FileDirectory) on: path) entries collect: [:e | e name] ]
>    
>    
>    OSProcess class>>osVersion
>       "After Squeak version 3.6, #osVersion was moved to SmalltalkImage. Some
>       versions of Pharo move this to OSPlatform and issue deprecation warnings
>       about the other usages."
>    
>       ^ (((Smalltalk hasClassNamed: #OSPlatform)
>             and: [(Smalltalk at: #OSPlatform)
>                   respondsTo: #osVersion])
>          ifTrue: [Smalltalk at: #OSPlatform]
>          ifFalse: [((Smalltalk classNamed: 'SmalltalkImage')
>                ifNil: [^ Smalltalk osVersion]) current]) osVersion
>
> I'm sure there are better ways to do this, but keeping up with multiple image
> versions can be a lot of work and the code can get quite ugly.
>
> (I have not yet tried updating OSProcess for Cuis, but I do want to do so).
>
> Dave
>
>
> _______________________________________________
> Cuis mailing list
> [hidden email]
> http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
>
>
>  


_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org