research assignment cs53144
play

RESEARCH ASSIGNMENT CS53144 GROUP OF 2 PARTICIPANTS SHEIKH SHDAB - PDF document

RESEARCH ASSIGNMENT CS53144 GROUP OF 2 PARTICIPANTS SHEIKH SHDAB NAWAZ PID-904567787 GURJEET SINGH PID-904567766 MIT INDIA PROGRAM 2005 1. Introduction Object-oriented programming, like most interesting new


  1. RESEARCH ASSIGNMENT CS53144 GROUP OF 2 PARTICIPANTS SHEIKH SHDAB NAWAZ PID-904567787 GURJEET SINGH PID-904567766 MIT INDIA PROGRAM 2005

  2. 1. Introduction Object-oriented programming, like most interesting new developments, builds on some old ideas, extends them, and puts them together in novel ways. The result is many-faceted and a clear step forward for the art of programming. An object-oriented approach makes programs more intuitive to design, faster to develop, more amenable to modifications, and easier to understand. It leads not only to new ways of constructing programs, but also to new ways of conceiving the programming task. Nevertheless, object-oriented programming presents some formidable obstacles to those who would like to understand what it's all about or begin trying it out. It introduces a new way of doing things that may seem strange at first, and it comes with an extensive terminology that can take some getting used to. The terminology will help in the end, but it's not always easy to learn. Moreover, there are as yet few full-fledged object-oriented development environments available to try out. It can be difficult to get started. 2. Why Objective-C The Objective-C language was chosen for the OPENSTEP development environment for a variety of reasons. First and foremost, it's an object-oriented language. The kind of functionality that's packaged in the OPENSTEP software frameworks can only be delivered through object-oriented techniques. This manual will explain how the frameworks work and why this is the case. Second, because Objective-C is an extension of standard ANSI C, existing C programs can be adapted to use the software frameworks without losing any of the work that went into their original development. Since Objective-C incorporates C, you get all the benefits of C when working within Objective-C. You can choose when to do something in an object-oriented way (define a new class, for example) and when to stick to procedural programming techniques (define a structure and some functions instead of a class). Moreover, Objective-C is a simple language. Its syntax is small, unambiguous, and easy to learn. Object-oriented programming, with its self-conscious terminology and emphasis on abstract design, often presents a steep learning curve to new recruits. A well-organized

  3. language like Objective-C can make becoming a proficient object-oriented programmer that much less difficult. The size of this manual is a testament to the simplicity of Objective-C. It's not a big book--and Objective-C is fully documented in just two of its chapters. Objective-C is the most dynamic of the object-oriented languages based on C. The compiler throws very little away, so a great deal of information is preserved for use at run time. Decisions that otherwise might be made at compile time can be postponed until the program is running. This gives Objective-C programs unusual flexibility and power. For example, Objective-C's dynamism yields two big benefits that are hard to get with other nominally object-oriented languages: Objective-C supports an open style of dynamic binding, a style than can accommodate a simple architecture for interactive user interfaces. Messages are not necessarily constrained by either the class of the receiver or the method selector, so a software framework can allow for user choices at run time and permit developers freedom of expression in their design. (Terminology like ``dynamic binding,'' ``message,'' ``class,'' ``receiver,'' and ``selector'' will be explained in due course in this manual.) Objective-C's dynamism enables the construction of sophisticated development tools. An interface to the run-time system provides access to information about running applications, so it's possible to develop tools that monitor, intervene, and reveal the underlying structure and activity of Objective-C applications. Interface Builder could not have been developed with a less dynamic language. As mentioned before Objective-C is an extension to the C programming language, which makes C object oriented. Then I told you that it wasn't something you wanted to know. I lied, you do want to know that. Without C there wouldn't be Objective-C. Objects in itself contain C code, so this section will introduce to you the basic parts of C, which happens to be the basic parts of Objective-C. We will start with data and then look at functions, because those are the two elements that make up every computer language and an object.

  4. 3. Data Types There are two different kinds of programming languages. The first one is called statically typed and the other is called a dynamically typed language. The difference between the two has to do with how values are assigned to variables. A variable is a named container for a value. Like, VAR=1 means that the variable called VAR has the value 1. This assignment is dynamically, because we haven't told anybody that VAR actually contains an integer. This means that apparently VAR can hold any value. In a dynamically typed language VAR=a; would also be legal. However C is a statically typed language. Which means we have to tell upfront what kind of data a variable is going to hold. To do this the language provides us with predefined data types, with which we can initialize a variable. Data types tell the computer the kind of data that is represented, which actually means the amount of memory that needs to be reserved to store information. To give you an overview of data types and the memory that is needed: Table 3-1. C standard types Type Description Size char A character of the local character set 1 byte (8 bits) Int An integer (whole numbers), e.g. 1, 2, 9, 1000 4 bytes (32 bits) Float Floating point number, e.g. 1.2, 1.7, 5.8 4 bytes (32 bits) Table 3-2. Derivative types Type Description Size Short A short integer 2 bytes Long A double short 4 bytes Long long A double long 8 bytes Double Double precision float 8 bytes

  5. Table 3-3. Objective-C data types Type Description Size Boolean type, which can either be YES, or NO. NO is 0, YES is BOOL non-0. 4 Id An object bytes STR IOD SEL IMP Id is the data type that indicates that we are talking about an object. So to declare a variable greeter we precede it by id. With which we tell that greeter is an object with its own rules. All mentioned lengths are the most common ones for 32 bit machines, like the Intel Pentium and compatible chipsets. The actual length is machine depended and can be found in the limits.h file and the float.h. Or can be shown with a little program like this: Sizes.h: /* Comments: ** Example written by Dennis Leeuw ** C code by Pascal Bourguignon */ #include <stdio.h> #include "Sizes.h" @implementation Sizes - (void)sizes

  6. { printf("sizeof(char )=%4d\n",sizeof(char)); printf("sizeof(unsigned char )=%4d\n",sizeof(unsigned char)); printf("sizeof(short )=%4d\n",sizeof(short)); printf("sizeof(unsigned short )=%4d\n",sizeof(unsigned short)); printf("sizeof(int )=%4d\n",sizeof(int)); printf("sizeof(unsigned int )=%4d\n",sizeof(unsigned int)); printf("sizeof(long )=%4d\n",sizeof(long)); printf("sizeof(unsigned long )=%4d\n",sizeof(unsigned long)); printf("sizeof(long long )=%4d\n",sizeof(long long)); printf("sizeof(unsigned long long )=%4d\n",sizeof(unsigned long long)); printf("sizeof(float )=%4d\n",sizeof(float)); printf("sizeof(double )=%4d\n",sizeof(double)); printf("sizeof(void )=%4d\n",sizeof(void)); printf("sizeof(id )=%4d\n",sizeof(id)); } @end The output this program returns is the relative size to the size of char. So if char is 8 bits and short int is 16, it will mention short =2. Since the ANSI C standard specifies size of (char) is equal to 1 by definition and size of (char)<=size of(short)<=size of(int)<=size of(long). But I think we are already to far away from the path we want to follow... You might know that computers only use a 1 and a 0 for their computations. That's why they call it a binary, from bi: 2. So everything we write in a program is actually converted to 1s and 0s. If we say that a integer is defined in a program, we actually mean that a piece of memory is reserved to store the amount of data that is associated with an integer. So let's have a look again at our Numbers program. We defined i and j to be short integers and from the above table we can read that that means that we use 32 bits of

Recommend


More recommend