Objective-C Programming: Will Learning C and / or Smalltalk Help?

Objective-C is an object-oriented programming language that adds Smalltalk-style messaging to the C programming language. I understand that learning Smalltalk can be a good way that learning Lisp is useful for one knowledge, but I want to know if it helps Whether learning the methods defined in Smalltalk is more understandable by Objective-C, given the role of Smalltalk in its "origin story". If so, what exactly?

Assuming someone already knows C programming, what can we learn from Smalltalk? Obviously, there are many concepts in Objective-C that simply aren't in C (i.e. messaging, interfaces, protocols, dynamic typing, delegation, reflection, object-oriented!), But they come from Smalltalk.

Edit: I added the C programming language to the question, since the general consensus is that C training is better to use once than Smalltalk training (when it comes to programming in Objective-C).

+6
c objective-c smalltalk
source share
7 answers

Smalltalk is an incredibly compact language and remains one of the purest object oriented languages. Objective-C is a pragmatic compromise between Smalltalk and C, which leads to some very significant differences. For example, in Smalltalk, all this is an object - even prime numbers - and each manipulation of the object is done by sending a message. Messages are evaluated in the same order, regardless of their name. So, for example, the following:

8 + 9 / 23 + 16 * 8 

It is evaluated in strict order from left to right, because the operators '+', '/' and '*' do not have much meaning for the language, which is just messages transmitted to numeric objects.

Objective-C adds Smalltalk-style objects to C, but is also a strict superset of C that preserves C primitive types and built-in operators. Thus, in Objective-C, the normal mathematical order of operations will be applied to the expression above - division and multiplication will be performed first, additions later.

Learning C is absolutely essential for a deep understanding of Objective-C. Objective-C is a strict superset of C and explicitly uses exactly the same syntax and semantics as possible. He transplants the concept of objects in C because of the ability of C to hold a pointer to a thing, not knowing how to apply any operations to an object. He then extends C syntax to provide means for sending messages to objects and for declaring and implementing messages that an object can receive.

Most of the overall design of the Objective-C runtime, especially in conjunction with Cocoa, comes directly from Smalltalk, including the concept of a selector, the use of metaclasses as factories for class instances, hierarchies and inheritance systems, the separation of the view-controller model (the original Smalltalk, though and now almost ubiquitous) and a multitude of posts defined in standard collections and objects.

At the top of my head, Smalltalk is also very different in its flow control system and has a similar, but subtly different, idea of ​​a “block” (although most of the new implementations brought them into line). Apple actually implemented the blocks as an extension at the C level, which is used by many new methods for Objective-C objects.

That being said, the Goldberg Smalltalk-80 book is extremely well written, easy to read, and language so simple that you can learn the whole language in just two or three chapters. Most of the complexity is swallowed by objects available at run time, and it is obvious that the material is not being transferred. The benefit lies in the fact that ideological material about objects and runtime is very much separated from the specifics of printing. Conversely, C does things like flow control and arithmetic, a language function, which means more syntax and more to read before you really feel that you know what is going on.

So, in conclusion: Smalltalk-80 (purple) is definitely noteworthy and extremely useful, but not necessarily completely relevant. Learning C is important anyway; my links to K & R for comparison.

+6
source share

From Smalltalk, you can learn real object-oriented programming. Hybrids like java, C # and Delphi don't seem to be that good. After ten years of hybrids, my coding style has improved significantly after several months of Smalltalk.

As an iPhone developer, you are probably more interested in designing the libraries and concepts that are used than the syntax. c there will be no help there (although you need to understand some basics). Programming in Objective-C is much more like programming in Smalltalk. Smalltalk smart environments are far superior to Objective-C objects and help you better understand how object-oriented code works and how to create it. It's much easier to keep your code clean and well refactored in Smalltalk (IDE) than any other object-oriented language. Cocoa libraries are very well designed, at least compared to java or .net. They seem to look a little better than, for example, Squeak Smalltalk.

+5
source share

I have to disagree with Knodel, just see an example in this

[someObject message] and see

someObject message.

You see that Objective-C uses the same "positioning", and yes, it comes from Smalltalk. Smalltalk training is always a good investment. And the point in this area is 100% smalltalk to send a message to either an object or a class that itself has some MetaClass.

And yes, learning C is useful to know how to use the Objective-C part, but getting used to OO is not studied C. Knowing C and Smalltalk makes it easy to use Objective-C. BUT Objective-C is not just a language that “power” comes from class libraries. Therefore, spending time on this is definitely a good time spent.

And yes, you knew C and Smalltalk better to do your best with Objective-C.

+3
source share

Disclaimer: I do not know Smalltalk.

I'm sure your Obj-C skills will benefit from learning Smalltalk, but in my opinion, your time will be much better spent learning C. As someone who learned Obj-C before understanding C, concepts taken Smalltalk is easy to pick up; concepts taken from C are much more complicated.

+2
source share

Yes, the Objective-C object parts are very similar to Smalltalk. If you first learn Smalltalk, some of the Objective-C concepts will be simpler, and the syntax for sending messages will be less shocking. However, I don’t think that Smalltalk will necessarily be easier to learn than Objective-C, of ​​course, if you do not already know C, so that you can immediately learn Objective-C.

Having said that, Smalltalk is a good IMO language and deserves to be studied for its own sake.

+2
source share

I think the best background for learning Objective-C is C. If you know C, you can easily get acquainted with object-oriented programming and write in Objective-C.

Personally, I don’t think teaching Smalltalk to us is a good idea.

0
source share

Getting used to passing messages to objects instead of calling methods is pretty easy without a SmallTalk background. However, SmallTalk is not like C (except for the SuperCollider variant), and the language even considers code blocks and other crazy things as first-class objects: for example, in SuperCollider {i < 5}.while({ // do stuff }) This behavior did not work to Objective-C, and most likely will just confuse you, like him.

0
source share

All Articles