[Pharo-project] could we agree to remove caseOf: and caseOf:otherwise:

Igor Stasenko siguctua at gmail.com
Mon Feb 14 17:34:17 CET 2011


On 14 February 2011 15:57, Henrik Sperre Johansen
<henrik.s.johansen at veloxit.no> wrote:
>
> I agree with both Igor and Levente.
>
> Uses of caseOf: is often times solvable in more "elegant" ways.
>
> Though, I think in f.ex. HandMorph>>#processEvents  and
> UTF8TextConverter>>nextFromStream:, it would actually *improve* readability
> to use it.
>
> Got any good refactoring to symbolics for those two, Igor? ;)
>

Yes, i having the code somewhere for translating evtBuf to nice events. So
the HandMorph>>processEvents then will be:

Sensor nextEvent dispatchOn: self

at some day :-)

As for UTF8, the caseOf is not clearly applicable, because it using
ranged comparison, so you can't dispatch using the table:

nextUTF8Char

	| value1 value2 value3 value4 |
	(value1 := self nextByte) ifNil: [^ self endOfStreamAction value].
	value1 <= 127 ifTrue: [
		"1-byte character"
		^ Character value: value1
	].

	"at least 2-byte character"
	(value2 := self nextByte) ifNil: [^self errorMalformedInput].
	value1 <= 2r11011111 ifTrue: [
		^ Unicode charFromUnicode: ((value1 bitAnd: 31) bitShift: 6) +
(value2 bitAnd: 63).
	].

	"at least 3-byte character"
	(value3 := self nextByte) ifNil: [^self errorMalformedInput].
	(value1 <= 2r11101111) ifTrue: [
		^ Unicode charFromUnicode: ((value1 bitAnd: 15) bitShift: 12) +
((value2 bitAnd: 63) bitShift: 6)
				+ (value3 bitAnd: 63).
	].

	"4-byte character"
	(value1 <= 2r11110111) ifTrue: [
		(value4 := self nextByte) ifNil: [^self errorMalformedInput].
		^ Unicode charFromUnicode: ((value1 bitAnd: 16r7) bitShift: 18) +
					((value2 bitAnd: 63) bitShift: 12) +
					((value3 bitAnd: 63) bitShift: 6) +
					(value4 bitAnd: 63).
	].

	^self errorMalformedInput


> Cheers,
> Henry
>
> -1 for removal/deprecation from me (from the system, not necessarily as
> special cases for the compiler)
> --
> View this message in context: http://forum.world.st/could-we-agree-to-remove-caseOf-and-caseOf-otherwise-tp3302475p3305140.html
> Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
>
>



-- 
Best regards,
Igor Stasenko AKA sig.




More information about the Pharo-project mailing list