首先学习Objective-C之前学习C [英] Learn C first before learning Objective-C

查看:135
本文介绍了首先学习Objective-C之前学习C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个有抱负的Apple开发人员,我希望得到社会各界的意见,如果它是最好先移动到Objective-C和最终Cocoa框架?

Being an aspiring Apple developer, I want to get the opinions of the community if it is better to learn C first before moving into Objective-C and ultimately the Cocoa Framework?

我的直觉说学习C,这会给我一个很好的基础。

My gut says learn C, which will give me a good foundation.

推荐答案

我先学C。我学会了C(,做一个在C很多)移动到obj-C之前。我有很多同事从来没有谁是真正的C ++程序员,他们开始用的OBJ-C和博学多才尽可能多的C作为必要的。

I would learn C first. I learned C (and did a lot in C) before moving to Obj-C. I have many colleagues who never were real C programmers, they started with Obj-C and learned only as much C as necessary.

时不时地,我看到他们的OBJ-C完全解决问题,有时会造成一个非常笨拙的解决方案。通常我再更换一些的OBJ-C code的纯C code(毕竟你可以尽可能多的,只要你喜欢混合使用它们,一个OBJ-C方法的内容可以是全部,纯C code )。没有任何意图侮辱任何对象 - 程序员,也有解决方案,非常优雅的OBJ - C的,这些都是刚工作(看看)到的对象的(OOP编程好了很多,感谢解决方案使复杂的程序要比函数式编程更加可爱;多态性例如是一个辉煌的功能)...我真的很喜欢的OBJ-C(比C更++我讨厌C ++的语法和一些语言特性是纯矫枉过正而导致不好的!发展模式恕我直言);然而,当我有时会重新写对象 - 我的同事(我真的只能这样做,如果我认为这是绝对必要的)的code,产生的code一般为小50%,只有25需要之前所使用的和所述存储器的%是在运行时快约400%。

Every now and then I see how they solve a problem entirely in Obj-C, sometimes resulting in a very clumsy solutions. Usually I then replace some Obj-C code with pure C code (after all you can mix them as much as you like, the content of an Obj-C method can be entirely, pure C code). Without any intention to insult any Obj-C programmer, there are solutions that are very elegant in Obj-C, these are solutions that just work (and look) a lot better thanks to objects (OOP programming can make complex programs much more lovely than functional programming; polymorphism for example is a brilliant feature)... and I really like Obj-C (much more than C++! I hate the C++ syntax and some language features are plain overkill and lead to bad development patterns IMHO); however, when I sometimes re-write Obj-C code of my colleagues (and I really only do so, if I think this is absolutely necessary), the resulting code is usually 50% smaller, needs only 25% of the memory it used before and is about 400% faster at runtime.

我想在这里说:每一种语言都有其优点和缺点。 C有利弊,所以做的OBJ-C。然而,OBJ-C的真正伟大的功能(这就是为什么我甚至喜欢它比Java更)是可以随意并再次跳到纯C。为什么这是这样一个伟大的功能?因为就像对象 - 修复了很多纯C的利弊,纯C能解决一些对象 - 的利弊。如果混合在一起他们你会收到一个非常强大的团队。

What I'm trying to say here: Every language has its pros and cons. C has pros and cons and so does Obj-C. However, the really great feature of Obj-C (that's why I even like it more than Java) is that you can jump to plain C at will and back again. Why this is such a great feature? Because just like Obj-C fixes many of the cons of pure C, pure C can fix some of the cons of Obj-C. If you mix them together you'll receive a very powerful team.

如果你只学习对象 - 并没有C的想法或只知道它的非常基本知识,并从来没有尝试过如何能够完美地解决一些常见的问题,你实际上只学的OBJ-C的一半。 C是对象 - 的基本组成部分。用C随时随处的能力是它的一个基本特征。

If you only learn Obj-C and have no idea of C or only know the very basics of it and never tried how elegantly it can solve some common problems, you actually learned only half of Obj-C. C is a fundamental part of Obj-C. The ability to use C at any time and everywhere is a fundamental feature of it.

一个典型的例子是,我们使用了一些code,它必须连接以base64 code的数据,但我们不能使用一个外部库(没有OpenSSL的LIB)。我们使用使用Cocoa类一个base64连接codeR,完全写。这是工作好了,但是当我们把它带code 200 MB的二进制数据,花了一个永恒和内存的开销是不可接受的。我用一个微小的,超小型的base64连接完全写为一个C函数codeR替换了它(我复制函数体进入方法体,方法花费的NSData作为输入,并返回的NSString作为输出,但是里面的功能一切为:C )。的C EN codeR这么更加紧凑,它的8倍,在速度上击败了纯可可恩codeR和内存开销也少得多。编码/解码数据,与位和相似的低级别的任务,玩弄只是C的长处。

A typical example was some code we used that had to encode data in base64, but we could not use an external library for that (no OpenSSL lib). We used a base64 encoder, entirely written using Cocoa classes. It was working okay, but when we made it encode 200 MB of binary data, it took an eternity and the memory overhead was unacceptable. I replaced it with a tiny, ultra compact base64 encoder written entirely as one C function (I copied the function body into the method body, method took NSData as input and returned NSString as output, however inside the function everything was C). The C encoder was so much more compact, it beat the pure Cocoa encoder by the factor 8 in speed and the memory overhead was also much less. Encoding/Decoding data, playing around with bits and similar low level tasks are just the strong points of C.

另一个例子是一些UI code,吸引了很多图形。为了存储需要绘制图表中的数据,我们使用NSArray的。其实NSMutableArray里的,因为图中的动画。结果:很慢的图形动画。我们全部换成NSArray的正常C数组,具有结构对象(所有图后的坐标信息,什么是你必须有对象),用简单的for循环枚举器访问,并开始与存储器复制移动阵列之间的数据,而不是从一个阵列服用数据另外一个,指数为指数。结果:经4倍。平滑的动态,即使在较旧的PPC系统图表上的曲线加速

Another example was some UI code that drew a lot of graphs. For storing the data necessary to paint the graphs, we used NSArray's. Actually NSMutableArray's, since the graph was animated. Result: Very slow graph animation. We replaced all NSArray's with normal C arrays, objects with structs (after all graph coordinate information is nothing you must have in objects), enumerator access with simple for loops and started moving data between the arrays with memcopy instead of taking data from one array to the other one, index for index. The result: A speed up by the factor 4. The graph animated smoothly, even on older PPC systems.

C的弱点是,每一个更为复杂的程序得到从长远看难看。保持C应用程序的可读性,可扩展性和可管理性的要求很多程序员的纪律。许多项目失败,因为这门学科丢失。 OBJ-C很容易让你使用类,继承,协议等构建应用程序。这么说,我也不会跨越除非必要的方法的边框采用纯C功能。我preFER让所有code中的对象的方式中的一个Objective-C的应用;一切违背一个面向对象的应用程序的目的。但是在方法中我有时用纯C独占。

The weakness of C is that every more complex program gets ugly in the long run. Keeping C applications readable, extensible and manageable demands a lot of discipline of a programmer. Many projects fail because this discipline is missing. Obj-C makes it easy for you to structure your application using classes, inheritance, protocols and so on. That said, I would not use pure C functionality across the borders of a method unless necessary. I prefer to keep all code in an Objective-C app within the method of an object; everything else defeats the purpose of an OO application. However within the method I sometimes use pure C exclusively.

这篇关于首先学习Objective-C之前学习C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