Le 27/7/15 09:53, Peter Uhnák a écrit :
stream surround: aBlock between: '( ' and: ' )'
This may be personal preference, but I do not like having more method arguments after a block argument... because if the block is longer it may not be visible...
+1
e.g.
stream surround: [ :aStream | self size > 100 ifTrue: [ aStream nextPutAll: 'size '. self size printOn: aStream ] ifFalse: [ self keysSortedSafely do: [ :key | aStream print: key; nextPutAll: '->'; print: (self at: key); space ] ] ] between: $( and: $)
vs between:and:surround:
That could even be #between:and:putAll: On Sat, Jul 25, 2015 at 4:48 AM, stepharo <stepharo@free.fr> wrote:
HI
while working on a lecture I saw that we have about 75 cases like:
aStream nextPut: $(. .... aStream nextPut: $).
... we have surroundedBy: aString
But only working on aString.
Well it seems that #surroundedBy: only has one sender #surroundedBySingleQuotes which in turn seems to be not sent anywhere. So actually #surroundedBy: seems ripe for culling to be replaced by more generic... aStream between: '(' and: ')' putAll: [ ... nextLevelIn ... ]. Now for most of those 75 cases and other cases where this pattern might apply, is performance so critical that using $( rather than '(' gains a lot? Perhaps on ancient machine and before Cog it was important but now using $( now is premature optimisation? Otherwise we might also need #betweenChars:and:putAll: On Mon, Jul 27, 2015 at 3:59 PM, Denis Kudriashov <dionisiydk@gmail.com> wrote:
In most cases we always surround text by "()". Can we just provide method for this and not duplicate "between: '( ' and: ' )'" everywhere? Something like "stream>>printInBrackets:"
Maybe it is also a useful pattern for markup languages: aStream between: '<HEAD>' and: '</HEAD>' putAll: [ ... nextLevelIn ... ]. On Sun, Jul 26, 2015 at 1:40 AM, Esteban Lorenzano <estebanlm@gmail.com> wrote:
(From my vacations)
Doesn't this solves the problem?
stream << $( << name << $)
It is already there :)
That is a reasonable point, but I think the having start and end tokens in visual close proximity has a slight advantage. On Mon, Jul 27, 2015 at 6:23 PM, stepharo <stepharo@free.fr> wrote:
May be I raised a not important issue.
Of course its easier to have an opinion on simple things. cheers -ben