IT story

Objective-C를 배우기 전에 먼저 C를 배우십시오.

hot-time 2020. 8. 9. 09:42
반응형

Objective-C를 배우기 전에 먼저 C를 배우십시오.


야심 찬 Apple 개발자이기 때문에 Objective-C로 이동하기 전에 먼저 C를 배우고 궁극적으로 Cocoa Framework를 배우는 것이 더 낫다면 커뮤니티의 의견을 듣고 싶습니다.

내 직감은 나에게 좋은 기초를 제공 할 C를 배우라고 말한다.


나는 먼저 C를 배울 것입니다. Obj-C로 이동하기 전에 C를 배웠습니다 (C에서 많은 일을했습니다). 저는 진짜 C 프로그래머가 아니었던 많은 동료들이 있습니다. 그들은 Obj-C로 시작하여 필요한만큼의 C 만 배웠습니다.

때때로 나는 그들이 Obj-C에서 문제를 완전히 해결하는 방법을 봅니다. 때로는 매우 서투른 해결책을 가져옵니다. 일반적으로 일부 Obj-C 코드를 순수한 C 코드로 대체합니다 (원하는만큼 혼합 할 수 있으며 Obj-C 메서드의 내용은 완전히 순수한 C 코드가 될 수 있습니다). Obj-C 프로그래머를 모욕 할 의도가없이 Obj-C에는 매우 우아한 솔루션이 있습니다. 이들은 객체 덕분에 훨씬 더 잘 작동하고 보이는 솔루션입니다.(OOP 프로그래밍은 복잡한 프로그램을 함수형 프로그래밍보다 훨씬 더 사랑스럽게 만들 수 있습니다. 예를 들어 다형성은 훌륭한 기능입니다) ... 그리고 저는 Obj-C를 정말 좋아합니다 (C ++보다 훨씬 더! C ++ 구문이 싫고 일부 언어 기능은 너무 과도합니다. 나쁜 개발 패턴 IMHO로 이어집니다. 그러나 때때로 동료의 Obj-C 코드를 다시 작성할 때 (그리고 이것이 절대적으로 필요하다고 생각하는 경우에만 그렇게합니다) 결과 코드는 일반적으로 50 % 더 작아지고 사용 된 메모리의 25 % 만 필요합니다. 런타임에 약 400 % 더 빠릅니다.

내가 여기서 말하려는 것 : 모든 언어에는 장단점이 있습니다. C에는 장단점이 있으며 Obj-C도 마찬가지입니다. 그러나 Obj-C의 정말 큰 기능은 (그래서 Java보다 더 좋아하는 이유입니다) 마음대로 평범한 C로 건너 뛸 수 있다는 것입니다. 이것이 왜 그렇게 훌륭한 기능입니까? Obj-C가 순수 C의 많은 단점을 수정하는 것처럼 순수 C는 Obj-C의 단점 중 일부를 수정할 수 있습니다. 그것들을 함께 섞으면 매우 강력한 팀을 얻게 될 것입니다.

Obj-C 만 배우고 C에 대해 전혀 모르거나 기본 사항 만 알고 있으며 일반적인 문제를 얼마나 우아하게 해결할 수 있는지 시도하지 않았다면 실제로 Obj-C의 절반 만 배웠습니다. C는 Obj-C의 기본 부분입니다. 언제 어디서나 C를 사용할 수있는 능력은 C의 기본 기능입니다.

일반적인 예는 base64로 데이터를 인코딩해야하는 일부 코드 였지만이를 위해 외부 라이브러리를 사용할 수 없었습니다 (OpenSSL lib 없음). 우리는 완전히 Cocoa 클래스를 사용하여 작성된 base64 인코더를 사용했습니다. 정상적으로 작동했지만 200MB의 이진 데이터를 인코딩 할 때 영원이 걸렸고 메모리 오버 헤드는 용납 할 수 없었습니다. 나는 그것을 하나의 C 함수로 완전히 작성된 작은 초소형 base64 인코더로 대체했습니다 (함수 본문을 메서드 본문에 복사하고 메서드는 NSData를 입력으로 사용하고 NSString을 출력으로 반환했지만 함수 내부에는 모든 것이 C였습니다). C 인코더는 훨씬 더 콤팩트하여 순수한 Cocoa 인코더보다 속도가 8 배나 높았으며 메모리 오버 헤드도 훨씬 적었습니다. 데이터 인코딩 / 디코딩, 비트 및 유사한 저수준 작업은 C의 강점 일뿐입니다.

또 다른 예는 많은 그래프를 그린 UI 코드입니다. 그래프를 그리는 데 필요한 데이터를 저장하기 위해 NSArray를 사용했습니다. 그래프가 애니메이션 되었기 때문에 실제로 NSMutableArray입니다. 결과 : 그래프 애니메이션이 매우 느립니다. 우리는 모든 NSArray를 일반 C 배열, 구조체가있는 객체 (모든 그래프 좌표 정보가 객체에 있어야 할 필요가없는 경우), 간단한 for 루프를 사용한 열거 자 액세스로 교체하고 하나의 배열에서 데이터를 가져 오는 대신 memcopy를 사용하여 배열간에 데이터를 이동하기 시작했습니다. 다른 하나는 색인을위한 색인입니다. 그 결과 4 배로 속도가 빨라졌습니다. 이전 PPC 시스템에서도 그래프가 부드럽게 움직였습니다.

C의 약점은 모든 복잡한 프로그램이 장기적으로 추악해진다는 것입니다. C 애플리케이션을 읽기 가능하고 확장 가능하며 관리 가능하게 유지하려면 프로그래머의 많은 규율이 필요합니다. 이 분야가 누락되어 많은 프로젝트가 실패합니다. Obj-C를 사용하면 클래스, 상속, 프로토콜 등을 사용하여 애플리케이션을 쉽게 구성 할 수 있습니다. 즉, 필요한 경우가 아니면 메서드의 경계를 넘어 순수한 C 기능을 사용하지 않을 것입니다. 객체의 메서드 내에서 Objective-C 앱의 모든 코드를 유지하는 것을 선호합니다. 다른 모든 것은 OO 응용 프로그램의 목적에 위배됩니다. 그러나 방법 내에서 나는 때때로 순수한 C를 독점적으로 사용합니다.


C와 Objective-C를 동시에 충분히 배울 수 있습니다. Objective-C를 언어에 추가하기 전에 C의 세부 사항 (포인터 산술 등 포함)을 배울 필요가 없습니다. Objective-C를 빠르게 진행하면 "객체에 대한 생각"을 더 빨리 시작할 수 있습니다.

사용 가능한 리소스 측면에서 Apple의 문서는 일반적으로 C에 익숙하다고 가정하므로 Objective-C 2.0 프로그래밍 언어로 시작하는 것은 큰 도움이되지 않습니다. 저는 Stephen Kochan의 Programming in Objective-C 사본에 투자 할 것입니다 (진행 속도에 따라 두 번째 버전을 기다리는 것을 고려할 수 있습니다).

프로그래밍 Objective-C 개발자 라이브러리 프로그래밍 Objective-C 2.0 개발자 라이브러리

사전 경험이 없다고 가정하고 Objective-C와 필요한만큼 C를 가르칩니다.

약간의 야심이 느껴진다면 Scott Stevenson의 "Learn C"자습서로 시작할 수 있지만 몇 가지 전제 조건이 있습니다 ( "함수, 변수 및 루프를 포함하여 적어도 하나의 스크립팅 또는 프로그래밍 언어를 이미 알고 있어야합니다. Mac OS X 터미널에 명령을 입력해야합니다. ").

(기록과 맥락을 위해서만 : 1991 년에 동시에 두 가지를 배웠습니다. 그것은 나에게 아무런 해를 끼치 지 않는 것 같았습니다.하지만 저는 BASIC, Pascal, Logo 및 LISP에 대한 배경 지식가지고 있었습니다. )


Objective-C에 대한 책을 쓰기 전에이 문제에 대해 많이 생각했습니다. 첫째, 저는 Objective-C를 배우기 전에 C 언어를 배우는 것이 잘못된 길이라고 정말로 믿습니다. C는 절차 적특히 초보자 수준에서 Objective-C 프로그래밍에 필요하지 않은 많은 기능을 포함하는 언어. 사실, 이러한 기능 중 일부에 의존하는 것은 좋은 객체 지향 프로그래밍 방법을 고수하는 수준에 위배됩니다. 객체 지향 언어를 배우기 전에 절차 적 언어의 모든 세부 사항을 가르치는 것도 좋은 생각이 아닙니다 (그리고 함수와 구조화 된 프로그래밍 기술로 문제의 해결책을 공격하는 것). 이것은 프로그래머를 잘못된 방향으로 시작하여 좋은 객체 지향 프로그래밍 원칙을 육성하기 위해 잘못된 방향과 사고 방식을 개발할 수 있습니다. Objective-C가 C 언어의 확장이라고해서 먼저 C를 배워야하는 것은 아닙니다!

Objective-C와 기본 C 언어를 단일 통합 언어로 가르치는 것이 올바른 접근 방식이라고 생각합니다. "for"문이 상위 집합 Objective-C 언어가 아니라 C 언어에서 온다는 것을 배울 이유가 없습니다. 또한, 전에 C 배열 및 문자열과 같은 것에 대해 자세히 배우는 이유는 무엇입니까?예를 들어 배열 (NSArray) 및 문자열 객체 (NSString)에 대해 배우고 있습니까? 많은 C 텍스트는 구조에 많은 시간을 할애하고 구조에 대한 포인터는 포인터로 배열을 반복합니다. 그러나 이러한 C 언어 기능에 대해 알지 못해도 Objective-C 프로그램 작성을 시작할 수 있습니다. 초보 프로그래머에게는 큰 일입니다. 이는 학습 곡선을 단축 할뿐만 아니라 Objective-C 프로그램을 작성하기 위해 학습해야하는 자료의 양 (및 일부는 선택적으로 필터링 됨)을 줄여줍니다.

나는 당신이 기본 C 기능을 전부는 아니더라도 대부분 배우기를 원할 것이라는 데 동의하지만, 클래스와 메서드를 정의하고, 객체와 메시지 표현으로 작업하고, 상속의 개념을 이해할 때까지 많은 것을 연기 할 수 있습니다. 다형성은 잘 알려져 있습니다.


I'd dive right in with Objective C - if you've already got a few languages under your belt, it's not the syntax which is the learning curve, it's Cocoa.


I think that, for the most part, learning C is a good idea no matter what arena you're going in to, at least to get the hang of the inner workings of software development before using prepackaged goods, that way if something goes wrong you have a better chance of understanding the inner workings. There's plenty of discussion about this on SO, and it's a rather subjective question, but in general you will inherently be using C within your Objective-C code, so I guess it's really up to you. I'm a ground up kind of person, but sometimes it can get in the way and I know several smart people who worked their way from the top down, I think the important part is that you get to understanding the inner workings as it will set your capabilities apart from those who don't as well as increase your capabilities.


It's a good idea to learn C before learning Objective-C, which is a strict superset of C. This means that Objective-C can support all normal C code, so the code common to C programs is bound to show up even in Objective-C code.

In addition to looking at things purely from a language point of view, you will find that Mac OS X is a complete Unix operating system. All the system level libraries are written in C.

It is probably possible to learn both at the same time, but I think you will appreciate and understand Objective-C more if you have a solid working knowledge of C first.


I'd learn Objective-C and learn as much C as you need as you go along.

The areas of C that you won't depend on much:

  • Pointer arithmetic and arrays. I haven't used C arrays at all.
  • C strings. Objective-C's strings do the job nicer and safer.
  • Manual memory management if you use GC in Obj-C 2.1. I highly recommend this route for development speed and performance reasons.

As you learn Objective-C and Cocoa, you cannot avoid learning bits of C. For example, rectangles are common represented by CGRect, a C struct.

If you have time, by all means learn C. As others have said here, Kochan's book (second and first editions) is excellent as a book to dip into.


There are a lot of things you can't do purely in Objective-C, so learning some basic C skills will be pretty critical. You'll at least need to understand variable declarations and the basic C library functions, or you'll be frustrated.


Honestly, so many languages are based on the C syntax that it's a good thing to be familiar with. I'd take a week or two to familiarize yourself with C regardless.

That said, I did just teach myself Objective C, and I have to be honest: I didn't find my C experience to be as useful as I would have thought. Objective C was definitely eye-opening for me.


You can jump directly into Objective-C, with the following benefits:

  1. You'll learn "some" C in the way.
  2. You'll learn the C parts that are relevant for you .

At least for me is easier to learn a new language when I'm interested in some specific app or sample, and I fail when I have to learn other thing that is not exactly what I'm interested on.

You can always refine your C knowledge later if you get interested in lower level programming.


Better, I don't know, even less as I am not familiar with Objective-C.
But bases of C aren't so hard to learn, it isn't a very complex language (in terms of syntax, not in terms of mastering!), so go for it, it won't be wasted time.
Personally, I think it is always a good idea to learn C, it gives a good insight of how computer works. After all, most languages and systems are still written in C. Then move on! :-)

