Squeak equivalent of OSPlatform ?

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

Squeak equivalent of OSPlatform ?

Squeak - Dev mailing list
Hi folks,

I am puttering about trying to see if I can import Pillar into Squeak.
BaselineOfPillar >> customProjectAttributes
    "Edit to return a collection of any custom attributes e.g. for conditional loading: Array with: #'Condition1' with: #'Condition2.

| attributes |
attributes := OrderedCollection new.
OSPlatform current isWindows ifTrue: [ attributes add: #windows ].
OSPlatform current isUnix    ifTrue: [ attributes add: #unix ].
OSPlatform current isMacOS   ifTrue: [ attributes add: #osx ].
^ attributes asArray

I have poked around a bit and 

ThisOSProcess concreteClass
looks like a good replacement candidate.

However, I figured I would check with you all first.


thx in advance.







Reply | Threaded
Open this post in threaded view
|

Re: Squeak equivalent of OSPlatform ?

marcel.taeumel
Hi Timothy.

Both OSProcess and also Squeak-FFI interface SmalltalkImage (via "Smalltalk" global), which queries platform-specific attributes (or labels) via VM primitives:

OSProcess class >> #platformName
OSProcess class >> #platformSubtype
OSProcess class >> #osVersion

FFIPlatformDescription class >> #current 
FFIPlatformDescription >> #name
FFIPlatformDescription >> #subtype
FFIPlatformDescription >> #is(Windows|ARM|Unix)

SmalltalkImage >> #getSystemAttribute:
SmalltalkImage >> #platformName
SmalltalkImage >> #platformSubtype

But beware of writing too much "is(Unix|Windows)"-like code across your abstraction levels because checking for more specific capabilites might produce more readable code such as "canReadFat32Device". ... which was not your question at all here. :-D

Best,
Marcel

Am 20.10.2020 14:37:50 schrieb gettimothy via Squeak-dev <[hidden email]>:

Hi folks,

I am puttering about trying to see if I can import Pillar into Squeak.
BaselineOfPillar >> customProjectAttributes
    "Edit to return a collection of any custom attributes e.g. for conditional loading: Array with: #'Condition1' with: #'Condition2.

| attributes |
attributes := OrderedCollection new.
OSPlatform current isWindows ifTrue: [ attributes add: #windows ].
OSPlatform current isUnix    ifTrue: [ attributes add: #unix ].
OSPlatform current isMacOS   ifTrue: [ attributes add: #osx ].
^ attributes asArray

I have poked around a bit and 

ThisOSProcess concreteClass
looks like a good replacement candidate.

However, I figured I would check with you all first.


thx in advance.







Reply | Threaded
Open this post in threaded view
|

Re: Squeak equivalent of OSPlatform ?

timrowledge


> On 2020-10-20, at 7:31 AM, Marcel Taeumel <[hidden email]> wrote:
>
> But beware of writing too much "is(Unix|Windows)"-like code across your abstraction levels because checking for more specific capabilites might produce more readable code such as "canReadFat32Device". ... which was not your question at all here. :-D

Exactly - ask 'can I do this' not 'am I a wotsit'.

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Don't diddle code to make it faster; find a better algorithm.



Reply | Threaded
Open this post in threaded view
|

Re: Squeak equivalent of OSPlatform ?

Squeak - Dev mailing list
In reply to this post by Squeak - Dev mailing list
Hi folks,

> On 2020-10-20, at 7:31 AM, Marcel Taeumel <[hidden email]> wrote:
>
> But beware of writing too much "is(Unix|Windows)"-like code across your abstraction levels because checking for more specific capabilites might produce more readable code such as "canReadFat32Device". ... which was not your question at all here. :-D

Exactly - ask 'can I do this' not 'am I a wotsit'.

Fascinating! I see the utility of it. thx



FWIW, the install of Pillar on Squeak relies on something called a PackageManifest and a KernelManifest in Pharo.

I do not think it is worth pursuing via that route and I suspect I will have to roll-my-own.


cheers.










Reply | Threaded
Open this post in threaded view
|

Re: Squeak equivalent of OSPlatform ?

timrowledge


> On 2020-10-20, at 11:55 AM, gettimothy via Squeak-dev <[hidden email]> wrote:
>
> Hi folks,
>
> > On 2020-10-20, at 7:31 AM, Marcel Taeumel <[hidden email]> wrote:
> >
> > But beware of writing too much "is(Unix|Windows)"-like code across your abstraction levels because checking for more specific capabilites might produce more readable code such as "canReadFat32Device". ... which was not your question at all here. :-D
>
> Exactly - ask 'can I do this' not 'am I a wotsit'.
>
> Fascinating! I see the utility of it. thx
>

There's a hierarchy of less-dumb things to do in this area.

#isKindOf: is about the worst possible (though I'm sure somebody will chime in with an even worse idea).

Specialising is a bit (as we often do, because of lack of opportunity to get it right) to #isInteger or
#isThingyMorph is at least sensibly indicative of what you are asking.

#canHandleDoodahReverse is much better but sometimes hard to implement really cleanly across a system.

And of course there's always
[thingy doStuff]
        on: MyStuffError
        do: [:ex| ex helpMeObiWanKenobi]
if you prefer to beg forgiveness rather than ask permission, but exceptions always seem to scare people off. And there is some performance cost - at least, there always seemed to be. Maybe there isn't so much any more?

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Trancelators interpret messages from the dead



Reply | Threaded
Open this post in threaded view
|

Re: Squeak equivalent of OSPlatform ?

Jakob Reschke
timrowledge wrote
> And of course there's always
> [thingy doStuff]
> on: MyStuffError
> do: [:ex| ex helpMeObiWanKenobi]

Though this doesn't work so well to check protocol conformance with on:
MessageNotUnderstood ("Can I use thingy doStuff or must I use otherThingy
doFluff instead on this platform?"). 1) thingy might actually implement
doStuff, but have a different idea of what it means than your code expects,
2) unless Obi-Wan very carefully checks the message send that signalled MNU,
you would also catch all the random type errors the programmers of thingy
made deep in doStuff.



--
Sent from: http://forum.world.st/Squeak-Dev-f45488.html

Reply | Threaded
Open this post in threaded view
|

Protocol Standards was (Re: Squeak equivalent of OSPlatform ?)

Squeak - Dev mailing list
This thread raises an important issue *

Does Squeak have a protocol/method naming standard?


Does OpenSmalltalk ?

Its a huge issue for the consortium minded, but the utility is self evident when one realizes that Smalltalks are poised for explosive growth.


I have bumped into, on Seaside, this issue and I entirely agree with the maintainer that java-isms are detrimental to thinking in objects.


Surely helpers can be written to scan method names and flag them for improvement.




*(SpeakinAsA DeveloperWhoHabituallyRevertsToCamelCaseWithDisastrousRamificationsAndClassNamesTwiceThisInLengthInA FutileDesireForClarity)


---- On Tue, 20 Oct 2020 17:40:22 -0400 [hidden email] wrote ----

timrowledge wrote
> And of course there's always
> [thingy doStuff]
>     on: MyStuffError
>     do: [:ex| ex helpMeObiWanKenobi]

Though this doesn't work so well to check protocol conformance with on:
MessageNotUnderstood ("Can I use thingy doStuff or must I use otherThingy
doFluff instead on this platform?"). 1) thingy might actually implement
doStuff, but have a different idea of what it means than your code expects,
2) unless Obi-Wan very carefully checks the message send that signalled MNU,
you would also catch all the random type errors the programmers of thingy
made deep in doStuff.



--
Sent from: http://forum.world.st/Squeak-Dev-f45488.html




Reply | Threaded
Open this post in threaded view
|

Re: Squeak equivalent of OSPlatform ?

Levente Uzonyi
In reply to this post by Squeak - Dev mailing list
Hi Tim,

On Tue, 20 Oct 2020, gettimothy via Squeak-dev wrote:

> Hi folks,
>
> I am puttering about trying to see if I can import Pillar into Squeak.
>       BaselineOfPillar >> customProjectAttributes
>     "Edit to return a collection of any custom attributes e.g. for conditional loading: Array with: #'Condition1' with: #'Condition2.
> For more information see: http://code.google.com/p/metacello/wiki/CustomProjectAttrributes "
>
> | attributes |
> attributes := OrderedCollection new.
> OSPlatform current isWindows ifTrue: [ attributes add: #windows ].
> OSPlatform current isUnix    ifTrue: [ attributes add: #unix ].
> OSPlatform current isMacOS   ifTrue: [ attributes add: #osx ].
> ^ attributes asArray
>
>
> I have poked around a bit and 
>
>       ThisOSProcess concreteClass
>
> looks like a good replacement candidate.
>
> However, I figured I would check with you all first.
That's totally unrelated. It's easier to fire up a pharo image if you want
to figure out what got rewritten into what than guessing.
So, OSPlatform provides the same information as the methods of the os
category of SmalltalkImage do in Squeak.

A simple replacement of that method in Squeak would be:

^Smalltalk platformName
  caseOf: {
  [ 'Mac OS' ] -> [ #(osx) ].
  [ 'Win32' ] -> [ #(windows) ].
  [ 'unix' ] -> [ #(unix) ] }
  otherwise: [ #() ]


Levente

>
>
> thx in advance.
>
>
>
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Squeak equivalent of OSPlatform ?

timrowledge
In reply to this post by Jakob Reschke


> On 2020-10-20, at 2:40 PM, Jakob Reschke <[hidden email]> wrote:
>
> timrowledge wrote
>> And of course there's always
>> [thingy doStuff]
>> on: MyStuffError
>> do: [:ex| ex helpMeObiWanKenobi]
>
> Though this doesn't work so well to check protocol conformance with on:
> MessageNotUnderstood ("Can I use thingy doStuff or must I use otherThingy
> doFluff instead on this platform?"). 1) thingy might actually implement
> doStuff, but have a different idea of what it means than your code expects,
> 2) unless Obi-Wan very carefully checks the message send that signalled MNU,
> you would also catch all the random type errors the programmers of thingy
> made deep in doStuff.
>

Yes. Exceptions can be exceptionally perplexing and stressing. This is probably why we too often see use of 'on: Error' etc.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
CITOKATE - Criticism is the Only Known Antidote to Error