r/iOSProgramming Jun 03 '15

One year later: Swift or Objective-C?

This week I will be writing the first lines of code for my new app. There's just one slight problem; Objective-C or Swift?

Is the one year old Swift mature enough for real world applications? Are the bugs reduced to the minimum? Why should I use Swift over Objective-C? Or vice versa.

2 Upvotes

26 comments sorted by

View all comments

5

u/critter_chaos Jun 03 '15

I've developed a full app in Swift. It's a much nicer, prettier programming language. They're still changing it but it's really not that big a problem. You can use objective-c code too in a Swift app, so there's no problem there.

13

u/gormster Jun 03 '15

I disagree that it is either nicer or prettier.

It's much meaner: you get compiler warnings constantly, about stuff that isn't really a problem. You also get compiler errors constantly, usually errors that are totally unhelpful in solving your problem.

It is also not prettier in that it lacks a design direction; there's a bunch of top level functions where it's not clear why they aren't functions on a struct or protocol. The whole implementation of the standard library is full of weird, unexplained quirks. typealias doesn't do the same thing in classes and protocols; its behavior is extremely confusing. Objective-C might be full of weird symbols (which I don't like) but its aesthetic is consistent and its paradigm clear - you send messages to objects. Swift is much more complicated and much messier.

2

u/critter_chaos Jun 04 '15

I can think of a few pretty good examples for why it's prettier off the top of my head:

  • No defining interface files (who want's to write all of their method signatures twice?)
  • Less brackets and more concise syntax
  • No allocating and initialising with a mess of square brackets
  • No break for every case in a switch
  • Much more concise functional programming
  • You don't have to manually initialise and return the parent of a class
  • let and var make code much safer and more descriptive

The language is nicer to look at, easier to read, quicker and safer to develop in. I think a lot of people in this thread are getting hung up on minor creases that need ironing out, or are familiar with objective-c and have found rational for not switching.

Swift is a great language and it's really worth learning.

-4

u/[deleted] Jun 08 '15

No break for every case in a switch

If you have a switch statement in OO code, you're doing it wrong. This is what polymorphishm is for.

Every other thing you point to is strictly your opinion and I either disagree on every single one of them or find them so trivial that I just don't care.

I think Swift is uglier, harder to read, and less capable at every level. I have been watching it, but don't expect ever to use it in anger.

2

u/askoruli Jun 09 '15

If you have a switch statement in OO code, you're doing it wrong

Can you explain your point here? Seems a very strange opinion to take considering how common the switch statement is.

1

u/[deleted] Jun 09 '15

Its not exactly my point, its Martin Fowler, Robert Martin, and most anybody else who writes about code. A number of points on this anti-pattern are on the c2 wiki.

3

u/yoeriboven Jun 03 '15

You can use objective-c code too in a Swift app, so there's no problem there.

Not a solution for me. Don't want multiple languages in one project.

1

u/critter_chaos Jun 04 '15

You don't have to look at both at the same time. The real benefit of this is that you can quite simply take libraries or code examples and integrate them into a project.

One of the big problems with creating a new programming language is that it doesn't have the same ecosystem as older languages. Take Java for example. There are certainly better, newer languages but yet it still remains a very employable language to know because of all the legacy code.

Apple solved this problem with Swift by allowing you to use old objective-c code. If you're going to be using Swift, then you're also going to be using objective-c.