Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


I'd add typed enums to the list of notable bug-avoiding improvements in Swift. I sometimes describe Objective-C as "all of the memory safety of C with the type safety of SmallTalk".


I may steal that quote; I think I like it better than calling Objective-C the "wild west of OOP".


We can even use string interpolation

    let x = "\(number)"


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.


Swift is much more type-safe (and modern overall). Also its OO-model similar to C++ with direct method calls instead of sending messages which results to better performance.


Objective-C likely suffers from similar problems of C and C++. It's just too easy to shoot yourself in the foot with these languages.

Rust, D, golang, swift all appear to share a common goal of having a mid-to-low-level imperative/OO language that has learned from C/C++/ObjC's mistakes.


[nil someMessage]

Though some consider this a feature, YMMV.


Too many times have I forgotten to initialize some member and just had things silently fail in strange ways. Swift checks for uninitialized "let" variables or non-optional "var"s




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: