Live data from Hacker News

Swift Programming Language Evolution

github.com

51–60 of 181 posts

Re: Swift Programming Language Evolution

#51
post #27

I've never understood the fascination with Swift. What's wrong with Objective C?

Objective-C has no safe collections for non-object values. If you want an array of ints, for example, you either get to use a C array with lots of manual management and potential for error, or you use an NSArray of NSNumbers and pay for a bunch of overhead.

It has very poor support for custom value types. Objective-C structs basically can't contain object pointers, so they're limited to simple things like CGRect. They also can't contain methods, so you end up writing associated code in global functions.

Protocols are extremely limited. They're basically just collections of method declarations. There's no way to add functionality to every class which conforms to a protocol.

Objective-C is often verbose to the point of painful redundancy. Consider:

    NSString *x = [NSString stringWithFormat: @"%d", number];
Versus:

    let x = String(format: "%d", number)
Other examples include having to write the signature of every public method twice (once in the header and once in the implementation) and the need to do an annoying `self = [super init]` dance in every initializer.

There's almost no functional programming stuff available, like map and reduce. This is not strictly a language complaint, but since the standard libraries are pretty tightly woven in, I think it still counts.

Generics support is really limited. What's there was only added to interoperate better with Swift, anyway!

That's a quick overview of some of the ways Swift improves on ObjC. I'm sure there's more.

Re: Swift Programming Language Evolution

#53
post #24

Earlier quoted context omitted.

That's rich coming from a C# developer looking at mobile...

You may have missed the announcement where MS bought out Xamarin and is now giving it away for free. You owe it to yourself to at least give it a try while waiting for actual cross-platform Swift. 90+% of your mobile code can be shared between Android and iOS. Not sure if that's something currently possible with Swift or not, but it was worth keeping C# around for our needs. We're more of a "mobile app is something w…

90%+ shared code is a bold claim, Xamarin.com states 60-90%.

In my experience it's closer to 60%.

Re: Swift Programming Language Evolution

#54

A bit too late for wider adoption, isn't it? Are there examples of similar path to openness?

I don't see why that would be the case. The language has been public for less than two years, and I don't see any reason it wouldn't become widely adopted for situations where it's a good fit.

Re: Swift Programming Language Evolution

#55

So Swift has been out awhile, what do people think of it? What other language would you compare it to (e.g. C#, C, C++, etc)? What about the libraries are they well laid out?

Semantically, it's probably closest to Rust (from my limited exposure). The syntax is slightly changed, but most things have a direct parallel between the two languages. Although Swift doesn't do ownership/borrow checking like Rust does and is a lot more relaxed in that department.

Re: Swift Programming Language Evolution

#56

Earlier quoted context omitted.

Do you have a link to some benchmarks at hand? Your "possibly faster than C" claim sounds too good to be true without a source, but I'd very much like to be proven wrong :)

By http://benchmarksgame.alioth.debian.org/u64q/which-programs-... Swift's performance is similar to Java's, but quite a bit faster when working with many objects: http://benchmarksgame.alioth.debian.org/u64q/swift.html On a few benchmarks it's faster than C as well: http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan... though not most. I suppose they were able to do the binary-tree benchmark so much better…

I don't think these benchmarks are realistic. Yes, you can use UnsafePointers, but that's not the real world case. ARC, runtime generics and structs have a huge cost in real world programs.

Swift is unfortunatelly usually an order of magnitude slower then Java and C# in real world according to last benchmarks I've made. I'm hoping that will change because I really love Swift.

Re: Swift Programming Language Evolution

#58

Earlier quoted context omitted.

I'd put Go at the top of the languages to compare it to. Maybe Java as well. The ecosystem still needs some time, but Swift's potential on the server is excellent: - It is incredibly fast compared to current interpreted languages (i. e. factor 30+ vs. Python, possibly faster than C) - Linux & OS X, open source - Typed, safe People like node.js mostly b/c it allows some code to be written once and run on both the serv…

Do you have a link to some benchmarks at hand? Your "possibly faster than C" claim sounds too good to be true without a source, but I'd very much like to be proven wrong :)

See https://gist.github.com/MatthiasWinkelmann/d1f19a11d539e609f... for something quick&dirty.

Note that I don't want to claim that Swift is faster than C in general/real life/anything but a few microbenchmarks. But the two just being within an order of magnitude makes a really strong case for Swift, I believe.

Re: Swift Programming Language Evolution

#60
post #27

I've never understood the fascination with Swift. What's wrong with Objective C?

Don't get me wrong – I'm a big fan of Objective C, and I think it gets a far harder time than it deserves.

That said, Swift feels similar while being more productive:

- Lots of nice syntactic sugar to reduce noise - Optionals (and chained calls) which do much the same - Type inference! - A REPL. Pretty amazing. - Bounds checking

lots more nice features too.

Post reply on HN