• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Several questions on Objective C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Several questions on Objective C


  • Subject: Re: Several questions on Objective C
  • From: Thomas Lachand-Robert <email@hidden>
  • Date: Mon, 18 Mar 2002 23:03:30 +0100

Le lundi 18 mars 2002, ` 07:24 , Ivan Gsmez a icrit :


But it doesn't matter. My questions were only to learnt about how the language exactly is. I have found ObjectiveC is a pretty interesting and good language having its cool stuff (categories, being so dynamic...) but lacks of many interesting things (possibility of declaring var everywhere in code, protected methods, templates, operators and functions overload, declaring methods and classes as abstract,...)


May I give you my own experience on Obj-C? At first sight, two years ago, I got the same impression, even worse (I don't like the brackets, plus they are difficult to get on a french keyboard). I already had a large experience in pascal, C++, and some others, so I decided to use Java. Java looks great at first sight, it is very structured, etc.

What a mistake! Java is really a dead end. It is like walking in a town with a cop at every corner, telling you (gently but firmly): "don't go that way, for your own sake!". I wasted almost a year with Java, and it was one of my most deceiving experience in programmation.

C++ doesn't have that many restrictions, but still has a lot. And it has a large number of downsides, that you probably know if you already used it, and you don't wish to know otherwise.

As I first started using Obj-C, I was really afraid I could mess something by using protected methods or something similar. The truth is, it never happens. "Private" methods are buried in the .m files, so you can't access them. "Protected" methods are so rarely used, even in C++, that you can easily live without, particularly in Obj-C where you usually DON'T derive a lot of classes. Same thing about "const" (or "final" in Java); declaring "const" arguments implies a lot of averhead, time wasted most of the time.

Templates, operators, function overload, etc., can easily be used in Obj-C:
just use Obj-C++, which means naming your file with extension ".mm" instead of ".m" (complicated, eh?). This allows any C++ construct in addition to Obj-C.

I agree with you about the inability to declare var everywhere in code. But, first, this is not a problem in Obj-C++; most of the time I rename a file ".mm" just to do that. If you read the code examples given here on this list, or in some "classical" books on Obj-C, you will see that they are usually very well written EXCEPT for some "contortions" due to the fact that you must declare variables at the beginning of blocks. Anyway you have to know that it is not really a limitation of the Obj-C language,
but of the older specification of C. The more recent one, C99, removes it.
It is implemented in gcc 3.0 and after, but for the moment Apple still limits us to gcc 2.95... Let us hope this will change very soon.

Finally I would like to emphasize some very cool features of Obj-C that are rarely stressed (even on this list), but make life much easier when you use it:
1/ Less classes. In C++ or Java you derive A LOT of classes, in Obj-C you hardly ever do (I don't count derivation from NSObject, which is not a true derivation in some sense). That's not necessary, because you can add methods to existing classes, and there are some other features of the language that just make it not very useful. To summarize, C++ or Java idiom is: "first derive a new class, then think about it"; Obj-C is "First think about it; then don't derive a new class".
2/ In C++ (or Java) a new class needs a number of things to work: a constructor, because you don't inherit constructors (save the default one)
, a copy constructor (because otherwise C++ provides a default one,not appropriate usually), etc. In Obj-C any new class inherits everything, the "constructors" (= init methods), the "copy" (existing only if necessary, that is, usually not), etc. So, while designing a new class, you just add what you really need.
3/ Memory management is very easy in Obj-C, once you got the retain/release/autorelease trick (the smart part is really "autorelease"). It is not so simple as in java (but you know the garbage collector of Java has its own problems), but still very simple and efficient. Actually a lot of developers implements this in C++ (in a very painful way, because it is difficult for C++).
4/ Pointers. I used to think that pointers are evil. They are not. Since every Obj-C "object" is really a pointer to a simple C-struct, it is again much simpler than C++ where you have to care about copied object, automatic objects, etc. Here Java is very similar to Obj-C, except you cannot cast in Java.

Ok, enough about this. If you did not, give Obj-C a try; also try to use Obj-C constructs, not C++ or Java ones. You likely won't regret it.

Thomas Lachand-Robert
********************** email@hidden
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Sub or superscripts with IB buttons
  • Next by Date: Re: Newbie with stupid question
  • Previous by thread: Re: Sub or superscripts with IB buttons
  • Next by thread: Re: Several questions on Objective C
  • Index(es):
    • Date
    • Thread