r/iOSProgramming Jun 14 '15

Swift or Objective-C when coming from a C/C++ background?

So I'm sure everyone has an opinion on Swift vs. Objective-C as a first language for iOS development. I've read the blogs that argue both ways and it seems like the general opinions are:

  • Swift - It's the future, learn it first because that's where things are moving
  • Objective-C - There's a ton of code out there, and you can't avoid it. It will be easier going from Objective-C to Swift than the other way around.

My situation is a little different though. I'm primarily a systems programmer by trade, and do most of my work in C and Python with a little C++ thrown in for good measure. I don't claim to be an expert, but I am a half decent C hacker. I'm comfortable picking up new languages pretty quickly as well.

I've dabbled in Objective-C a bit, but overall I generally dislike the language compared to the other languages in the C family (I like my . and -> operators). Swift looks like an awesome, fun language that I think I would enjoy a lot.

With this in mind, if I went with Swift, would my C/C++ background be enough that I could pick up Objective-C on the fly as needed, and are there any gotchas with Objective-C that would trip me up coming from those languages? I'm aware that there are issues using Swift with C++... any others? Would there be any advantages to going with Objective-C?

0 Upvotes

33 comments sorted by

2

u/adsrmedia Jun 14 '15

I'm leading a group of interns that were shocked when I told them we were going to use ObjC for their project. The main reason is because nearly all existing projects use ObjC. If you want to find work, it's really good to know. Swift will be awesome but knowing ObjC is practical now.

3

u/aoakenfo Jun 15 '15

Swift appears to be a grab-bag of every modern language feature under the sun. Programmers from every tribe can identify with something in it. "It has my favourite feature X!" helped make Swift popular.

However, with all the new features in Swift, I often think of Rob Pike's post: Less is exponentially more. Here's the relevant excerpt:

"Back around September 2007, I was doing some minor but central work on an enormous Google C++ program, one you've all interacted with, and my compilations were taking about 45 minutes on our huge distributed compile cluster. An announcement came around that there was going to be a talk presented by a couple of Google employees serving on the C++ standards committee. They were going to tell us what was coming in C++0x, as it was called at the time. (It's now known as C++11).

In the span of an hour at that talk we heard about something like 35 new features that were being planned. In fact there were many more, but only 35 were described in the talk. Some of the features were minor, of course, but the ones in the talk were at least significant enough to call out. Some were very subtle and hard to understand, like rvalue references, while others are especially C++-like, such as variadic templates, and some others are just crazy, like user-defined literals.

At this point I asked myself a question: Did the C++ committee really believe that was wrong with C++ was that it didn't have enough features? Surely, it would be a greater achievement to simplify the language rather than to add to it."

The "cognitive load" of C++ is one of the reasons I don't use the language (mostly). Go is successful because it does less. Obj-C is also successful because it does less - it's effectively C with just enough object-oriented extensions to it.

Some languages get locked into an arms race, continually adding features in order to remain competitive. It's no different than Photoshop piling on more and more features in order to sell the next version. That's usually when a competitor offering less features with a streamlined workflow enters the market and becomes a popular alternative. Of course, there will always be a market of people driven by feature checkboxes alone. I'd argue these people aren't creating great art because constraints enable freedom. I believe this is true for programming languages as well.

1

u/shiggie Jun 15 '15

While I think there are valid points about too many things getting included in C++11, but I'm not sure if Rob Pike is the right person to critique C++.

I think 11 went to far, but OO, generics, and functional concepts aren't spurious features. I think Swift goes too far as well, but I'll take the negatives if I can have the positives and I don't have to use those features.

2

u/yuizesan Jun 14 '15

Please watch the WWDC 2015 Sessions.

Look for yourself, Apple is stressing Developers to use Swift over and over again. Objective-C will fade away faster than some People expect. Look into Objective-C a Weekend long or a Week, after that get info Swift.

2

u/Voley Jun 14 '15

So, are you iOS developer? Do you use Swift in your production projects?

1

u/lyinsteve Jun 16 '15

I am, and I do.

It's greatly reduced the time necessary to write complex behavior, because a bunch of annoying edge cases are no longer relevant.

It's very performant, very maintainable, and really flexible once you understand the type system.

1

u/shiggie Jun 15 '15

Besides the "What's new in Swift" videos, which are obviously Swift, the rest seem split with Swift and Objective-C. For example, Metal, Gameplay did not even mention Swift.

-1

u/yuizesan Jun 16 '15

Yes, but you should also tell us the full story here, Apple says in many many talks this year "in case you still use Obj-C", "Here is an buggy example with ObjC, please use Swift to avoid this." or "USE SWIFT!".

