• 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: A question about static typing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A question about static typing


  • Subject: Re: A question about static typing
  • From: "R. Tony Goold" <email@hidden>
  • Date: Sat, 21 Jul 2001 12:34:34 -0400

I've been working my way through "Learning Cocoa" and I can't figure out why the authors static type some places and not others.

Static typing is useful for catching some errors at compile time which would be missed by simply using the id type, such as unsupported methods. There are other times when static typing is impossible because you don't know what type to expect. I would ask the question "why didn't they use static typing here?"

It's probably also worth pointing out that books and magazines on programming often sacrifice style for brevity. Object oriented practices help to manage complexity, but there isn't much complexity in a 10-20 line code snippet so "good practices" are only a minor consideration. Unless we'
re talking about a book on software design!

They particularly like to static type outlets but I can't understand why outlets are especially error prone. It seems that static typing is less likely to help here than in the general case since one is more likely to,
for example, send a button message to the wrong button than to send a textField message to a button.

As a very simple case, consider typos:

id button1;
NSButton* button2;
[button1 titel]; // Mistake not caught until execution
[button2 titel]; // Mistake caught during compilation

There are similar mistakes related to casting which can also be caught during compilation by using static typing. I tend to think of the "id" type as a "void*", something best used when there is no other choice. Neither permit much in the way of compile time error checking.

Mind you, I learned Objective C only recently, after I'd been programming in C++ for a while, so this may be more of a C++ oriented philosophy. If I'
ve missed something, maybe one of the ObjC gurus can set me straight here.

Cheers,
Tony


References: 
 >A question about static typing (From: Chris Gehlker <email@hidden>)

  • Prev by Date: Re: [NSImage lockFocus] and threads
  • Next by Date: Re: [NSImage lockFocus] and threads
  • Previous by thread: A question about static typing
  • Next by thread: Re: A question about static typing
  • Index(es):
    • Date
    • Thread