Capitalized

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Capitalized

Torsten Bergmann
According to https://en.wikipedia.org/wiki/Capitalization

to "capitalize" is writing a word with its first letter as a capital letter (upper-case letter)
AND THE REMAINING LETTERS IN LOWER CASE writing systems.

So

  'SOMETHING' capitalized

currently returns "SOMETHING" in Pharo but should return "Something" according to the definition to end up with lowercase.
If we fix this I guess we would also align Pharo with other languages, like C# for example [1].

Could be easily changed by replacing "copy" with "asLowercase" in #capitalized:

 capitalized
        "Return a copy with the first letter capitalized"
        | cap |
        self isEmpty ifTrue: [ ^self copy ].
        cap := self asLowercase.
        cap at: 1 put: (cap at: 1) asUppercase.
        ^ cap

Should we fix this? Do not know about any side effects...


Note: a) Squeak has the same issue
      b) it fits for #uncapitalized, see [2]
      c) Dont know about ANSI standard or any other ST dialect

Thx
T.


[1] https://github.com/srkirkland/Inflector/blob/master/Inflector.Tests/CapitalizeTests.cs
[2] https://github.com/srkirkland/Inflector/blob/master/Inflector.Tests/UncapitalizeTests.cs

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Capitalized

Henrik-Nergaard

>to "capitalize" is writing a word with its first letter.

The Smalltalk String is not neccessarily just a word, it could be something else so the current implementation makes no assumptions of what the string is.

---------------------------------------------------------------------------------------------

| newClass |

newClass := Object subclass: #AbcSomeClass 
instanceVariableNames: 'errorCodeName referencePosition instanceVariable'.
newClass instanceVariableNamesDo: [ :aString | | code |
code := String streamContents: [ :aStream | | prefix cap |
prefix := aString first isVowel ifTrue: ['an'] ifFalse: ['a'].
cap := aString capitalized.
aStream 
<< aString; << ':'; space; << prefix; << cap;
cr; cr; tab;
<< aString; << ' := '; << prefix; << cap.
].
newClass compile: code classified: 'accessing'
].

newClass browse
--------------------------------------------------------------------------------------------

>Should we fix this? Do not know about any side effects...

I think it would be better and more clear to then implement a new method called something like #onlyCapitalized that removes all other uppercase letters.


Best regards,

Henrik



Fra: Pharo-dev <[hidden email]> på vegne av Torsten Bergmann <[hidden email]>
Sendt: 15. mars 2017 11:33:35
Til: Pharo Development List
Emne: [Pharo-dev] Capitalized
 
According to https://en.wikipedia.org/wiki/Capitalization

to "capitalize" is writing a word with its first letter as a capital letter (upper-case letter)
AND THE REMAINING LETTERS IN LOWER CASE writing systems.

So

  'SOMETHING' capitalized

currently returns "SOMETHING" in Pharo but should return "Something" according to the definition to end up with lowercase.
If we fix this I guess we would also align Pharo with other languages, like C# for example [1].

Could be easily changed by replacing "copy" with "asLowercase" in #capitalized:

 capitalized
        "Return a copy with the first letter capitalized"
        | cap |
        self isEmpty ifTrue: [ ^self copy ].
        cap := self asLowercase.
        cap at: 1 put: (cap at: 1) asUppercase.
        ^ cap

Should we fix this? Do not know about any side effects...


Note: a) Squeak has the same issue
      b) it fits for #uncapitalized, see [2]
      c) Dont know about ANSI standard or any other ST dialect

Thx
T.


[1] https://github.com/srkirkland/Inflector/blob/master/Inflector.Tests/CapitalizeTests.cs
[2] https://github.com/srkirkland/Inflector/blob/master/Inflector.Tests/UncapitalizeTests.cs

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Capitalized

Peter Uhnak
Maybe for next Pharo version? As this is a breaking change, which you cannot just deprecate. Also then there would need to be another method that provides the current behavior.

Peter

On Wed, Mar 15, 2017 at 12:16:44PM +0000, Henrik Nergaard wrote:

