Swift is great, but you should still know Objective-C first

Couldn’t agree more. I’ve always made the case that people should learn C as their first language, then take on an object-programming language beyond C (Objective-C, Java, etc.) That way, you’ll always know where C lets off and the object-superset of C begins. You’ll be able to write tight, performant C code as needed.

The question of whether to learn Objective-C and Swift is a bit different. Swift is a different language. Objective-C is a superset of C. Swift is not. That said, anyone developing for iOS or OS X will be working with a huge existing base of Objective-C code for a long, long time. Even if you are starting from scratch, there’s a wealth of how-to posts on the web dedicated to solving specific development problems. The vast majority of those are in Objective-C. The same is true for the sample code and reusable code posted in GitHub repositories and the like.

If you are a new developer, build a working knowledge of C, then Objective-C, then go out and master Swift. That’s my 2 cents.

UPDATE: I got a lot of pushback on learning C first. Some people think that C is dead. I disagree with that. There are APIs (and will be for some time) that require C (parts of Core Audio, Grand Central Dispatch, Core Graphics). So there’s that. There’s also the embedded space, which makes great use of C. There is also value in being able to move from iOS onto other platforms. Knowing C makes learning Java much easier.

That said, I do understand the logic in starting off with Swift as a first language, then taking on other languages as you need them. Nothing inherently wrong with that approach. As an example, I am starting my kids off with Arduino programming using C. They also understand binary, how masks work, and how pointers work. I think there’s real value in this nuts and bolts understanding of development. Again, my 2 cents, for a total of 4.



