Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 13, 2013, 07:44 AM   #1
nashyo
macrumors 6502
 
Join Date: Oct 2010
Location: Bristol
C and Objective-C relationships

I started my App development career learning Objective-C, having no background in programming whatsoever. It has been 12 months since I started learning code and I am now curious about learning another language.

A friend mentioned that learning C would enhance my understand of Objective-C, so I got my hands on this book.

http://www.amazon.co.uk/C-Programmin.../dp/0131103628

I have progressed 33% of the way through this book to find that the similarities are so similar that I might as well not bother reading the rest of it.

It would be good to get a thread going on other developers thoughts on C, in the context of how it might benefit an Objective-C developer of iOS Apps.
__________________
Xcode 4.5.2, SDK 6.0, OSX Mountain Lion, ARC
nashyo is offline   0 Reply With Quote
Old Jan 13, 2013, 07:58 AM   #2
throAU
macrumors 68030
 
Join Date: Feb 2012
Location: Perth, Western Australia
Objective-C is an add on to C.

All the non-object oriented Obj-C code you write (including, likely much of the code in your methods) is plain C. It's not just similar - it IS C.


Plain C will be useful to you if you ever do any low level work with hardware, or write code for another platform, possibly where Objective-C does not exist.
__________________
MBP (early 2011) - Core i7 2720 2.2ghz, Hires Glossy, 16GB, Seagate Momentus XT 750GB
Mac Mini (mid 2007) - Core2 Duo 1.8, 2gb, 320gb 7200 rpm
iPhone 4S, iPad 4, iPad Mini, HTC One (eval)
throAU is offline   0 Reply With Quote
Old Jan 13, 2013, 08:01 AM   #3
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
K&R may not have been the best choice of books. Just my humble opinion.

You might have been better served by one of the phone book sized books that provides tons of example of more specific things.

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Jan 13, 2013, 08:02 AM   #4
nashyo
Thread Starter
macrumors 6502
 
Join Date: Oct 2010
Location: Bristol
Quote:
Originally Posted by balamw View Post
K&R may not have been the best choice of books. Just my humble opinion.

B
What would you have suggested as an alternative?
__________________
Xcode 4.5.2, SDK 6.0, OSX Mountain Lion, ARC
nashyo is offline   0 Reply With Quote
Old Jan 13, 2013, 08:09 AM   #5
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Quote:
Originally Posted by nashyo View Post
What would you have suggested as an alternative?
I edited my post. I can't think of a specific example right now with my pre-coffee brain, but K&R is a thin book where a lot of the actual work is left as an exercise to the user. Thus, if you already know some programming of any kind it doesn't really add anything to your arsenal beyond the language reference. You do it the way you already know it.

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Jan 13, 2013, 08:12 AM   #6
nashyo
Thread Starter
macrumors 6502
 
Join Date: Oct 2010
Location: Bristol
Good point @balamW

I suppose it might be worth learning Python or something completely different, to enhance my skills as a 'problem solver'
__________________
Xcode 4.5.2, SDK 6.0, OSX Mountain Lion, ARC
nashyo is offline   0 Reply With Quote
Old Jan 13, 2013, 08:18 AM   #7
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
I wouldn't forgo that entire book... I did the same thing as you, learning Obj-C before C, except I knew Obj-C was an extension of C and so I thought I knew all there was to know about C.

But it turns out that on account of learning Obj-C first, I didn't learn about some of the plain old C ways of doing things. For example:

A struct is basically a class full of instance variables and no methods. Do you know how to use them? NSRange and NSRect are examples of structs that Apple uses that you might have used before.

Do you know how to use a c-array? They look like this
Code:
int array[3];
array[0] = 2;
array[1] = 3;
array[2] = 10;
printf("%i", array[1]);
Can you use a function pointer?

Do you know how to allocate memory?

Can you use switch statements?

I would just look through this and read any chapters that you don't think you understand just so you can make sure you know all there is to know about C.

http://c.learncodethehardway.org/book/

Also note that ALL VALID C CODE IS ALSO VALID OBJ-C CODE.

If you know how to do something in C and Obj-C, and doing it the C way won't take significantly more time or lines to write, do it the C way. Your code will be more portable (more platforms understand C than Obj-C,) and chances are it'll execute faster.

Other languages you can learn:
C++
java

C++ is mostly just an extension of C, although occasionally the authors decided to take out features of C that they felt were insecure. Honestly, I don't like C++... I feel like the main new features that it has and other languages don't just lead to more confusing code. IE, they allow you to redefine operators in the language. So typing

Code:
"string1" + "string2"
Is valid. What does it result in? "string1string2"? Okay, fine, but what about

Code:
"string1" - "string2"
I don't think it's valid, but it could be depending on how the string class is written, and lord knows what they decided to make the minus operator do.