> >to "capitalize" is writing a word with its first letter.
>
> The Smalltalk String is not neccessarily just a word, it could be something else so the current implementation makes no assumptions of what the string is.
>
> ---------------------------------------------------------------------------------------------
>
> | newClass |
>
> newClass := Object subclass: #AbcSomeClass
> instanceVariableNames: 'errorCodeName referencePosition instanceVariable'.
> newClass instanceVariableNamesDo: [ :aString | | code |
> code := String streamContents: [ :aStream | | prefix cap |
> prefix := aString first isVowel ifTrue: ['an'] ifFalse: ['a'].
> cap := aString capitalized.
> aStream
> << aString; << ':'; space; << prefix; << cap;
> cr; cr; tab;
> << aString; << ' := '; << prefix; << cap.
> ].
> newClass compile: code classified: 'accessing'
> ].
>
> newClass browse
> --------------------------------------------------------------------------------------------
>
>
> >Should we fix this? Do not know about any side effects...
>
> I think it would be better and more clear to then implement a new method called something like #onlyCapitalized that removes all other uppercase letters.
>
>
> Best regards,
>
> Henrik
>
>
> ________________________________
> Fra: Pharo-dev <[hidden email]> på vegne av Torsten Bergmann <[hidden email]>
> Sendt: 15. mars 2017 11:33:35
> Til: Pharo Development List
> Emne: [Pharo-dev] Capitalized
>
> According to https://en.wikipedia.org/wiki/Capitalization
>
> to "capitalize" is writing a word with its first letter as a capital letter (upper-case letter)
> AND THE REMAINING LETTERS IN LOWER CASE writing systems.
>
> So
>
>   'SOMETHING' capitalized
>
> currently returns "SOMETHING" in Pharo but should return "Something" according to the definition to end up with lowercase.
> If we fix this I guess we would also align Pharo with other languages, like C# for example [1].
>
> Could be easily changed by replacing "copy" with "asLowercase" in #capitalized:
>
>  capitalized
>         "Return a copy with the first letter capitalized"
>         | cap |
>         self isEmpty ifTrue: [ ^self copy ].
>         cap := self asLowercase.
>         cap at: 1 put: (cap at: 1) asUppercase.
>         ^ cap
>
> Should we fix this? Do not know about any side effects...
>
>
> Note: a) Squeak has the same issue
>       b) it fits for #uncapitalized, see [2]
>       c) Dont know about ANSI standard or any other ST dialect
>
> Thx
> T.
>
>
> [1] https://github.com/srkirkland/Inflector/blob/master/Inflector.Tests/CapitalizeTests.cs
> [2] https://github.com/srkirkland/Inflector/blob/master/Inflector.Tests/UncapitalizeTests.cs
>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Capitalized

John Brant-2
In reply to this post by Torsten Bergmann
On 03/15/2017 05:33 AM, Torsten Bergmann wrote:

> According to https://en.wikipedia.org/wiki/Capitalization
>
> to "capitalize" is writing a word with its first letter as a capital letter (upper-case letter)
> AND THE REMAINING LETTERS IN LOWER CASE writing systems.
>
> So
>
>   'SOMETHING' capitalized
>
> currently returns "SOMETHING" in Pharo but should return "Something" according to the definition to end up with lowercase.
> If we fix this I guess we would also align Pharo with other languages, like C# for example [1].

That wouldn't be what I would expect. Here's what dictionary.com has for
capitalize:

        1. to write or print in capital letters letters or
        with an initial capital letter

That definition doesn't say what happens with the rest of the letters.

As for C#, isn't that someone's extension method for String and not a
Microsoft method? I don't see that method on Microsoft's current String
class documentation:

https://msdn.microsoft.com/en-us/library/system.string(v=vs.110).aspx

Also, the Uncapitalize method is inconsistent with the Capitalize
method. The Uncapitalize method changes only the first character and all
other characters are unchanged. However, the Capitalize method can
change all characters.

Finally, Dolphin Smalltalk has an implementation that is similar to Pharo's:

https://github.com/dolphinsmalltalk/Dolphin/blob/master/Core/Object%20Arts/Dolphin/Base/String.cls


John Brant

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Capitalized

Ben Coman
In reply to this post by Torsten Bergmann


On Wed, Mar 15, 2017 at 6:33 PM, Torsten Bergmann <[hidden email]> wrote:
According to https://en.wikipedia.org/wiki/Capitalization

to "capitalize" is writing a word with its first letter as a capital letter (upper-case letter)
AND THE REMAINING LETTERS IN LOWER CASE writing systems.

So

  'SOMETHING' capitalized

currently returns "SOMETHING" in Pharo but should return "Something" according to the definition to end up with lowercase.

I think it would be reasonable to expect...
    self assert: 'something' capitalized 
           equals: 'SOMETHING' capitalized

In ignorance of history, I'd call this a bug.
Maybe not for "frozen" Pharo 6, but not needing a deprecation, just a fix.

cheers -ben
 
If we fix this I guess we would also align Pharo with other languages, like C# for example [1].

Could be easily changed by replacing "copy" with "asLowercase" in #capitalized:

 capitalized
        "Return a copy with the first letter capitalized"
        | cap |
        self isEmpty ifTrue: [ ^self copy ].
        cap := self asLowercase.
        cap at: 1 put: (cap at: 1) asUppercase.
        ^ cap

Should we fix this? Do not know about any side effects...


Note: a) Squeak has the same issue
      b) it fits for #uncapitalized, see [2]
      c) Dont know about ANSI standard or any other ST dialect

Thx
T.