PS.: By "move on", I didn't mean "drop it", just "learn more, learn different". Once you know C, you might never drop it: Java uses JNI to call C routines for low level stuff, Python, Lua, etc. are often extended with C code (Lua reference even just assumes some C knowledge for some functions which are just a thin wrapper to the C function behind), and so on.


Yes, learning C language before any other advanced langauges will help you to learn quiclky other langauges.


According to Wikipedia, Objective-C is a strict super-set of C. This being the case, I would suggest learning C first. Then when you learn Objective-C it will be clear what parts are added as part of Objective-C.


C gives you very little abstraction from assembly. Some C Compilers will even let you inline assembly. This can be very useful for thinking about how the computer works, which is important to know.

That being said, if you're really interested in Object-C don't let yourself get stuck writing something in C just because its "good for you". You don't need to frustrate yourself while you're trying to learn a new skill set. It is important that you have fun with what you're doing.


Do you want to be a hard-core developer? Then learn c first.

The books you need to completely master c are some of the best writings in technology. Here's what you need:

C Programming Language

The Standard C Library


Objective C is sufficiently different from C as to not merit learning C first.

From a syntax / language-family perspective one is almost better off studying SmallTalk (on which objective C is based)

From a practical perspective, focus your efforts on learning one language at a time.

Later, if you wish to learn another language, C++, Java and Python are 1) easy to learn as a bunch 2) popular and thus marketable 3) powerful.


