Changeset: articles.1.cs

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Changeset: articles.1.cs

Christoph Thiede

Hi all, please take a look at the following changeset. It eliminates a lot of duplication for printing a string with article, for example:


| title |
title := self class name.
aStream
nextPutAll: (title first isVowel ifTrue: ['an '] ifFalse: ['a ']);
nextPutAll: title.


With this changeset, the example is rewritten much simpler as:

aStream nextPutAll: self class name asString withArticle.

(Additionally, this unification provides a possible hook, should we ever want to increase multilingual support. :))

I tried to find as many occurrences as possible (6), but even if we don't replace them all, I would like to propose to put the following three methods into Trunk (which are part of the changeset, of course):

String >> article
^ self first isVowel
ifTrue: ['an']
ifFalse: ['a']

String >> withArticle
^ self article , ' ' , self capitalized

Symbol >> withArticle
^ self article , self capitalized

Theoretically, we could also put them into the '*System-Support' category. Not sure about this.
Looking forward to your opinions :-)

Best,
Christoph



articles.1.cs (6K) Download Attachment
Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: Changeset: articles.1.cs

Chris Muller-3
Sorry Christoph, I'm not a fan of this one.  IMO, such an abstraction isn't worth poaching such a common word, #article, from availability for applications and expanding Squeak's core API with it, especially for something of such limited use.  Many objects already care enough to provide their own #printOn: anyway (sometimes not even calling super).  There's no multilingual hook here (not that there should be one, for this I think there shouldn't) since, even if it *was* possible to replace regular Strings with one's own subclass, that isn't how one would handle internationalization in Squeak.

Instead of adding code to increase printing of type information, the abstraction *I* like for #printOn: is one that could *exclude* the printing of it entirely, and assures a *terse, one-line* print (like, < 80 characters) which identifies the object to the user, but excludes unnecessary data details like its "type" (class).  Numbers and Dates and a few others do this by default, but I like this style to be available for all types as an "alternate" #abbreviatedPrintString, depending on the use-case I'm printing it for (e.g., as elements of a Collection).

Anyway, I call it #printAbbreviatedOn: in my own code, and even though it's been useful to me over two decades and I still use it, I never actually proposed it for trunk because just the one level of intercept, #printOn:, has proven to be *just the right amount* of abstraction for object printing in a general sense.  Simplicity and resilience from original Smalltalk-80 that has withstood the test of time.

Best,
  Chris

On Sun, Jan 19, 2020 at 4:03 PM Thiede, Christoph <[hidden email]> wrote:

Hi all, please take a look at the following changeset. It eliminates a lot of duplication for printing a string with article, for example:


| title |
title := self class name.
aStream
nextPutAll: (title first isVowel ifTrue: ['an '] ifFalse: ['a ']);
nextPutAll: title.


With this changeset, the example is rewritten much simpler as:

aStream nextPutAll: self class name asString withArticle.

(Additionally, this unification provides a possible hook, should we ever want to increase multilingual support. :))

I tried to find as many occurrences as possible (6), but even if we don't replace them all, I would like to propose to put the following three methods into Trunk (which are part of the changeset, of course):

String >> article
^ self first isVowel
ifTrue: ['an']
ifFalse: ['a']

String >> withArticle
^ self article , ' ' , self capitalized

Symbol >> withArticle
^ self article , self capitalized

Theoretically, we could also put them into the '*System-Support' category. Not sure about this.
Looking forward to your opinions :-)

Best,
Christoph



Reply | Threaded
Open this post in threaded view
|

Re: Changeset: articles.1.cs

timrowledge


> On 2020-01-20, at 2:10 PM, Chris Muller <[hidden email]> wrote:
>
> Sorry Christoph, I'm not a fan of this one.  IMO, such an abstraction isn't worth poaching such a common word, #article

I pretty much agree - and in any case it ought to be #indefiniteArticle, at least in English. Further, the simple test for the next word starting with a vowel isn't as useful as it could be. Consider the case of an abbreviation or initialism such as 'FTD'. It should be 'an FTD'. Plenty of very confusing an not necessarily logical cases to get lost in!


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Useful Latin Phrases:- Te precor dulcissime supplex! = Pretty please with a cherry on top!



Reply | Threaded
Open this post in threaded view
|

Re: Changeset: articles.1.cs

Christoph Thiede

Hi, thank you for the feedback.


Further, the simple test for the next word starting with a vowel isn't as useful as it could be. Consider the case of an abbreviation or initialism such as 'FTD'. It should be 'an FTD'. Plenty of very confusing an not necessarily logical cases to get lost in!


Yes, but that's state of the art as well. There are even more exception: 'a honor' would also be wrong. Fixing them all might be indeed a multilingual problem, and I actually did not want to touch that issue. My only desire was to avoid this nasty duplication which indeed affects the readability of several #printOn: methods ...


Best,

Christoph


Von: Squeak-dev <[hidden email]> im Auftrag von tim Rowledge <[hidden email]>
Gesendet: Dienstag, 21. Januar 2020 00:00:05
An: The general-purpose Squeak developers list
Betreff: Re: [squeak-dev] Changeset: articles.1.cs
 


> On 2020-01-20, at 2:10 PM, Chris Muller <[hidden email]> wrote:
>
> Sorry Christoph, I'm not a fan of this one.  IMO, such an abstraction isn't worth poaching such a common word, #article

I pretty much agree - and in any case it ought to be #indefiniteArticle, at least in English. Further, the simple test for the next word starting with a vowel isn't as useful as it could be. Consider the case of an abbreviation or initialism such as 'FTD'. It should be 'an FTD'. Plenty of very confusing an not necessarily logical cases to get lost in!


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Useful Latin Phrases:- Te precor dulcissime supplex! = Pretty please with a cherry on top!





Carpe Squeak!