The Cocoa Bindings system is a toolset available in Panther which allows you to define relationships between user interface and data objects. This means a lot less code, and a lot more functionality for free. This tutorial walks you through the conversion of a standard application into a bindings application.
I wish the frameworks I use when coding for the Win platform had this!!!
Do other frameworks support binding? I wonder if Java or .Net will support this (maybe they do?)…
I’ve tried binding with a few simple Cocoa apps and have been amazed so far… Nothing comercial or large, but seems to work for simple apps so far. Planning on writing some apps in pure Cocoa soon, so will know then I guess 😉
just “looks bad”. I’ve been a developer for nearly 10 years. For the first 6 years as a developer, I was primarily programming in C/C++ and as of about 4 years ago – I started developing in Java (about 50% my time is Java the other 50% is still C++). When I look at Obj-C syntax, it just looks absolutely horrible to me. I find it to be confusing, misleading and long.
Is this just me or do others feel the same about Obj-C?
Also, about in reference to the previous post – I believe GTK+ supports bindings as well.
While it is nice that Cocoa has data-binding standard with the development tools, many widgets in Windows have done this very same thing for many years. The best data-centric widgets for Windows development offer excellent performance in many large data set usage scenarios as well.
I am a developer for about 10 years too and in that time I do very different languages like: C/C++, Cobol (yes it still exists), VisualBasic & VBA, Java, C# and a lot of HTML coding.
Since 2001 I am a Mac user and about that time I develop ObjC apps in my sparetime.
You are right in pointing out that, when you first look at the ObjC syntax, it looks really strange. But I can ensure you that you need about one week to get really familiar with the syntax and you will like it.
The really good thing in ObjC is that every Method has named arguments:
Lets say you got a Class Foo that adds two values. In Javs the call might look like:
myFoo.add(5,3);
//You have to go to the doc to see what the two operants are
in ObjC you write (for example):
[myFoo addOperant1:5 toOperant2:3];
as you can see, in ObgC the arguments are allways named. You can read the method in a sentence. That might be trivial for a method that adds two values but is extremely helpful for complex methods with lots of parameters.
as you can see, in ObgC the arguments are allways named. You can read the method in a sentence. That might be trivial for a method that adds two values but is extremely helpful for complex methods with lots of parameters.
That is hideous. Just a decent IDE that shows you the arguments as you type if that’s a problem.
Damn that syntax is about as ugly as it can it!
When I look at Obj-C syntax, it just looks absolutely horrible to me. I find it to be confusing, misleading and long.
Objective-C was an attempt to make an object oriented C that never really took off (it never had anyone important enough behind it, like C# does.) FWIW, I’d much, much rather use Objective-C than C#.
I had the same problem with the look. I actually hated Python more (the whitespace thing) but even that grows on you. Cocoa’s memory management is really cool (I don’t like garbage collection), to the point that I implemented it for C++.
Yeah, it’s long winded and looks strange. I despise the whole Interface Builder system (it’s the single most confusing and counterintuitive thing I’ve ever worked with) but it does work once you figure it out. Project Builder/XCode, is, to put it mildly, not ready for commercial scale programming, primarily because of extreme slowness with large projects (and I don’t just mean gcc.) The biggest problem the Cocoa framework has is being closed source and having some major bugs and design flaws (both of which Apple has called “features”) that are hard to work around without the source. .NET is the same way, incidentally.
Objective-C is actually fun once you get used to it. I can’t really picture doing a whole program of any size or complexity with it, but it mixes fairly well with C++ and is, ultimately, a tool for making Apple GUI’s. At that, it’s not bad.
Oh my god!!!!
when will people get it that a good IDE does NOT make up for poor syntax!!!
lets say you were maintaining some code and were not using an IDE because you did not like them. now assume the developer was a moron and did not comment.
you would have to open up the 3 inch think documentation turn to the section with the method you are using, and look it up.
that is a waste of time!!!
and Obj-C is not a horrible syntax. it is meant to be readable and powerful, which it is.
I too find Objective-C truly bizarre. WTF is this:
if (self = [super init]) {
…. initialize stuff …
}
return self;
Since when can a constructor be run more than once on a single instance?
This whole bindings thing looks like a confusing take on the MVC paradigm, which other toolkits have also had for years. It’s semi-visual and has some translucent cubes: nice, but hardly world changing.
I hear all this whining about “eww it looks so weird”
it is called LEARNING A NEW LANGUAGE people.
of course the syntax will look different than C++, not that C++ is any awesome syntax artwork.
get over yourselves and try actually extending your skill set, and no, going from Basic, to Visual basic, to VB.Net is not expanding your skill set.
As a former VB, PHP, and Objective-C programmer, I think the whole “it looks ugly” argument about foreign language syntax is full of ****. Any half-way decent programmer could learn and get used to Obj-C in a day or two MAX. Heck, I’ve looked at Ruby and Python and think their syntax is weird, but I could get used it pretty soon I imagine.
If you have a Mac and want to write programs, Cocoa IS the way to do it. And it’s really enjoyable to use Obj-C, believe me. Besides, if you absolutely must, you can always use your beloved Java syntax to write Cocoa apps too.
Regards,
Jared
P. S. I bet if all you knew were Python or Ruby, you’d think Java and C++ are ugly. So it’s all relative, you know.
My last post didn’t make sense — I meant I’m currently a PHP and Obj-C developer, and I used to develop with VB. Sorry for the confusion.
Jared
> hear all this whining about “eww it looks so weird”
it is called LEARNING A NEW LANGUAGE people.
The reason why syntax is important is simple. If the syntax is:
– long,
– wordy,
– not readable
It means that it will:
– take longer for the developer to write code
– make code unclear as to what it does (b/c it’s so wordy) and difficult to upgrade at a future date
– be more prone to bugs/errors because the syntax doesn’t promote the ability to quickly recongize mistakes.
init is not a constructor, it’s an initializer. In C# and Java, a constructor is a special language construct which performs allocation of memory and instance initialization all at once. This is simply not so in Objective C (and in many dynamic languages). An initializer is just a regular instance method that by convention is known to initalize an instance of a given class.
I’ve worked extensively with the bindings system in Windows Forms and with the bindings system in Cocoa’s AppKit. While I’m also a strong .NET advocate, I have to say that Cocoa’s bindings just work a lot better than the bindings in Windows Forms. (Perhaps you’ve worked with other binding systems that are better than Cocoa’s.) They are always two-way, unless the target is read-only. This is not true of Windows Forms databindings. Also, binding in Objective C works with almost any class, because it is built into the root NSObject class. Again, not true with Windows Forms.
Objective C and C# are radically different languages. It’s just as easy to criticize C# from an Objective C programmer’s perspective. For instance, why can’t I declare a static virtual method? Why aren’t constructors polymorphic? Why is C# only polymorphic at the instance level?
what you just wrote is probably the biggest steaming pile I have ever read.
1) you must be lazy
2) oh please, unclear and difficult to upgrade? the code is very explicit, making it much easier to read, not unclear. and the upgradability of code is not contingent on how easy it is to read, it is contingent on how well a developer can design the code
3)Bugs!!! oh my god, you are really clueless, the length of the code and the explicitness of the code syntax has no impact on bugs.
my conclusion is that you have no idea what you are talking about.
“Ever notice that most of the larger Cocoa apps of any complexity are, well, made by Apple? Yeah, me too. Interesting, that. A lot of the 3rd party apps out there having massive investments in legacy code bases, and the opportunity-cost issue comes into play. And you also have the problem that if you’re using Obj-C/Cocoa, you’re pretty much tied to the Mac… if your app is of any significant size, this can be a pretty scary proposition. So they just use Metrowerks with C++ and the procedural APIs, aka Carbon. Yeah, it hardly ever feels “quite right”, and the wonders of Cocoa RAD are pretty much out of the picture, but it gets the job done and your code can go between platforms fairly easily if you’re careful. One could wonder who exactly reaps the lions’ share of benefit from Cocoa: Apple or independent developers.”
http://www.drunkenbatman.com/
First learn about the language before you start to say how aweful you think it is. Here are a few links:
http://www.dekorte.com/Objective-C/
http://theory.uwinnipeg.ca/gnu/libobjects/objective-c_24.html#SEC43
http://www.levenez.com/lang/
http://www.macdevcenter.com/pub/a/mac/2002/05/03/cocoa_history_one….
Second, you don’t need an IDE to develop applications in ObjC. Third any GUI framework that binds with c/c++ can bind with ObjC/ObjC++.
I started programming in the early 80’s almost 10 years before VB, and most GUI programming languages came into existance. The reason why many of you neve heard of ObjC was due to the fact that you were too young to remember NeXT, NEXTSTEP, and OpenStep (http://www.osnews.com/story.php?news_id=4042).
If you are truly interested in developing applications in a very sofisticated OO language I suggest you purchase “Programming in Objective-C” by Stephen G. Kochan. And then if you want to take it to the next level (no pun intended) look at “Cocoa Programming” by Scott Anguish, Et All.
BTW there is a differnece between Cocoa and ObjC. Cocoa can use ObjC, Java, and AppleScript to write native applications that run on OS X. Before you ask, no Cocoa applications written in Java can not be ported to other platforms.
because of the heavy reliance on Interface Builder, there are a lot of things in Cocoa program src code that are not very explicit. Of course you can create all your widgets by hand, but it’s a total pain in the ass to do so. I remember when looking at source to setup a cocoa toolbar, it’s like 10 lines of code for each stupid object on the toolbar.
My point? There is a weird disconnect between what you do in the GUI and in src, and I don’t care much for the “then some magic happens” layer BETWEEN two parts of my code (I dont mind the magic underneath my classes, but not between my own objects.
> Before you ask, no Cocoa applications written in Java can not be ported to other platforms.
<rant>
I really don’t want to sound like a troll, but does anyone else find this statement to be very discouraging. It almost completely takes away the usefullness of writing the application in Java if it’s not going to be able to be platform independent.
Don’t get me wrong, I love Java and have been developing in it for the last 4 years. But taking a performance hit (which, yes – I know it’s getting better with ever version) but taking a performance hit by using Java when you don’t have the benefit of portability seems somewhat dumb to me.
I guess the ability is there to allow Java developers like myself to ability to interact with the native API of OS X without having to use Obj-C.
</rant>
That’s why Cocoa/Java is far far less common than Cocoa/ObjC.
you use java very nicely between Mac and other platforms. the only thing you need Cocoa for is the GUI, guess what, 90% of the code is not the GUI.
write a Java app, use interface builder, done.
BTW, to Zephic, you are a VB developer right? you like your right click and insert code snippet development?
“My point? There is a weird disconnect between what you do in the GUI and in src, and I don’t care much for the “then some magic happens”..”
There is no “weird” disconnect between the GUI and the src, there is a disconnection, and that’s a good thing.
GUI the way it is done in Cocoa/GNUstep is quite close to how it is suppose to be done. You draw your GUI and connect it to actions in the logic, done. No source-generation or other evil things.
“And you also have the problem that if you’re using Obj-C/Cocoa, you’re pretty much tied to the Mac… if your app is of any significant size, this can be a pretty scary proposition.”
Cocoa is an implementation of the OpenStep standard. Because it is a standard, other implementations exist. GNUstep, for example, (http://www.gnustep.org) is an implementation that works on many Unix-like operating systems. It doesn’t take much work to port a Cocoa app to GNUstep. There are a few extensions which GNUstep doesn’t have yet, but progress is pretty swift.
Just as a quick note, you CAN implement the standard java GUI and it WILL run under OS X. Ive developed several small diving applications in the past (for my own use) with Java 1.4 in Linux and they run very well on OS X.
True, if you develop a Cocoa based Java app, then its not going to be portable, though the model classes should be.
“And you also have the problem that if you’re using Obj-C/Cocoa, you’re pretty much tied to the Mac… if your app is of any significant size, this can be a pretty scary proposition.”
If I uses the WinAPI’s or ATL or COM/DCOM and so on I’m pretty much tied to the Win platform am I not? (yes, I read the article on COM Dev on Mac, but there are still many many problems). I could tie myself to Linux just as easily.
If I was starting a big project on the Mac, I would have to make certain decisions
1. Is this only a Mac app, or do I want it on more platforms.
2. Which platforms (will make a difference)
3. Does it interact with Mac specific h/w?
I think with a bit of foresight, most apps that aren’t tied to a specific device or hardware could easily be written for all platforms at the same time.
When I write code in Delphi on the Win platform, I don’t write business logic into my forms (well, except for test apps and so on). I keep my business logic seperate. Takes a bit more time (first time anyway), but the benifits are worth it…
To port code to the Mac would be simple enough, code your business logic in Java, C, C++, Ruby, Perl, whatever.
Write your interface in pure Cocoa and attach the needed business logic. There would be very little code needed to do this, and your app on the Mac would look like a native OS X app, your app on the PC would look native there…
Too easy…
There is no reason why business logic has to be in Obj-C and use the Cocoa framework.
there you go now, making sense and all.
When I said that you can’t port Cocoa/Java applications, I was refering to the program as a whole. The backend of your applicaton that is written in Java can be run on other platforms. You can use standard Java API’s to talk to middle tier applications, databases etc… The most difficult part of a Java/Cocoa application for a standard Java developer is understanding how to wire the UI to the backend. Which is not difficult.
If you have experiance developing OO applications, grasping Cocoa should take you an hour, two max. If you are unable to think in an OO approache to solving problems then you will never grasp the Cocoa concepts for developing applications. And…. there is a big difference in unsderstanding Java, C++, Delphi, C#, PowerBuilder syntax and knowing how to think and write OO applications.
If you’re new to the mac programming world, i recommend you first learn objective-c. I’ve put together a good online tutorial for those experience programmers who just want to dive right in: http://www.otierney.net/objective-c.html
Objective-C is nothing but C with OOP extensions, with a runtime engine implemented in C. The OOP syntax is identical to smalltalk, as this is what it’s based off of. Thus to understand why the OOP syntax seems “weird” you have to consider objective-c is really two languages mixed: c and smalltalk. however that’s about the only major difference from C. it’s mostly C types/syntax/pointers/memory with a thin layer of OOP abstraction on top to handle inheritance/polymorphism and various other nice oop features.
but, honestly, as another person posted in the C# article a few articles back, consider this example (i’ll just copy/paste it for the sake of simplicity):
By Chris (IP: —.vs.shawcable.net) – Posted on 2004-05-01 23:46:41
In the latter (C++/Java/C#-ish) syntax, how do you know what each argument is for?
Consider the following fictional example:
String * myString = “hello”;
String * subString1 = [myString subStringFrom: 1 to: 3];
String * subString2 = [myString subStringFrom: 1 withLength: 3];
vs.
String * myString = “hello”;
String * subString1 = myString.subString(1, 3);
String * subString2 = myString.subStringWithLength(1, 3);
Now, is the first argument the start index, or the end/length of the desired substring? Guess you’re off to the documentation while the Obj-C programmer merrily continues coding.
be careful, the VS.Net fanboys will start to tell you that explicit and expressive syntax is a hindrance that causes you to be less productive and make more buggy code <snikers at the non-CompSci programmers>.