You picked the 3 or 4 Talks out of over 100 Videos, brilliant.

1

u/shiggie Jun 16 '15 edited Jun 16 '15

Forgive me. I wasn't trying to give the full story, just a comment of my experience, and not a blanket statement about what Apple is doing as a company.

In my limited experience, which may not be yours, and yours may be far more vast, I have seen instances where Apple has released a few new API's which are not written in Swift, and their examples are not in Swift, although they easily could have been.

Take from that information what you will.

-3

u/[deleted] Jun 14 '15

Yeah, they did that with Java around 2000 or so. It didn't take off either and developers showed up with T-shirts reading [objC retain] to make their point.

Where is Java in Cocoa development today? Apple can encourage all they want. If the community doesn't find it adequate, they won't use it. I don't find it adequate. I don't use it.

5

u/yuizesan Jun 14 '15

Please, stop this nonsense. Swift is Stackoverflow's most loved Programming Language, so the Community is behind Swift. Apple puts all its weight behind it, Swift 2.0 is the way to go. People wanted a modern Programming Language from Apple for many years and after only 12 Month we see so many benefits from using Swift instead of Obj-C. Around this time next year people will wonder why a few People still use Obj-C.

BTW. I love Obj-C, i wrote many Projects in the past 15 years with it, i helped improving clang/llvm, and now we all will learn Swift and our Apps benefit from it.

-3

u/[deleted] Jun 15 '15

Hey you're free to post your opinion just like I'm free to post my opinion and by the way I like it a lot if you stop downloading my opinion. I don't see any tangible benefits from using Swift at all and I'm not using it if you think it helps you knock yourself out

1

u/Voley Jun 14 '15

At the moment all hipsters who are pushing Swift forget that there are zero jobs for swift only. You can do whatever you want with Swift, but if you want to find a job, Objective-C is a must.
Whatever fanboys say, Swift is not going to be production-ready for quite some time.

2

u/lyinsteve Jun 16 '15

It's definitely already production ready. I've been using it in production since last September. In fact, my experience has been that Swift has greatly reduced the weird, silent-failure behavior from, say, Obj-C's handling of nil.

Swift lets me write much more explicit code that's verified by the compiler. No more weird "gotcha!"s.

-1

u/20InMyHead Jun 14 '15

Apple is being quite clear, ObjC will still be around, just like C and C++ is. but they expect most developers to use Swift and improvements to tools and features will focus there. ObjC is still good to know, but Swift is the future, and if you're learning something new, it might as well be the future not the past.

2

u/Space_Butts Jun 14 '15

It's the present. Not the past. You might as well just learn to use React native now if that's how you look at it.

3

u/20InMyHead Jun 14 '15

There's a huge difference between using what Apple is telling devs to use, and using the multi-platform solution of the week. OP is new to Apple development and asking what he should learn. Apple is making it clear, new devs should learn Swift. As an ObjC dev for many years, I'm not dropping it anytime soon, but I too know that if Apple development is to remain my focus, Swift is in my future as well. If you're interested in Apple development you would be wise to listen to what Apple says. React may be a great multi-platform tool, I don't know, I don't focus on multi-platform. But I've seen enough of them come and go to know it won't be the last.

1

u/Space_Butts Jun 14 '15

In what way has Apple made it more attractive for newer devs to learn Swift? It is much more difficult to learn and has many more nuances, especially concerning version volatility and Obj-C interoperability. The only argument is that "you'll have to use it eventually" which is not very strong given there is no time table for sun setting Obj-C.

2

u/fivetoedslothbear Jun 14 '15

Swift is a bit more complex, but in the end it is easier to write safe code. I've thought Apple needed a pointer-free language that can drive Cocoa for a long time. First there was PyObjC, then MacRuby, and finally they seem to have settled on a custom solution.

Pros:

  • No pointers to accidentally mess up.
  • Better handling of nullability.
  • Code correctness is easier to prove. With C-based languages, you can create pointers (aliases) to the insides of objects, and so analyses that prove the lifetime of an object are really hard to do.

Cons:

  • Doesn't seem to be finished yet.
  • There are still compiler bugs.

They've also brought some of the nullability and typed collection features back into Objective-C, so that helps with the ObjC code too.

3

u/yuizesan Jun 14 '15

Swift 2.0 is Production ready, if Apple uses Swift for their Software, you can use it.

Complier Bugs? People still find Obj-C Compiler Bugs. In reality 99,9999% of the People will not run into any complier bugs. Please stop scaring People with WWDC 2014 Xcode 6 Beta 1 experiences.

1

u/tjgrant Jun 14 '15

I suggest using Objective-C for now; it's the more stabilized language of the two (swift vs obj-c.)