Java is inspired by C++ but they managed to weed out a lot of the stupid ideas from C++... unfortunately, they didn't get all of them, because a terrible concept introduced in C++, known as exceptions, still exists in Java (and I actually think Java's standard classes utilizes them more.) The basic concept of an exception is that, rather than have errors when you try to compile buggy code, or return error codes, it's much better to crash or slow down the application. The person who introduced the concept in C++ is on my time traveling hit list.
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed.
Including the ones paired with other Macs on your network.
ArtOfWarfare is offline   0 Reply With Quote
Old Jan 13, 2013, 08:22 AM   #8
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Quote:
Originally Posted by nashyo View Post
I suppose it might be worth learning Python or something completely different, to enhance my skills as a 'problem solver'
Everyone learns things differently.

I'd suggest a C-based book on a specific topic that is either related to what you are working on or in a completely different area. (games? databases? ...)

Learning new languages is great, but doesn't always translate to putting new arrows in the quiver.

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Jan 13, 2013, 08:26 AM   #9
ChristianJapan
macrumors Demi-God
 
ChristianJapan's Avatar
 
Join Date: May 2010
Location: 日本
How about SQL to be able to use databases ? Of course there are libs around but some solid SQL is good in many cases. Things like stored procedures, trigger ...

Maybe PHP for server-side stuff.
And JavaScript also can be handy to know, too.

