Objective-C: the More Flexible C++
It is a surprising fact that anyone studying GNUstep or the Cocoa Framework will notice they are nearly identical to the NEXTSTEP APIs that were defined ten years ago. A decade is an eternity in the software industry. If the framework (and its programming language--Objective C) came through untouched these past ten years, there must be something special about it. And Objective-C has done more than survive; some famous games including Quake and NuclearStrike were developed using Objective-C.
Objective-C gives you the full power of a true object-oriented language with exactly one syntax addition to C and, unlike C++, about a dozen additional keywords.
Since Apple purchase Next for $400 million and Mac OS X ships with Objective-C, recycling NEXTSTEP (later called OpenStep), as well as the fact that GNUstep is delivering the rock-solid window-manager Window Maker, Objective-C is (rightly) getting more attention because it is more flexible than C++ at the cost of being slower.
In reality, Objective-C is Object C and is as close to Smalltalk as a compiled language can be. This is no surprise as Brad J. Cox added object-oriented, Smalltalk-80-based extensions to the C language.
So objective-C is a hybrid between Smalltalk and C. A string can be represented as a `char *' or as an object, whereas in Smalltalk everything is an object. As with Java (int, double,.. are no objects) this leads to faster performance.
In contrast, C++ traditionally is associated with the Simula 67 school of object-oriented programming. In C++, the static type of an object fixes what messages it can receive. In Objective-C the dynamic type of an object determines what messages it can receive. The Simula 67 format allows problems to be detected at compile time. The Smalltalk approach delays typing until runtime and therefore is more flexible.
A GNU version was written by Dennis Gladding in 1992 and then Richard Stallman took over the development. The current GNU version is derived from the version written by Kresten Thorup when he was a still a university student in 1993. He ported that version to the NeXTcube and joined NeXT.
Apple chose Objective-C for Cocoa, as NEXTSTEP was based on Objective-C. But, even if they had written it from scratch, they might have decided to use Objective-C because it is object-oriented, which is undoubtedly a must for big software projects. It extends the standard ANSI C, so that existing C programs can be adapted to use the frameworks, and programmers can chose when to stick to procedural programming and when to go the object-oriented way. C was intended to be a good language for system programming. C is fine as it allows the programmer to do exactly what she wants, all the way down to the hardware. C also keeps the gold old pointers, which can be used for efficient code.
Objective-C is simple, unambiguous and easy to learn. But most of all, it is the most dynamic language of all object-oriented languages based on C. Its dynamic late binding offers flexibility and power. Messages are not constrained by either the class of the receiver or the method selector, allowing rapid change and offering access to information about running applications.
The following is a short introduction to OOP in Objective-C, starting with the basics. Procedural programs consist of data and operations on data. OOP works at a higher level by grouping data into units, which are called objects. Several objects combined and their interactions form a program.
Abstraction is at the root of all understanding; it helps us capture the bigger image as the details are hidden. Object-Oriented Programming and the Objective-C Language (see Resources) shows the image of a clock cut half-open: what we normally see (the external view) is the interface, and the implementation (the internal workings) is hidden inside.
@interface declares a new class. It indicates the name of the class and its superclass, the protocols adhered to, the layout of the instance variables and declares the methods implemented by this class. Traditionally a class interface is stored in a file called <classname>.h.
Only externally visible methods are listed in the interface section. However, there are visibility keywords for instance variables:
@private: the instance variable is accessible only within the class that declares it.
@protected: the instance variable is accessible within the class that declares it and with the class that inherits it.
@public: the instance variable is accessible everywhere.
@implementation' defines a class. The implementation is a collection of method definitions stored in a file called <classname>.m.
|Designing Electronics with Linux||May 22, 2013|
|Dynamic DNS—an Object Lesson in Problem Solving||May 21, 2013|
|Using Salt Stack and Vagrant for Drupal Development||May 20, 2013|
|Making Linux and Android Get Along (It's Not as Hard as It Sounds)||May 16, 2013|
|Drupal Is a Framework: Why Everyone Needs to Understand This||May 15, 2013|
|Home, My Backup Data Center||May 13, 2013|
- RSS Feeds
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Validate an E-Mail Address with PHP, the Right Way
- Designing Electronics with Linux
- What's the tweeting protocol?
- Kernel Problem
2 hours 7 min ago
- BASH script to log IPs on public web server
6 hours 34 min ago
10 hours 10 min ago
- Reply to comment | Linux Journal
10 hours 42 min ago
- All the articles you talked
13 hours 6 min ago
- All the articles you talked
13 hours 9 min ago
- All the articles you talked
13 hours 10 min ago
17 hours 35 min ago
- Keeping track of IP address
19 hours 26 min ago
- Roll your own dynamic dns
1 day 39 min ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi
It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?