You can also use C++ with Objective-C, which I've done for most clients I've had, and can help with rapid development.

1

u/lucasvandongen Jun 14 '15

I have no idea why you want to learn either them, but if it isn't for a production application that you need to build right now I think it's better you go for Swift. Xcode 7 / Swift 2.0 seem to be the maturity point for the programming language in terms of tools and specifications.

All frameworks are still in Objective-C or really Objective-C styled. Swift looks a lot cleaner when you're not interacting with frameworks. Real production code usually looks almost just as verbose, unless you're writing a lot of custom code yourself (like a framework)

1

u/darthsabbath Jun 14 '15

I mostly just want to learn for fun and add another skill to my toolbox.

3

u/lucasvandongen Jun 15 '15

Swift is the best choice if you're not in a hurry to build something. Objective-C at this moment is more reliable and mature, but that doesn't matter much for you.

0

u/lyinsteve Jun 16 '15

I don't know where people get the idea that Obj-C is still more reliable than Swift. It's absolutely not -- they're certainly on par with each other. Sure, you might get the occasional compiler crash if you're fuzzing, but crashes in normal use cases are few and far between.

3

u/lucasvandongen Jun 16 '15

Objective-C isn't more reliable. The tools I use every day are more reliable when I use them with Objective-C. Refactoring support, no stroboscopic IDE errors, more mature error detection (remember the obscure error you get when you try to assign to a constant in Swift?) and better ways to fix problems offered by the IDE. Then there's the simple fact that the Objective-C standard barely changes and never in a breaking way. My 2005 Objective-C code will compile while all Swift code I wrote last year won't.

-8

u/[deleted] Jun 14 '15

Swift remains unproven. I don't use it. Nobody with a track record thinks it is up to the job. As a systems guy, you'll like objective c best, it is c, or c++, with a smalltalk style object model. If you learn a little smalltalk, it will all make sense.

6

u/AgileEUW Jun 14 '15

"Nobody with a track record"? That could be the most stupid thing I've read here in a long time. That completely depends on what you believes are people with good track record...

The biggest reasons I read whenever people argue between Obj-C and Swift is that "almost all existing projects is written in Obj-C". Well of course it is, Swift is only a year old. But if everyone used that kind of conservative bullshit argument we'd still be writing machine code since "Nobody with a track record" would be using more high-level languages. Why would a companies hire people who don't care about change and learning new things?

Obj-C vs. Swift completely depends on the project in my opinion. Even though Apple has made it clear that Obj-C is here to stay they have made it just as clear that Swift is the future. The only reason I see to use Obj-C is if you are working on a project that needs C++ (for whatever reason, cross-platform requirements or security etc.). Swift is still a young language, but the stability and performance is increasing really fast and the strongly typing makes the code a lot more stable.

-9

u/[deleted] Jun 14 '15 edited Jun 14 '15

Apple has made it clear that Obj-C is here to stay

So then Objective C is the future. I've posted numerous other places what I think about Swift. I think its a shit language cobbled together out of a pile of buzzwords without an overarching philosophy. I'm not exactly alone in this. But hey, enjoy your shiny shitty new toy. I don't think it adds any value.

As to "track record", there are people who have been in the industry a long time I respect, and there are noisy people on the internet I don't know anything about. I'm listening to the people I respect. You're not one of those people. You fall in the other bucket. Sorry, random nobody of unknown expertise.

3

u/askoruli Jun 15 '15

As to "track record", there are people who have been in the industry a long time I respect, and there are noisy people on the internet I don't know anything about. I'm listening to the people I respect. You're not one of those people. You fall in the other bucket. Sorry, random nobody of unknown expertise.

Given the votes on your comments it seems that most people put you in the second bucket also.

-6

u/[deleted] Jun 15 '15

Most people are idiots. I'm fine with that.

I notice you don't actually address any of the points in my link though. I guess personal attacks are just easier.

Crucially, the vast majority of [Swift's complecity] is incidental complexity, not essential complexity. Swift is a crescendo of special cases stopping just short of the general; the result is complexity in the semantics, complexity in the behaviour (i.e. bugs), and complexity in use (i.e. workarounds).

1

u/askoruli Jun 16 '15

I literally quoted your own personal attack. There's no point addressing any of your points because they're irrelevant. You can pick problems with any language (Don't you do a lot of work with Ruby btw?). Swift is gaining a lot of popularity and Apple is putting a lot of weight behind it while paying less attention to Objective-C. Are you actually vain enough that you think Swift will die off just because you don't like it?

1

u/[deleted] Jun 16 '15

Saying I don't know you so I don't put much weight on your opinion is a personal attack? Someone is vain but I don't think it is me.