[Cuis] [aida] Marking a dialect specific code

Janko Mivšek janko.mivsek at eranova.si
Mon Jan 21 07:50:56 CST 2013


Dne 21. 01. 2013 14:29, piše H. Hirzel:

>>>>>> Also, for methods which are now Cuis specific, put "Cuis specific" in a
>>>>>> method comment.
>>
>>>>> Yes, or self flag: #adaptedForCuis as Hannes suggested?
>>
>>>> #flag: is Squeak and friends specific, not supported on VW. Let we stay
>>>> with proven "* specific" comments instead.
>>
>>> How do you browse methods marked with a comment
>>>             "* specific"
>>>
>>> in Squeak and Cuis?
>>
>> Such browsing could probably be portable from VW. One of the tricks is
>> also to put dialect specific methods in separate, as stable as possible
>> methods, so that they probably won't change for a long time. That way
>> you avoid overriding them accidentally. Even if you do that, you can
>> find such error with dialect specific code browser easily.
> 
> Sounds good, but is a bit abstract.
> 
> Could you give an example, please?

See the recent example while introducing WebSockets to Swazoo and making
it as portable as possible. Base64 encoding is very dialect specific, so
it is good to introduce a separate, the only dialect specific method:

SwazooWebSocket>>base64From: aByteArray
  "VW specific"
  ^Base64EncodingStream encodeBytesWithoutLineBreaks: aByteArray

Now the method using Base64 encoding is not dialect specific anymore:

SwazooWebSocket>>calculateAcceptValueFrom:  aHTTPRequest
  | key string hash |
  key := (aHTTPRequest headerAt:'Sec-WebSocket-Key' ifAbsent:[]) value.
  key = nil ifTrue: [^nil].
  string := key, '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'.
  hash := self shaHashFrom: string.
  ^self base64From: hash

>> Of course a first preventive is to avoid dialect specific code at all
>> and rather try to find a code which works on all dialects, a "least
>> common denominator" therefore. As we are just doing with process forking
>> code.
> 
> Sure
> 
>> In any case, this pragmatic way of dealing with dialect specific code
>> serves me well for Aida last 6 years after the first Squeak port, so I
>> propose to continue for Cuis port as well.
> 
> I assume you have a package which implements such a layer.
> 
> Could you give a reference please?

On VW Aida there are two methods to find and browse dialect specific
methods:

AIDASite class>>platformSpecificMethods
  "find all methods which have '* specific' (like 'VW specific')
   in method comments"

AIDASite class>>browsePlatformSpecificMethods
  "open a code browser with all platform specific methods having like
   'VW specific' in method comments"

It would be really nice if someone helps here a bit and port at least
first method to other dialects too.

Best regards
Janko








More information about the Cuis mailing list