5 ms·
Just glanced thru the Swift book in about 3 hours. Conclusion: all your programming language are belong to Swift, mostly stolen good ideas, some innovations, a
by wyuenho 12y ago
Just glanced thru the Swift book in about 3 hours. Conclusion: all your programming language are belong to Swift, mostly stolen good ideas, some innovations, a few gripes.
I can say Swift takes inspiration and improves on at least these languages:
C:
typealias
struct
control structures
labeled statements AKA gotos
varargs
C++:
default arguments
class instance construction syntax
// comment
superclass, implementing protocol declaration syntax
semi-virtual class init, deinit
Go:
No parentheses around the condition part of control statements
Unicode identifiers
shorthand for signed and unsigned integer types U?Int(8|16|32|64)
C#:
in-out params
properties
subscript access of class member values
Objective-C:
ARC
protocols
extensions
param names as method names
willSet/didSet
nil?
Java:
enum
@final
super keyword
override method keyword
Scala:
Local type-inference, blend of an ML flavored FP with OOP without the noise and believe it or not, even more powerful in specifying generic type constraints. No stupid JVM type erasures either so you can actually create an instance of a generic type, just like C++ templates.
Self:
self
Python:
for i in enumerate(seq)
for key, value in dictionary
Type(value) explicit type conversion syntax
No public/private/protected class member access modifier bullshit
Array literals, dictionary is also like Python but use [] instead of {}
Ruby:
0..100, 100_000
Lisp:
closures
Scheme, Coffeescript:
? optional type modifier
Bash:
$0, $1... inside short callback closures
Innovations
---------------
break-less switch, optional fall-thru, comma as multiple case, case can be any value of any type, condition or a type constraint for pattern matching, supports method call shorthand
generic type constraint queries
overflow operators
@prefix, @postfix, @infix, @assignment modifiers for operator overloading
Trailing closure as partial function application
Gripes
------
Seems like array[4..6] is even more useless than Javascript's Array#slice, and a far cry from Python's slices.
No set literals and list/set/dict comprehension.
Nothing for concurrency???? No yield, no generators, no channels, not even the synchronized keyword.
There's no decorator or annotations, and Swift isn't Objective-C, what's with the odd-ball @ modifiers?
I don't see namespaces as mentioned in the WWDC slides, and goto is definitely still here so you might just write another gotofail.
Looks like Swift is Apple's answer to Go, Rust, Scala, Java, PyObjC/RubyMotion, Unity, Xamarin and all these HTML5 + JS/Phonegap people. I'll definitely pay attention to Swift. If the performance results hold up, Swift + iOS8 will definitely leave Android's ancient Java 5 crap way out in the dust.
https://itunes.apple.com/us/book/swift-programming-language/id881256329?mt=11 https://itunes.apple.com/us/book/swift-programming-language/...
- hornetblack 12y ago> break-less switch, optional fall-thru Like Go and Dart?
- wyuenho 12y agoThere's actually a new keyword called `fallthrough`.
- ustolemyname 12y agoInteresting definition of 'new' you're using there. http://golang.org/ref/spec#Fallthrough_statements http://golang.org/ref/spec#Fallthrough_statements
- wyuenho 12y agoHa thanks! It's been a while since I looked at Go. I wish I could edit the comment now!
- bigdubs 12y agoGood list, I think the generics notation was inspired by C# but with the improvement of moving the generic constraints inside the <>'s
- mambodog 12y agoConcurrency will probably be handled using Grand Central Dispatch's[0] queues. [0] http://en.wikipedia.org/wiki/Grand_Central_Dispatch http://en.wikipedia.org/wiki/Grand_Central_Dispatch
- jgimenez 12y agoYou're right. I can remember an example with something like: dispatch_async(queue) { /* code here */} That's an idiomatic adaptation to dispatch_async to support closures. I guess this internally might be converted to a block.
- 12y ago