Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
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-Programming-Language-2nd/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.
 

throAU

macrumors G3
Feb 13, 2012
8,772
6,935
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.
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
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
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
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
 

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
Good point @balamW

I suppose it might be worth learning Python or something completely different, to enhance my skills as a 'problem solver'
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,544
6,042
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.
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
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
 

ChristianVirtual

macrumors 601
May 10, 2010
4,122
282
日本
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.
 
Last edited:

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
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
 

Albright

macrumors regular
Aug 23, 2011
130
299
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.

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.
 

ctdonath

macrumors 68000
Mar 11, 2009
1,592
629
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.

----------

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-Programming-Language-2nd/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.
 

firewood

macrumors G3
Jul 29, 2003
8,106
1,343
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.
 

Albright

macrumors regular
Aug 23, 2011
130
299
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.
 

ctdonath

macrumors 68000
Mar 11, 2009
1,592
629
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.
 

Albright

macrumors regular
Aug 23, 2011
130
299
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?
 

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.