[swift-evolution] Proposal: Add .times method to Integer type

Cihat Gündüz CihatGuenduez at posteo.de
Fri Dec 18 17:20:19 CST 2015


By the way and/or for all of you who like the idea of a .times method:

I’ve just setup a library for features like this `times` method and implemented the suggested method there. Feel free to contribute code / provide feedback via that third party library (as suggested by Chris) here:

https://github.com/Flinesoft/HandySwift <https://github.com/Flinesoft/HandySwift>

– Cihat

> Am 18.12.2015 um 23:42 schrieb Cihat Gündüz via swift-evolution <swift-evolution at swift.org>:
> 
> As far as I can remember it was never a goal of Swift to be a purely object-oriented language. Instead I can find expressiveness stated explicitly amongst the three main goals behind the language here: https://swift.org/about/#platform-support <https://swift.org/about/#platform-support>
> 
> Therefore I feel it is okay if the language becomes more expressive in a way that is less object-oriented. I see the suggested method as a functional construct.
> 
> – Cihat
> 
> 
>> Am 18.12.2015 um 23:22 schrieb Kenny Leung <kenny_leung at pobox.com <mailto:kenny_leung at pobox.com>>:
>> 
>> I don’t agree with this on the grounds that it isn’t very object-oriented. That is, it does not conform with what one usually associates with an integer. A number has certain intrinsic properties: 5 is greater than 4 but less than 6. If you’re a synesthete, it may have the color blue. But I never think of there being a big number 5 that takes something and repeats it 5 times. I think of a person taking something and doing it over 5 times.
>> 
>> -Kenny
>> 
>>> On Dec 18, 2015, at 10:25 AM, Cihat Gündüz via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> 
>>> Dear Swift-Community,
>>> 
>>> I’d like to propose an addition of a useful method, especially for beginners that also makes Swift much more readable in some situations: The addition of a .times method to Integer type(s).
>>> 
>>> For example recently in one of my projects I wanted to test the scalability of an important piece of code and wrote this method:
>>> 
>>>    func testPerfQualityInPercentWithoutQualityImprovements() {
>>>        self.measureBlock {
>>>            let expectedQuality = 33.33
>>>            0.stride(to: 5_000, by: 1).forEach { _ in
>>>                XCTAssertEqualWithAccuracy(self.crossword.qualityInPercent, expectedQuality, accuracy: 0.1)   
>>>            }   
>>>        }
>>>    }
>>> 
>>> As you can see what I basically wanted was to repeat the test some thousand times. I also like to use the Ruby language and one thing I love about it is that it has some really handy methods integrated to the language in situations like this which make the code very readable and therefore fun to use.
>>> 
>>> I’m an even bigger fan of Swift so I’d love to see such useful methods appear in Swift, too and this is the first I came across that I really missed. So I’m asking myself, what if I could write the same code above like this:
>>> 
>>>    func testPerfQualityInPercentWithoutQualityImprovements() {
>>>        self.measureBlock {
>>>            let expectedQuality = 33.33
>>>            5_000.times {
>>>                XCTAssertEqualWithAccuracy(self.crossword.qualityInPercent, expectedQuality, accuracy: 0.1)   
>>>            }   
>>>        }
>>>    }
>>> 
>>> I think it could be added to the Swift standard library very easily (for example by using the .stride method like I used) without any side effects and has enough advantages to be part of Swift itself. What do you think?
>>> 
>>> I wish you all the best,
>>> Cihat
>>> 
>>> 
>>> P.S.: This is my very first mail in such a mailing list so I did everything correctly. ^.^
>>> 
>>> 
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> 
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151219/433f8bc7/attachment.html>


More information about the swift-evolution mailing list