32 thoughts on “Swift is great, but you should still know Objective-C first”

  1. People also suggest you learn manual release/retain (MRR) before using automatic reference counting (ARC). I used MRR for years, and it really didn’t help me learn ARC. What helped me was understanding the object graph model, which was actually HIDDEN by MRR. I think knowing MRR makes it harder to learn ARC.

    Just looking at it and playing for a few minutes, I think Swift is another great example of this. Swift is a teaching language that’s actually more useful for day-to-day programming tasks than the language it replaces.

    If you’re a new developer, get the concepts down and learn the language you’re going to actually use. Code examples will come quickly.

  2. New coders aren’t going to be writing “tight performant code” at all. First they need to start thinking about very basic things, including the abstraction of objects, the basic concepts of programming, and so on.

    Starting with C and all of its low-level bare metal issues is strange to me. Great for advanced high school students or intro college students, but it’s not a starter language and no one doing a starter language is going to write tight anything.

  3. I wasn’t even going to mention the high performant code, but you’re absolutely right: That argument is raw bullshit. Due to its nature, Swift will produce faster executables than Objective-C. And for a new developer, Swift is going to produce more correct code than pure C.

    So thanks for poking me into saying something. 🙂

  4. ARC is slower at some tasks than MRR. Like C/Swift, sometimes you need to do things yourself.

  5. Why isn’t a new developer going to writing tight performant code? Many new developers are hired for projects where it’s necessary to write tight/performant code. If you don’t understand the basics and the theory, you’ll be forever relegated to searching stackoverflow for anything remotely challenging.

    I’ve seen it plenty of times. Code that should be fast was ridiculously slow and memory intensive. A few suggestions made huge improvements. And the new developers were quite happy to learn some new “tricks.”

  6. Agreed. This is applicable to any profession. Learn the theory, and the basics first. You appreciate the high level stuff first, and you understand how it works, which can help understand what’s going on when the high level stuff isn’t doing what you want.

  7. I think the “learn Objective C” crowd is missing a critical point here – Apple made Swift easier to learn than Objective C for a reason. The doors will now be open to developers who thought they might be interested in learning to write code, but were put off by Objective C. To give them the advice of “learn Objective C first” makes absolutely no sense for that crowd. And it’s a bigger crowd than people realize. And a year from now the number of Apple developers will be much larger.

  8. although i write C and Objective C most of the time, I am not sure learning C first is the best way. A pure functional language is a good way to start and learn fundamental concepts of computer science. For me, it was Scheme and ML(although I messed around with BASIC as a child) That combo of functional and then a bare-metal procedural language like C has enabled me to pick up other languages insanely quickly. C++, Java, Ruby, Python, Erlang, Javascript, and now Swift hold no surprises and I can appreciate them all for their strengths and weaknesses.

  9. Learning C is really good for one important thing: fundamentals. Knowing why a language or platform is doing something is at least as important as knowing how to use it. For example, if you tell people learning to program not to worry about your data types or whether something ought to be a constant or not, what inevitably results is sloppy code that’s expensive when it comes to CPU and RAM utilization. Why does this matter? It’s the same reason why Apple added enhancements to Mavericks to make the OS more power (and by extension, battery) efficient.

  10. Learn a lot of math (symbolic and abstract one, algebra, calculus, statistics, boolean logic), think algorithmicaly then approach any programming language you need with a reference book and the confidence you’ll master them all ’cause they’re just different accents from what you already know… Otherwise start with the one you think is best suited to the protect that really motivates you… That way you won’t give up easily… Have Fun and The Rest Will Just Come Along…

  11. I’ve been a C programmer for years and I love lots of parts of the language, and of course fundamentals are important. Fundamentals are always important. But you don’t need to learn C to learn fundamentals.

  12. Maybe they will! Why do you think it’s easier to do in one language than another?

    Most of the multipliers in performance are from concepts, not languages.

  13. MRR isn’t helpful there, is it?

    Understanding retain/release and object graphs will help you get memory management correct, but writing your own retain/release code doesn’t have to be part of that. And, judging by code I’ve seen, might actually hurt you.

    As for performance, sure. But again, knowing release/retain isn’t necessarily helpful there. That’s the way we MRR people are trained to look at it. But I submit it’s not a very good way to look at it.

    A better way: Why is this code (…) slower? Because it’s assigning a strong reference in a loop. Why is this code slower? Because this.

    Concepts, not mechanics. You don’t need to know that there used to be a method called retain for that; it’s enough to know it’s a strong reference, and there’s a cost associated with that.

  14. Swift is combing several paradigms including
    procedural of C, object-orienting of Obj-C and several
    functional programing concepts.

    right know Swift standard library is lacking
    so it can’t replace anything yet.
    right now It is not optimized enough to beat Obj-C either.

    Plus Cocoa is littered with Object-C and message passing concepts.
    Swift is not really supporting message passing even though
    it does support obj-c runtime just for compatibility reason.

    So Swift is trying to do everything well at the same
    time, it is trying to not be elegant as Obj-C.

    It can replace c if you need safety and security.
    it can replace obj-c if you need speed.
    It can replace scripting language if you need interactivity.

  15. The “learn C first” argument is wrong, but not because “C is dead.” It’s wrong because it saddles the beginner with a host of edge cases and implementation details that are irrelevant to her immediate goals. You can learn C later, as needed, to backfill knowledge, enhance performance or satisfy curiosity.

    And the Firskics article is poor: Swift, having been explicitly designed to work with Cocoa APIs, maintains the calling and nomenclature conventions in a rather clever way, such that nothing is gained (or lost) by using Objective-C over Swift in that regard. Ultimately, his entire article boils down to the “maturity” of the learning materials, which is a glaring conflict of interest given his involvement with Code School.

    You don’t need to know Objective-C first. The value in knowing Objective-C at all is primarily legacy code. For the complete beginner, going Swift-only is perfectly fine.

  16. I don’t like C*. I hope to never have to write another damned line of it again in my life.

    But it’s a damned useful thing to learn, as a programmer, and I’m glad I learned it – it gets you in touch with low-level operations in a way only matched, that I’ve seen, by assembler.

    (Which probably any programmer ought to know a little of just to be glad they don’t have to do it, but it’s also useful for knowing the kind of mess your code actually compiles down to.)

    (* No string type? Managing my own memory? No objects? What is this, 1972?)

  17. “Many new developers are hired for projects where it’s necessary to write tight/performant code”?
    Maaaybe.

    But they’re not going to be any good at it until they’re not new anymore.

    (By which I mean, that job is their OJT for learning how to write tight code.)

  18. XCode?

    I’m not sure it counts as C if you’re not writing makefiles and editing in vi and pretending it’s not 1980 yet.

    (I am only half kidding.

    Not that I think using stone knives and bearskins is good – but C is itself stone knives and bearskins territory.)

  19. Also, snarkily: Knowing C makes learning Java much easier.

    Admittedly, a good argument against knowing C: you might be tempted to learn Java.

    And then you might try to use Java.

    I am at this point much of the opinion (and this part ain’t snark) that, for everything other than server-side backend use, Java should be regarded like Flash: A sign you’re doing something wrong, and a runtime I try to avoid have sullying and un-securing my hardware whenever possible.

    Yes, it’s portable.

    So’s syphilis.

  20. I am not a C programmer. I only use enough Objective-C to get things done with much tutoring. I don’t know where Swift is going to fall here. but, I am eager to learn.

    I also like the idea of new high level languages emerging to make programming for platforms easier.

    I imagine a day when writing any code that isn’t tuned to the task will be a thing of the distant past.

  21. No, that is absurd. It is totally absurd. Should you learn Latin before you write a novel in English? Hell no. Get on with writing your novel.

    “You should learn C first” is exactly as arbitrary as “you should learn FORTRAN first” or “you should learn Latin first.”

    In fact, saying “learn Objective-C before Swift” is even worse than that — Swift was created as a replacement for Objective-C. So that you don’t have to learn Objective-C. So saying “learn Objective-C before Swift” is like saying “before you use Photoshop version 11, learn Photoshop 10, or Photoshop 7.” It is absurd.

    I learned to program with AppleScript because I wanted to automate graphics workflows. Later, I learned JavaScript to be able to program for the Web, and all the things I had learned for AppleScript made learning JavaScript much, much easier. Then I took on a project that required a small amount of PHP, and I learned that basically overnight because my JavaScript and AppleScript experience had taught me to program, and it didn’t matter as much anymore what language I was working in. Now, if I want to make an iOS app, I can learn Swift because it is the right tool for making iOS apps, and the fact that I already know how to program will make that much easier than starting from scratch in Swift.

    But if the first programming project you ever want to do is an iOS app, then just start in Swift and get your app done. The fact that you have a practical purpose and get practical results from your Swift learning will propel you through the hard work of learning programming. Later, you may want to make your app cross-platform, so you may want to do a hunk of it in C. Or you may not. Scratch that itch when you come to it.

  22. No, that is absurd.

    Junior developers write code. Senior developers do optimizations. If you are only just learning programming, you are not even a junior developer yet — you are only a novice developer. Once you move from novice to junior developer, you can learn optimizations on your way to becoming a senior developer.

    So the original poster was quite right in saying that novice developers are not going to write highly optimized code while they are only just learning to program. Sure, you can teach them some senior developer tricks, but you may not really be helping them if they don’t understand why those tricks work. They should stay focused on learning and on writing concise, readable, functional code that can be optimized by a more-experienced developer.

  23. It is like telling a new driver to learn the stick shift before driving automatic, when 99% of cars are automatic. They should learn the stick shift only if they want to drive stick and either have a stick shift car or are about to buy one.

    People who already know Objective-C (or stick shift) forget that it took them a long time to learn that, and that they had no other choice but to learn it. Once you have a choice of an easier/faster way, that is always the most sensible, because people have apps to make and places they need to drive to. We are not immortal academics, sitting around some University with infinite time to learn Latin before English and so on.

  24. Don’t tell me it’s absurd. In an ideal world, you are absolutely correct. But we don’t live in an ideal world and all organizations don’t work the way they should. I’m speaking from experience here.

  25. I agree that concepts are the bigger factor.

    But things are easier to do in different languages because languages differ greatly in design. If it were just as easy, then one language would simply be a syntax translation from one to another.

    Just look at this article: http://www.splasmata.com/?p=2798

    In Swift you can’t control the creation/destruction of types which could lead to performance problems. What’s the solution here? Unless Swift gains a new feature (which it could at this point, I admit), the solution is to write in C or objective-C.

  26. You guys are acting as if C is akin to learning
    Sanskrit – it’s not.
    It’s not impossible to learn a lower level language as your first
    language. My first language was C++. Was it a challenge? Sure. Impossible? Hell no. Is learning a higher level language easier? Sure. More efficient? Sometimes. Does it spoil you a bit? Probably.

    I don’t think the argument to learn C is arbitrary, as a ton of modern languages are descendents of C or share a similar syntax(C++, Objective C, C#, Java, ect)

    Sooner or later in programming you will have to
    work with a library or example written in C, so you might as well know it, but really, What language you learn first should probably be whatever language you will end up using! If you want to develop console or computer games, C/C++ is probably a good place to start. If you want to develop mobile or web apps, maybe think about learning Java. If you want to program mac stuff, Objective C/Swift is necessary. But apart
    from learning a language (and really once you know a language like C it’s not too difficult to learn another) a lot of programming comes down to learning libraries, frameworks, and APIs. Unless you plan on writing device drivers or something, these will be more important to learn than individual languages, IMO.

  27. I finally start to learn IOS development because the announcement of swift. Objective-C for me, a busier developer in other platforms, is just to weird and cost to learn, I can’t even read a piece of code in objective-c without twist my eyes! :-). In my perspective is more or less that way: Ok we have this concept that is two lines in Java, now many lines after in objective-c my brain is reluctant to learn. With swift I can instantly read, recognise, and start coding and learning the underline concepts (that are similar to other languages). Even method call vs message call in objective-c is strange, I can’t read instantaneously.

  28. I believe that having the opportunity to learn C, Assembly or whatever closer-to-the-metal language is always a good thing. It can be quite painful, but it is the best way to have a better understanding on how the magic of computing really works under the hood. It WILL give you more power on any *nix environment. Not to mention that most languages in the world can be at some point traced to plain C. It is like the alphabet of coding. That being said, some people can get really scared when they first try programming anything. And some people really don’t care about how the hardware work if it works. I still think C is the most beautiful thing 🙂 (not a longed multi-decade curse as many think).

  29. You like Java more than Objective-C? That it? I’m the opposite… Also, if you compare an Obj-C / Java implementation of any app the Java is always more lines of code. Steve Jobs even made videos about this when he was still at NeXT. Being a superset of plain C, Objective-C kind of requires C knowledge. But I really like the use of [ ] to Obj-c code (which seems to be something people dislike most). And Java is interpreted while Obj-C is compiled to machine code. But yeah, I can see Swift being used at schools and Universities. Seems to be easy enough and playgrounds add a lot to that.

  30. I think java model is easier that objective-c. Java is not direct interpreted, is compiled to byte code than interpreted, that helps improvement in performance, it’s not raw performance as machine code but in some cases are close. My personal view of object-c is that even if you write less, is difficult to read, and in large systems you read more than you type. I don’t see Swift as a academic only language, because is a modern language with raw performance and a lot of concepts designed for professional use, like non nullable types, closures, classes, generics, protocols, extensions and Automatic Reference Counting. It align with the modern move in other languages. Also, apple will never make a joke with something as important as a language to substitute the language that runs it platform, is like suicide.

Leave a Reply

Your email address will not be published. Required fields are marked *