PodSearch

Developing Perspective

#78: Managing 3rd Party Libraries.

 

00:00:00   Hello, and welcome to Developing Perspective.

00:00:03   Developing Perspective is a podcast discussing news of note in iOS development, Apple, and

00:00:07   the like.

00:00:08   I'm your host, David Smith.

00:00:09   I'm an independent iOS developer based in Herndon, Virginia.

00:00:11   This is show number 78, and today is Tuesday, September 11th.

00:00:15   Developing Perspective is never longer than 15 minutes, so let's get started.

00:00:19   All right, so I'm going to be continuing on my process that I started in the last show,

00:00:24   kind of this arc I'm going to be doing about developing a new project from start to finish.

00:00:31   And I really appreciate all the people who sent me questions, feedback, comments about

00:00:35   that.

00:00:36   I've been collecting them all on Twitter and email and all that.

00:00:39   I'm not really able to reply to everybody, so just know that everything you send I will

00:00:43   read and I will try and incorporate as best I can.

00:00:47   Sometimes there's duplication, sometimes there's not.

00:00:49   It's just kind of impractical to actually respond to every person individually for exactly

00:00:53   how I do that.

00:00:54   But hopefully the results is positive, and I just want to encourage you, if you have

00:00:58   those thoughts, I definitely appreciate getting them, and by all means keep sending them in.

00:01:03   I really like it on Twitter, just because it's short and succinct.

00:01:06   If you're going to send me an email, please try and smush that down to sort of a kernel

00:01:11   of what it is that you're asking, just to make my life a little bit easier.

00:01:15   And just probably a note, tomorrow is of course announcement day, which is very exciting.

00:01:19   I'm recording this on Tuesday, September 11th.

00:01:22   Tomorrow, Wednesday, September 12th is the big Apple announcement, new iPhone, all that.

00:01:27   I may do an extra episode to cover that, or maybe do it as Thursday's episode.

00:01:31   I'll just have to see based on how it goes.

00:01:33   All right, so for the main topic I'm going to talk about today when you're building a

00:01:36   new project is talking about a little bit of one more thing on prototyping and then

00:01:42   how I manage third-party libraries.

00:01:45   So first, one more thing about prototyping.

00:01:46   I've got a couple of little questions about that, and I think an area that I wanted to

00:01:50   cover is just sort of the importance of encapsulation when you're prototyping.

00:01:55   And if you're not familiar with encapsulation, or it goes by all kinds of different names,

00:01:58   I'm sure, but when I say encapsulation, what I mean is the taking functionality and grouping

00:02:04   it into distinct classes so that you organize the logic of your application into smaller

00:02:09   and smaller parts that have smaller and smaller roles and more and more focus.

00:02:14   And this is really important when you're prototyping.

00:02:17   It's in general a pretty good practice.

00:02:18   You can get carried away with it for sure.

00:02:20   But what I find is really important is

00:02:23   sort of having as loose coupling

00:02:26   between components as you can.

00:02:28   And by that I mean I want to be able to pull things

00:02:31   in and out and sort of, oh, change my mind,

00:02:33   throw this away, oh, might change my mind,

00:02:34   throw this away, and have that effect

00:02:36   as few things as possible, or affect things

00:02:38   in as defined of an interface as possible.

00:02:41   So as an example, I recently completely changed

00:02:45   my data provider underneath the weather application.

00:02:48   I was trying one, found some things I didn't like,

00:02:50   moved to another.

00:02:52   Okay, that's great.

00:02:54   And what I ended up having to do is I really only had

00:02:56   to change it in one place because I'd encapsulated

00:03:00   all the data loading functionality into sort of a class

00:03:04   two or three level steep so that all my view stuff

00:03:07   didn't even know that anything had changed.

00:03:10   It was all being provided the data in exactly the same format as it was before, it just

00:03:13   happened to come from a different source.

00:03:15   And all I had to change was the thing that was doing the setting the URL that I wanted

00:03:20   to get the data from, and then my actual sort of parser that was taking that and moving

00:03:24   it just from a JSON blob into sort of domain objects in my application.

00:03:29   And so by doing that, it made that process really easy.

00:03:31   And it was also very dependable for, I knew I didn't break a lot of things in doing that.

00:03:37   So that's just something that I do a lot,

00:03:42   is when you're creating a new project, especially early on,

00:03:44   don't feel scared of just,

00:03:47   it's like, "File new file, make a new class,

00:03:51   "make a new class, make a new class."

00:03:55   Have lots of classes.

00:03:57   A lot of them you end up throwing away.

00:03:57   I've probably deleted about 12-ish classes

00:03:59   since I started this project.

00:04:03   Things that I built, tried, didn't work, threw it away.

00:04:03   But it allows me to do a lot of things really quickly and really safely, rather than if

00:04:07   you end up squishing lots and lots of functionality into one thing.

00:04:10   It's really important generally to do that, but it's really, really important when you're

00:04:13   prototyping early on to do it.

00:04:16   Because you feel like you're saving time.

00:04:18   If you're sort of, "Oh, I'll just throw everything into this one logic, or in one place.

00:04:23   I'll have my one view controller that has everything in it."

00:04:26   There's a place for that maybe, but if you're ever ... And that's really only for true throwaway

00:04:32   prototypes I could see doing that,

00:04:37   where you are building something expecting to throw it away.

00:04:39   It's like a proof of concept.

00:04:42   Maybe you can do probably your logic into a view controller.

00:04:43   But if you're building something that you're expecting

00:04:46   to actually ship at some point,

00:04:47   but you're prototyping it, your early phases,

00:04:50   your early iterations on it,

00:04:52   then it's important to break things up as much as you can,

00:04:54   because it gives you so much more flexibility and speed

00:04:57   while you're doing that prototyping phase.

00:04:59   And so then the next thing I was going to talk about

00:05:04   is managing third-party libraries.

00:05:06   And I got a lot of feedback on that,

00:05:08   and I got a couple people who said it was great,

00:05:10   that I said, "Oh, I use AF networking.

00:05:12   It's the best."

00:05:14   And there's a lot of third-party libraries

00:05:15   that you'll end up using typically,

00:05:17   and often you're going to want to talk,

00:05:19   you want to use third-party libraries,

00:05:21   but they make your life easier.

00:05:23   And that's a very hard thing to judge, potentially.

00:05:26   It's often sometimes like, "Oh, here's this guy

00:05:31   who does this library that does exactly what I want."

00:05:33   Make sure that it is actually exactly what you want.

00:05:36   Typically what I find is I never really use

00:05:38   third-party libraries for functionality that is,

00:05:41   I suppose, specific to my application,

00:05:45   or in the same problem domain as my application.

00:05:48   I almost always write that custom,

00:05:50   because it's very unlikely that a third-party

00:05:52   general-purpose solution is going to fit

00:05:52   for what exactly I want.

00:05:57   Where third-party libraries and open-source code

00:05:58   really come into play is when you are doing something

00:06:00   that's very orthogonal, that's very distinct

00:06:04   from your application.

00:06:06   So the great example there is something like a networking stack.

00:06:07   My app is not about networking.

00:06:10   I don't really care how I go from a URL to a blob of JSON.

00:06:11   I just want a URL blob of JSON.

00:06:16   And so ASN like AF networking makes that really, really simple for me

00:06:17   and handles a lot of the weird edge cases,

00:06:22   and things that I'd have to do anyway.

00:06:24   Another example is JSON parsing.

00:06:27   I don't really care how I go from a JSON string

00:06:29   to a collection of NS dictionaries,

00:06:33   NS arrays, NS numbers, NS strings.

00:06:37   I don't really care how that translation happens,

00:06:41   so I go ahead and do it.

00:06:43   Using that as a broad guide, though,

00:06:43   I think is really constructive,

00:06:48   to make sure you're not doing things

00:06:50   that you really don't want to.

00:06:52   And so that's sort of the first part,

00:06:55   is how do you decide when to use one?

00:06:57   And it's always worth playing around with

00:06:59   and looking around, seeing what people have done.

00:07:02   What I find I do more often than necessarily using

00:07:03   third-party libraries in open source is I'll look for

00:07:06   inspiration inside them.

00:07:08   So if someone's done something similar to what I'm doing,

00:07:09   So say someone's doing, as an example,

00:07:14   I do, in my weather app, I have some charts

00:07:17   for showing the forecast over the day

00:07:20   and some of those kinds of things.

00:07:23   And I don't, there's all manner of third-party

00:07:25   graphing clients that I could use.

00:07:29   But the thing that I was looking at is,

00:07:32   the thing is, what I want is,

00:07:34   I want it to look a very specific way.