[1] https://github.com/srkirkland/Inflector/blob/master/Inflector.Tests/CapitalizeTests.cs
[2] https://github.com/srkirkland/Inflector/blob/master/Inflector.Tests/UncapitalizeTests.cs


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Capitalized

Torsten Bergmann
In reply to this post by John Brant-2
Hi,

thanks for the feedback. So it depends on which definition we will follow...

After investigating a little bit more I guess the current implementation is more
valuable and should stay. For instance we can easily convert an ivar name into
a class name with it:   'ellipseMorph' capitalized -> 'EllipseMorph'
Also then this is in alignment with other dialects.

Additionally: changing it would break too many things because it is often used in some #perform:
based meta-magic and other (see SpecPreDebugWindow>>createNotifierPaneWidgets for an example)

Sorry for the noise. I should upload a slice to Wikipedia + GitHub ;)

Bye
T.

> Gesendet: Mittwoch, 15. März 2017 um 14:30 Uhr
> Von: "John Brant" <[hidden email]>
> An: [hidden email]
> Betreff: Re: [Pharo-dev] Capitalized
>
> On 03/15/2017 05:33 AM, Torsten Bergmann wrote:
> > According to https://en.wikipedia.org/wiki/Capitalization
> >
> > to "capitalize" is writing a word with its first letter as a capital letter (upper-case letter)
> > AND THE REMAINING LETTERS IN LOWER CASE writing systems.
> >
> > So
> >
> >   'SOMETHING' capitalized
> >
> > currently returns "SOMETHING" in Pharo but should return "Something" according to the definition to end up with lowercase.
> > If we fix this I guess we would also align Pharo with other languages, like C# for example [1].
>
> That wouldn't be what I would expect. Here's what dictionary.com has for
> capitalize:
>
> 1. to write or print in capital letters letters or
> with an initial capital letter
>
> That definition doesn't say what happens with the rest of the letters.
>
> As for C#, isn't that someone's extension method for String and not a
> Microsoft method? I don't see that method on Microsoft's current String
> class documentation:
>
> https://msdn.microsoft.com/en-us/library/system.string(v=vs.110).aspx
>
> Also, the Uncapitalize method is inconsistent with the Capitalize
> method. The Uncapitalize method changes only the first character and all
> other characters are unchanged. However, the Capitalize method can
> change all characters.
>
> Finally, Dolphin Smalltalk has an implementation that is similar to Pharo's:
>
> https://github.com/dolphinsmalltalk/Dolphin/blob/master/Core/Object%20Arts/Dolphin/Base/String.cls
>
>
> John Brant
>
>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Capitalized

stepharong
In reply to this post by Torsten Bergmann
Ok I got it

you mean

        "'snOOpy' capitalized
        >>>'Snoopy'"


        and not
        "'snOOpy' capitalized
        >>>'SnOOpy'"


Indeed.

Now captialized comment is clear.
We could do that in Pharo70 alpha.
Now for OS that distinguish S from s we should pay attention.

Stef

On Wed, 15 Mar 2017 11:33:35 +0100, Torsten Bergmann <[hidden email]>  
wrote:

> According to https://en.wikipedia.org/wiki/Capitalization
>
> to "capitalize" is writing a word with its first letter as a capital  
> letter (upper-case letter)
> AND THE REMAINING LETTERS IN LOWER CASE writing systems.
>
> So
>
>   'SOMETHING' capitalized
>
> currently returns "SOMETHING" in Pharo but should return "Something"  
> according to the definition to end up with lowercase.
> If we fix this I guess we would also align Pharo with other languages,  
> like C# for example [1].
>
> Could be easily changed by replacing "copy" with "asLowercase" in  
> #capitalized:
>
>  capitalized
> "Return a copy with the first letter capitalized"
> | cap |
> self isEmpty ifTrue: [ ^self copy ].
> cap := self asLowercase.
> cap at: 1 put: (cap at: 1) asUppercase.
> ^ cap
>
> Should we fix this? Do not know about any side effects...
>
>
> Note: a) Squeak has the same issue
>       b) it fits for #uncapitalized, see [2]
>       c) Dont know about ANSI standard or any other ST dialect
>
> Thx
> T.
>
>
> [1]  
> https://github.com/srkirkland/Inflector/blob/master/Inflector.Tests/CapitalizeTests.cs
> [2]  
> https://github.com/srkirkland/Inflector/blob/master/Inflector.Tests/UncapitalizeTests.cs
>


--
Using Opera's mail client: http://www.opera.com/mail/

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Capitalized

stepharong
In reply to this post by Torsten Bergmann
Hi torsten

I do not get your point. In Pharo 60 we have.

capitalized
        "Return a copy with the first letter capitalized"
        | cap |
        self isEmpty ifTrue: [ ^self copy ].
        cap := self copy.
        cap at: 1 put: (cap at: 1) asUppercase.
        ^ cap


"'snoopy' capitalized
>>> 'Snoopy'"

Stef

Loading...