Quicksort in Swift
gist.github.com
gist.github.com
var ar = [3456,45,53567,356,7225,47858]
quickSort(&ar, Range(start: ar.startIndex, end: ar.endIndex))
// [45, 356, 3456, 7225, 47858, 53567]
There's also a version that let's you specify the "less" comparator.This means you can override .. (to disable it) and define your own operator for half-closed ranges if you'd prefer (Swift supports building your own operators from combinations of punctuation characters). At least I think you could do this: I haven't tried.
For the subject at hand: I would like to have seen ranges use () for open endings and [] for closed ones. For example, [1..5) would include 1 but exclude (that is standard notation in mathematics. See http://en.wikipedia.org/wiki/Interval_(mathematics)#Excludin...)
Back to the obfuscation thing: unfortunately for that goal, one cannot create prefix operators with names (, [ or {
It is possible to define an infix operator named ., though. That could give whole new meaning to what look like floating point values such as 3.14.
http://comjnl.oxfordjournals.org/content/5/1/10.full.pdf+htm...
There are reasons not to perform quickSort the way people did fifty years ago. Data sets are larger and worst case time for quickSort approach 0(n^2) when data is already ordered and pivots are selected in-order. Randomizing pivot selection mitigates this back toward O(log n).
All that mutation and pointer swapping are artifacts of the way things used to have to be done by programmers. And they're useful as academic exercises. Hoare's algorithm is really fucking brilliant. But mapping and filtering in a functional style, makes more sense than dotting the 'i's and 'j's if someone is going to be reading and maintaining the code. There's a reason people don't use C to program mobile devices.
Moreover, while Hoare's original algorithm was designed to work in place, the idea of working in place is less coherent today. When we strive to distribute and parallelize big nasty resource intensive jobs, what does "in-place" mean? See Leslie Lamport, Thinking for Programmers at about time = 36:00
http://channel9.msdn.com/Events/Build/2014/3-642
And even on a non-distributed system, when are we really coming up against the bounds of 'fast memory' these days? A serious problem that stretches 16 GigaBytes of RAM is less than $10,000 from 64 GigaBytes...or $200 from an SSD and using 'slow memory'.
Of course if we are parallelizing, we can even do it on one machine and again, what is 'in-place'? The caches? Again which ones and at what level. The Swift code (or Java or C#) may look like C, but it's not. It may be garbage collected, JIT'd, byte coded, and micro-coded all before it hits the mulit-stage branch predicting pipeline from several levels of cache reading from code pages that may have gone in and out to disk as threads and tasks switch.
'Place' might just mean somewhere. But probably somewheres.
[1] http://stackoverflow.com/questions/971312/why-avoid-incremen...
sheepCounted += 1
vs. sheepCounted = sheepCounted + 1 pInterface->m_someField[currentItem] += 1;But then, hey... Objective-C syntax just offends me right-out ;-P
If you're saying it's "dead to me", that's valid. It would be good to see them open up the Swift toolchain, and there will definitely be a significant percentage of devs who won't touch it unless they do.
Put another way, how well does Objective-C do outside of Apple development?
Edit: ...and then swiftly unpublished. It is unclear to me the legal issues involved in forking and publishing unlicensed gists.
http://stackoverflow.com/questions/4007674/whats-the-default...
However, for a trivial piece of code as this... it could be argued it's not copyright-able and therefore you are OK... but just be careful in the future.
Unpublishing!
Many times I've emailed devs on Github regarding some code they have that I'd like to use part of but they've failed to assign a license. A few time's I've been turned away... but usually the dev just forgot or was not aware others couldn't freely use it.
"npm? Isn't that for javascript?
Yes, but:
native node modules are written in c++
npm already exists
npm installs packages in a way that avoids dependency hell"
>Naming Constants and Variables
>You can use almost any character you like for constant and
>variable names, including Unicode characters:
>let π = 3.14159
>let 你好 = "你好世界"
>let 🐶🐮 = "dogcow"
https://developer.apple.com/library/prerelease/ios/documenta...
My position is that it's the language's job to allow expression of ideas and not its job to police or disallow bad sentences. I think such a thing [EDIT: disallowing bad sentences] is impossible and leads to COBOL-like languages. (Compilers can have options for coding standards, like "house rules" but I don't think it's the language's role.)
Basically using unicode characters is comparable to purposeful obfuscation, are difficult to type (no keyboard i'm aware of has a "cow" key), difficult to read/remember, and may become wrongly converted if the code is copy/pasted into a text editor not supporting that character.
Now, I don't think this constituted as a "strong criticism" nor warranted the downvote nor the expletive.