If you can Objective-C the classical C is too close and concepts like ARC are great compared to nasty old malloc/free.
__________________
Member of MacRumors.com Folding@Home Team (#3446) & developer of the F@H Mobile Monitoring app

Last edited by ChristianJapan; Jan 13, 2013 at 08:34 AM. Reason: Remove some 'some'
ChristianJapan is offline   0 Reply With Quote
Old Jan 13, 2013, 08:31 AM   #10
nashyo
Thread Starter
macrumors 6502
 
Join Date: Oct 2010
Location: Bristol
Good point. I want to explore animations and user interface design from a coding perspective, so I think I will read in those areas.

@ArtOfWarfare from what you have said here I feel pretty confident that I know enough about C.

----------

Ye, I've just figured out how to set up APNS using SQL and PHP.

Will explore that in more detail.

----------

Easyapns.com was really helpful
nashyo is offline   0 Reply With Quote
Old Jan 13, 2013, 11:45 PM   #11
Albright
macrumors regular
 
Join Date: Aug 2011
Quote:
Originally Posted by ArtOfWarfare View Post
If you know how to do something in C and Obj-C, and doing it the C way won't take significantly more time or lines to write, do it the C way. Your code will be more portable (more platforms understand C than Obj-C,) and chances are it'll execute faster.
I disagree. Unless you're working on a separate subproject for which portability is a must, you might as well stick with Objective-C and the safety and other benefits it has to offer - all or nothing. For example, I can't recall where I saw it, but I recently saw an article from someone making the point that iOS developers who are using "int" instead of "NSInteger" are probably doing fine now, but might run into easily-avoidable bugs once Apple's ARM hardware goes 64-bit. Also, Objective-C has much more pleasant ways to sort and iterate over stuff than pure C. If your project is already using Objective-C, then why not just stick with it, own it, and milk it for all it's worth?

I'm also not totally convinced that C will be that much faster for most purposes than Objective-C once compiled, particularly since Apple has done so much work to make sure that Objective-C is a first-class player in Clang/LLVC.

That being said, this is a matter of personal choice, so don't take my word for it. Go with what works best for you.

Quote:
Java is inspired by C++ but they managed to weed out a lot of the stupid ideas from C++... unfortunately, they didn't get all of them, because a terrible concept introduced in C++, known as exceptions, still exists in Java…
Interesting to see such hate for exceptions. They of course exist in Obj-C as well… do they bother you there as well?

In my case, I learned C in college, then promptly forgot about it after changing from a CS to an English Lit major (one of the worst decisions in my life, but I'm slowly recovering). When I decided I wanted to earnestly pick up iOS dev, I had to relearn a lot of stuff, but in retrospect it wasn't as tough as I thought it would be - just practice enough, and it becomes second nature, just like with anything else. All that being said, if I have the choice, I'd still rather write in Objective-C than straight C, as much of a n00b as that might make me.
Albright is offline   0 Reply With Quote
Old Jan 14, 2013, 12:10 PM   #12
ctdonath
macrumors 65816
 
Join Date: Mar 2009
Quote:
Originally Posted by ArtOfWarfare View Post
what about

Code:
"string1" - "string2"
I don't think it's valid, but it could be depending on how the string class is written, and lord knows what they decided to make the minus operator do.
Thing is, the language designer doesn't know what shouldn't be allowed/facilitated. You might not see the sensibility of it, but it may be reasonable in a particular application; I can see some application defining operator-() such that "string1"-"string" returns "1", and "string1"-"string2" returns "string1" (to wit, remove every instance of rvalue from lvalue).

Sure, it makes it easier to do stupid/confusing things, but balanced by making it much easier to do smart/sensible things. Powerful tools are dangerous when wielded by the confused. If a language is going to allow unrestricted manipulation of pointers, then risk of redefining the subtraction operator is minor.

----------

Quote:
Originally Posted by nashyo View Post
A friend mentioned that learning C would enhance my understand of Objective-C, so I got my hands on this book.

http://www.amazon.co.uk/C-Programmin.../dp/0131103628

I have progressed 33% of the way through this book to find that the similarities are so similar that I might as well not bother reading the rest of it.
The real value in reading "K&R C" is historical: that is the book that introduced and defined C to the world. As a competent programmer it will tell you little you don't already know, but as a student of the totality of programming it will help understand why things are what they are because that book is where that major branch of the discipline started. It's a bit like learning Latin: not so much for daily use, as comprehension of origins of dialects.
ctdonath is offline   1 Reply With Quote
Old Jan 14, 2013, 01:48 PM   #13
firewood
macrumors 603
 
Join Date: Jul 2003
Location: Silicon Valley
A good programmer usually knows more than one programming language, and learning the C language core of the Objective C superset can give a coder far greater understanding into how their device's processor actually runs stuff, how to debug their apps in more detail, and the possibility of some options for improving the performance of their code.

K&R is a great historical document. It doesn't include some of the newer C99 (and later) constructs used in modern coding, but can give you great insight into the core of the C language that everything else (including Objective C) was built on top of.
firewood is offline   0 Reply With Quote
Old Jan 16, 2013, 01:35 AM   #14
Albright
macrumors regular
 
Join Date: Aug 2011
Quote:
Originally Posted by ctdonath View Post
Thing is, the language designer doesn't know what shouldn't be allowed/facilitated. You might not see the sensibility of it, but it may be reasonable in a particular application; I can see some application defining operator-() such that "string1"-"string" returns "1", and "string1"-"string2" returns "string1" (to wit, remove every instance of rvalue from lvalue).
Or you could create a function named something like remove_string_from_string() and not confuse the next developer who looks at that code (who might be you, in a few months after you've forgotten that you've overloaded the hyphen operator in that project).

Just because you can do things like overload the basic arithmetic operators doesn't mean you should, even in the languages that allow you to do so.
Albright is offline   0 Reply With Quote
Old Jan 16, 2013, 08:51 AM   #15
ctdonath
macrumors 65816
 
Join Date: Mar 2009
Quote:
Originally Posted by Albright View Post
Just because you can do things like overload the basic arithmetic operators doesn't mean you should, even in the languages that allow you to do so.
That's not the issue. I'm not saying you should; I was trying to (on short notice) suggest a case where it might be sensible, as just because we can't think of a good reason now doesn't mean one doesn't exist.

The issue is whether the language should let you. Some people seem to think that, just because they can't think of a good use, the option shouldn't be available to anyone.
ctdonath is offline   0 Reply With Quote
Old Jan 20, 2013, 04:32 AM   #16
Albright
macrumors regular
 
Join Date: Aug 2011
Coincidentally, an iBooks book was recently released on this topic: All the C You Need to Know (the "you," implicitly, being an Objective-C developer), by Bill Dudney. The price looks a bit high relative to its length, though it does take advantage of the iBooks platform with some interactivity tricks and such. Has anyone given this a look yet and can give a quick review?
Albright is offline   0 Reply With Quote
Old Jan 21, 2013, 05:48 AM   #17
nashyo
Thread Starter
macrumors 6502
 
Join Date: Oct 2010
Location: Bristol
Quote:
Originally Posted by Albright View Post
Coincidentally, an iBooks book was recently released on this topic: All the C You Need to Know (the "you," implicitly, being an Objective-C developer), by Bill Dudney. The price looks a bit high relative to its length, though it does take advantage of the iBooks platform with some interactivity tricks and such. Has anyone given this a look yet and can give a quick review?
looks pretty good. might get it
__________________
Xcode 4.5.2, SDK 6.0, OSX Mountain Lion, ARC
nashyo is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Tags
learning, objective-c

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
What do you think about long-distance relationships? sunnysweet Community Discussion 71 Jan 10, 2014 07:10 AM
Managing relationships by fetching related objects within subclass of NSManagedObject Monaj iPhone/iPad Programming 0 Feb 8, 2013 12:38 AM
How have your political views affected your relationships with others this year? glocke12 Politics, Religion, Social Issues 144 Oct 17, 2012 06:55 PM
So how progressive are you? Relationships niuniu Politics, Religion, Social Issues 65 Aug 13, 2012 08:20 PM

Forum Jump

All times are GMT -5. The time now is 03:31 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC