there is a method but then I ran into another warning

FindAndDeleteWordsWithForbiddenParts
    "deletes all the words that contain forbidden parts"

    | result |
    result := words
        select: [ :word |
            [ (forbiddenWords detect: [ :forbidden | word includesAll: forbidden ]) = true ]
                on: NotFound
                do: [ true ] ].
    ^ result

then I see a unnecearry = true but if I deleted that part the code does not what I was intented to do.

Roelof



Op 13-12-2018 om 18:15 schreef Richard Sargent:
It's bad advice in this case, but correctly indicates there is a problem with your code. See below.

On Thu, Dec 13, 2018 at 8:13 AM Roelof Wobben <r.wob...@home.nl> wrote:
Hello, 

I have this code :  

 FindAndDeleteWordsWithForbiddenParts
    "deletes all the words that contain forbidden parts"

    | result |
    result := words
        select: [ :word | 
            [ (forbiddenWords reject: [ :forbidden | '*' , forbidden , '*' match: word ]) isNotEmpty ]
Constructing a pattern and pattern matching is a heavy-handed approach to find out if a word contains a substring.
I'm not familiar with Pharo's methods, but at the least String inherits #indexOfSubCollection:startingAt: and probably a number of others. There is also a good chance String inherits or implements a more specific method that will test for the presence of a sub-string.

A good piece of advice I once received is (paraphrased as): Spend more time reading and less time writing. :-)
The deeper a class hierarchy, the greater the chance that the exact thing you need has already been implemented in the leaf class or its abstraction.

                on: NotFound
                do: [ false ] ].
    ^ result


but I see warnings that I have to use a stream instead of string concentation.

Anyone hints how to do so ? 

Roelof


Reply via email to