You should have a basic knowledge of C before starting Objective_C, but there's no need master every detail of C.

I've published my notes after reading "Programming in Objective-C" in case it helps someone else.

learn objective c with programming-


Depending on many languages you already know it may be a better idea to just start learning Objective-C. The foundation in most languages are basically the same, it's the syntax that is different. Learning C first isn't really going to make much of a difference when it comes to learning Objective-C.


I learned Objective-C straight away and it worked fine for about a year now, I just had some difficulty reading C code when I downloaded project to see how they work, but now I really feel the need to learn C. You can try learning ObjC without C, but sooner or later, you will need C.


IMHO one should first learn at least some C and especially about pointers. That’s even more important if one comes from a language that doesn’t have pointers. A lot of people ask about code like

NSString *string = [[NSString alloc] init];
string = @"something";

since they don’t know about the distinction between a pointer and the object it points to.

Of course one doesn’t have to learn all of C before one can start with Objective-C, but some fundamental things are absolutely necessary.


Heck no, go straight to objective C!

I moved from ActionScript 3 to Objective C, and I already have an intern at a company!

Do what you want.


If you learn some other language prior, then you will always have confusion in writing right syntax. I do not know purpose, but Object C uses weird (not common) syntax for calling object methods. It names it as sending messages, yes, it is true accordingly pure Object Oriented concept, however most Object oriented languages name that as calling method and use more traditional syntax of calling methods. Garbage collection is also something very odd, Object C is based on old school reference count. So you will have difficulties to accept it if you switch from other language. I am writing a book Object C quick migration guide for C/C++ programmers hoping to help people to pickup all differences quicker.

참고URL : https://stackoverflow.com/questions/180549/learn-c-first-before-learning-objective-c

반응형