Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3722226
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:49:38+00:00 2026-05-19T05:49:38+00:00

What is better and why ? What is better in such situations as the

  • 0

What is better and why ?

What is better in such situations as the class init method and usual variables in a code ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T05:49:40+00:00Added an answer on May 19, 2026 at 5:49 am

    What is better and why ?

    Explicit typing information is always better unless you just can’t use it for some reason (see below).

    It allows the compiler to much more stringently validate the code and will catch many errors at compile time that would otherwise cause your app to crash at runtime.

    A long, long, time ago, everything in the APIs used id. This proved to be a complete pain in the butt; fragile and led to many crashes that would have been caught with specific types.

    So, it was changed. (This was ~1994).

    What is better in such situations as
    the class init method and usual
    variables in a code ?

    For init, you have no choice but to use the generic (id) return type. Objective-C does not support either co-variant or contra-variant declarations, nor is there a mechanism for generalizing the declaration of init while also providing support for specific type checking.

    Same goes for retain, objectAtIndex:, addObject: and many other methods that take or return one of many kinds of objects (or take ’em as arguments).

    And, no, there is absolutely no performance difference whatsoever between id and, say, NSView*.

    can you give an example when explicit
    typing will cause a problem please?

    If you wrote:

    - (MyClass *) init;
    

    And in a subclass:

    - (MySubclass *) init;
    

    You’d get compiler warnings out the wazoo most likely or you’d have to typecast out the wazoo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are situations where I declare member variables at the top of my class
I have a method that invokes other method in the same class such as:
Is there any better way to get take a string such as (123) 455-2344
I've seen some examples, but trying to better understand how Resource files work, such
Is there a better way to code this? def __contains__(self, e): return e in
Maybe even better is: Why does the standard require forwarding to a base class
In situations such as the one in the java snippet below, is it faster
Please pardon me for a n00bish question. Please consider the following code: public class
Better way to do it (without QImage )?: QImage image(width, height, QImage::Format_RGB888); memcpy(image.bits(), m_frameRGB->data[0],
Better to give an example, to illustrate what i am describing. The div element

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.