00:07:35   And this is what I'm getting at,

00:07:37   where I have a very specific domain need for my application,

00:07:37   So it doesn't necessarily make sense to do it just generally like that.

00:07:42   And so instead of using a third-party plumbing library, what I did is I wrote my own.

00:07:46   But I went and I looked around at how other people are doing charts, how other people are doing graphs.

00:07:55   Just looking in their code.

00:07:59   Don't feel like you're going to GitHub, you can browse the project right there, you can look at the code, see how, "Oh, that's how they do it."

00:08:03   and that's how they got their performance up, or whatever.

00:08:08   That's a great tool for a third-party code

00:08:12   that you then are picking and choosing the concepts

00:08:15   and bits and pieces from that project,

00:08:17   but then ending up with a really custom,

00:08:20   sort of highly-tuned version of that

00:08:23   for your particular application.

00:08:25   So that's something else I do.

00:08:27   And then lastly, what I wanted to talk about

00:08:28   is how I organize my third-party libraries.

00:08:30   And I recently, and this is the first time

00:08:29   I've ever done it for this project, I started using a thing called CocoaPods.

00:08:34   And CocoaPods, if you're familiar with a package manager from another language, say for example

00:08:39   like gems in Ruby or I think Python, PHP, a lot of them have these kind of things that

00:08:45   are designed to bundle up functionality in a way that is easy to sort of pull in and

00:08:51   out, that you can version well, that you can reference directly in your source control.

00:08:56   And CocoaPods is one that's designed to do this for Objective-C projects.

00:09:02   And the great thing about it is it integrates really well with Xcode.

00:09:05   And so a little bit of sort of how it does it, I recommend just looking at their website

00:09:10   and going from there.

00:09:11   But what CocoaPods do is it takes your Xcode project and moves it inside of an Xcode workspace,

00:09:19   which if you're not familiar with, a workspace is just a collection of projects that Xcode

00:09:23   is aware of.

00:09:25   and you can share code between and kind of when you build, it builds both projects.

00:09:28   But it creates its own project, the pods project, that handles all the third-party libraries

00:09:34   for you.

00:09:35   And so that has this really nice effect of separating them out from your code so you

00:09:39   don't have to worry about them there.

00:09:41   And it's also handling all of the other stuff that you would sometimes need to do in terms

00:09:46   of linking frameworks and all this stuff.

00:09:48   All the extra frameworks that you need for this are all pushed over into the pods directory.

00:09:53   They're not in your own code.

00:09:55   And so that's really nice from a cleanliness perspective

00:09:58   of keeping your project clean and light.

00:10:00   And whenever you install a new pod, I guess they'd call it,

00:10:05   it adds it to that, it updates its own Xcode project.

00:10:08   It's a project that you should never edit yourself,

00:10:10   because it's always going to be overridden,

00:10:12   and it's kind of like CocoaPods manages that for you.

00:10:14   But it works great.

00:10:15   And you want to add a new one, you just

00:10:17   added it to your pod file, which is a little thing where

00:10:19   you specify, like, I want AF networking version 1.0 RC2.

00:10:23   or whatever my current one is, and you say pod install,

00:10:26   and it installs it.

00:10:27   That's it.

00:10:28   You can say pod-- you can delete it, and then do pod install,

00:10:31   and it'll delete it.

00:10:33   You can search for different ones.

00:10:34   You can do like pod search, JSON,

00:10:36   and it'll give you a list of JSON file-- of JSON libraries

00:10:39   that exist that you can choose from.

00:10:41   There's a lot of really nice things like that,

00:10:43   that I've started using it, and I think I really will probably

00:10:46   be moving forward.

00:10:47   If you're a third-party library developer,

00:10:49   I highly recommend creating a pod spec

00:10:50   file for your library.

00:10:55   It makes it really easy for other people to integrate with,

00:10:58   and it's really straightforward.

00:11:00   I mean, they make it really easy.

00:11:01   Another nice thing, too, you can also have private pods.

00:11:04   And I've done this myself for one of the little components

00:11:07   that I have internally.

00:11:11   So this is code that's not publicly available,

00:11:12   but it's in a private GitHub repository.

00:11:15   But you can just create a pod spec for it and link to it,

00:11:17   just like you would normally.

00:11:16   And so you can manage your own dependencies internally

00:11:19   this way, too, which is kind of nice.

00:11:22   So definitely worth checking out,

00:11:23   and I highly recommend it.

00:11:24   There'll be a link in the show notes to the CocoaPods project.

00:11:28   All right.

00:11:29   So that's sort of the main two topics I'm going to talk about.

00:11:31   And to kind of round out our 15 minutes,

00:11:33   I'm just going to sort of do a little speculation,

00:11:35   a little talking about the new iPhone, what I'm hoping for,

00:11:39   what sort of things I'm thinking about as it's coming out.

00:11:43   So there's a couple of things that I don't really care about.

00:11:48   I mean, whatever it is, I'm going to buy one.

00:11:49   That's sort of a given.

00:11:50   It doesn't matter what it is, what it costs.

00:11:52   This is what I do for a living.

00:11:54   So whatever Apple's new hotness is, I'm going to buy one.

00:11:56   I'm probably going to buy it unlocked this time,

00:11:58   just because I'm not--

00:12:00   I'm still on contract with AT&T, so I'll just

00:12:02   need to buy a new one.

00:12:04   Flat out, that's probably better in terms

00:12:06   of gradually releasing the shackles AT&T has on me.

00:12:11   Things that I'm a little nervous about is 16 by nine.

00:12:16   It's weird because if the screen is a 16 by nine resolution

00:12:21   and there's a couple of things you can do to hack

00:12:25   the simulator to make it look like 16 by nine

00:12:27   and see how your applications respond.

00:12:29   And my apps do pretty well.

00:12:31   Overall, it's fine.

00:12:33   And especially this app that I've been, my weather app,

00:12:35   I've been building from the beginning

00:12:37   to be 16 by nine flexible.

00:12:39   So in the vertical dimension, it's very flexible.

00:12:39   But the thing that I worry about is a lot of these apps, I think, look funny in 16 by

00:12:44   9.

00:12:45   And by that I mean you have so much space to put information on, and the information

00:12:52   is so tall, that you end up with this really strange kind of look to it.

00:12:57   Maybe it's just not what I'm used to, but it feels very stretched and odd in that way.

00:13:03   And so I'm sure we'll get used to it, whatever it is, but that kind of makes me nervous.

00:13:06   And as I've been looking at my layouts and my designs,

00:13:09   I don't like the aesthetic of 16 by 9 nearly as much

00:13:12   as I do the current dimensions we have on the iPhone.

00:13:15   But if that's where they're going,

00:13:16   that's where they're going, I'll just get used to it

00:13:19   and adapt accordingly.

00:13:21   Things that I really want in the new iPhone is more storage.

00:13:24   I'd love for the new ones to be rather than 16, 32, 64.

00:13:28   I would love for the base model to be 32,

00:13:31   just because I think that's really what I probably want,

00:13:34   is about a 32 gig.

00:13:35   be nice for it to be $100 less.

00:13:38   And otherwise, I don't really care.

00:13:40   I mean, there's so many things that Apple

00:13:41   could do this, this, and the other.

00:13:43   It's like, if it has LTE, that's great.

00:13:46   I hope that works.

00:13:48   I'm still on the needTNT unlimited plan

00:13:51   from back in the day.

00:13:52   So I have no idea if that would work with LTE.

00:13:54   And if it does, great.

00:13:55   I got a nice, fast connection.

00:13:57   This is where I am.

00:13:58   I have pretty good AT&T LTE coverage.

00:14:00   I know it varies based on where you are.

00:14:03   NFC doesn't really make any sense.

00:14:05   A slightly slimmer form factor, sure.

00:14:08   Better battery life, maybe.

00:14:10   If they could squeeze out more battery life, I'd love it.

00:14:13   But I'm not really holding my breath on that.

00:14:15   And otherwise, I just look forward to enjoying the ride.

00:14:17   I'm sure there will be some cool things on iOS 6

00:14:19   to take advantage of.

00:14:20   And it's an exciting time as a developer.

00:14:23   I know I'll sort of get out the popcorn,

00:14:25   enjoy watching the live blogs.

00:14:26   And I hope you do too.

00:14:28   All right, that's it for today's show.

00:14:30   As always, if you have questions, comments, concerns,

00:14:32   I'm on Twitter @_DavidSmith.

00:14:34   And otherwise, I hope you have a good announcement day.

00:14:36   Enjoy it, and I'll talk to you afterwards.

00:14:38   Bye.