 |
 |
I think Obj-C sucks
|
 |
|
 |
|
Registered User
Join Date: Apr 2001
Status:
Offline
|
|
OK, dont bash me too hard if I'm wrong, but I hate the syntax of obj-c. It makes way more sense to have function(parameter) than [function parameter]...I know this is insignificant, but the whole language uses illogical conventions
|
|
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
Part of why you think it sucks is because you've gotten it wrong.
It's [class method:value0 param1:value1 ....]
|
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Sep 2000
Location: Medford, MA
Status:
Offline
|
|
If you're used to thinking function(parameter) it's a little funny. Obj-c wants to stress that you're not calling a function, you're sending a message. When you become intimate with the language, you'll see that these are very separate things on the implementation level, and you should think about them separately too. It's a different approach, and can be quite cool.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Sep 2000
Status:
Offline
|
|
Also,
[document save:YES usingName:"My Doc" asRichText:NO createPreview:YES saveBackup:NO];
is lot clearer than
document.save(YES, "My Doc", NO, YES, NO);
So when you have multiple arguments, ObjC's argument keywords are quite handy.
Ali
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Feb 2001
Location: Rochester, uk
Status:
Offline
|
|
you know, it'd be nice if it bothered to rearrange the arguments according to what you call them, so that:
[x do: x isDocument: YES isVisible: NO]
did the same as
[x do: x isVisible: NO isDocument: YES]
At the moment, it simply ignores what you actually call the parameters. In fact, i think this would work:
[x do: x : YES : NO]
|
|
All words are lies. Including these ones.
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Sep 2000
Status:
Offline
|
|
Originally posted by sadie:
you know, it'd be nice if it bothered to rearrange the arguments according to what you call them, so that:
[x do: x isDocument: YES isVisible: NO]
did the same as
[x do: x isVisible: NO isDocument: YES]
At the moment, it simply ignores what you actually call the parameters. In fact, i think this would work:
[x do: x : YES : NO]
Actually no, it's pretty strict with regards to the keywords. So if there are keywords, they have to be in the specified order, and the keywords have to be specified.
Might be nice to allow reordering them, but this could lead to ambiguities, where you can't tell which method you're really calling. Having the option of not specifying them would not only make the source less readable, but it would also introduce ambiguities...
Ali
[This message has been edited by ali (edited 05-19-2001).]
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status:
Offline
|
|
Originally posted by sadie:
At the moment, it simply ignores what you actually call the parameters. In fact, i think this would work:
[x do: x : YES : NO]
No, actually. The "parameter names" are in fact part of the method name.
The method name do:isDocument:isVisible: is a separate method from do:isVisible:isDocument, which is separate again from do:::. Things like @selector and NSSelectorFromString() expect the full name like that. It's just that the parameter values are mixed in with the pieces of the method name for increased clarity. This style is taken directly from Smalltalk, the original object-oriented language (in fact, Objective-C was modeled on Smalltalk as much as possible).
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status:
Offline
|
|
Originally posted by ali:
Also,
[document save:YES usingName:"My Doc" asRichText:NO createPreview:YES saveBackup:NO];
is lot clearer than
document.save(YES, "My Doc", NO, YES, NO);
So when you have multiple arguments, ObjC's argument keywords are quite handy.
Ali
I have to agree with the original poster. That is just whacked!
What a bunch of useless typing! 85 characters VS 42!!!
I LOVE JAVA!
It is so syntactically clean. And javadoc helps keep it all perfectly clear.
Why would anyone prefer that horrendous syntax
|
|
signatures are a waste of bandwidth
especially ones with political tripe in them.
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Feb 2001
Status:
Offline
|
|
But it's more clear. If I am calling a lot of functions with multiple parameters of the same type (like several booleans as in the example above), I often feel obliged to make some comments about what they are doing anyway -- so the Objective C syntax maintains clarity, saves typing, and lets me keep on programming without checking the docs. (Now if Apple's documentation was as good as that for Java, this might be less of an issue  .) For an alternative (non-C) syntax, they could have done a lot worse (perl comes to mind).
|
|
The 4 o'clock train will be a bus.
It will depart at 20 minutes to 5.
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Nov 2000
Location: Malaysia
Status:
Offline
|
|
Originally posted by lenz:
OK, dont bash me too hard if I'm wrong, but I hate the syntax of obj-c. It makes way more sense to have function(parameter) than [function parameter]...I know this is insignificant, but the whole language uses illogical conventions
You are 110% correct. But if you want some advice, I wouldn't post anything like that on any forums used by developers for the apple platform. I would hate to think of the responses you would get.
Any "objective" developer would have to agree with lenz, in comparison to typical languages of today. If you were raised to only develop for objective-c, then you wouldn't be able to see the forest for the trees and know about typical programming languages to understand what lenz is talking about.
---gralem
[This message has been edited by gralem (edited 05-22-2001).]
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Mar 2001
Status:
Offline
|
|
Here's how a certain method would look in C++. What does it do?
myBitmapImageRep = new NSBitmapImageRep(NULL, 400, 300, 8, 4, YES, NO, NSCalibratedRGBColorSpace, 0, 0);
Here it is in Objective-C. It's a bit easier to tell what it does now, isn't it?
myBitmapImageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:400
pixelsHigh:300
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:0
bitsPerPixel:0 ]
I don't honestly see how "Any 'objective' developer would have to agree with lenz," other than the fact that the C++ syntax is far more common than the Objective-C one. I certaintly wasn't raised to only develop for Objective-C.
-Peter
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: May 2001
Location: Oviedo, Floriduh USA
Status:
Offline
|
|
Objective-C isn't bad, but it's REALLY different. I've worked in all sorts of languages, most of which use no keywords in calls. It's always much easier to use keywords.
I have been reading through the examples given on the developer CD-ROM and I find it difficult to understand the syntax of Objective-C at the function definition/implementation level. The '+' and '-' are unclear to me. The Java plus NeXTStep/Cocoa (why do all the functions have NS in front? :-)) combination is much more agreeable at this point.
I think that, if there is a drawback to getting UNIX developers onto Mac OS X, it's going to be Objective-C as a native, more dynamic replacement to C .
Yuki
|
|
folding@home is good for you.
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Nov 1999
Status:
Offline
|
|
So in other words, you don't like Objective-C because you aren't used to the conventions.
Yeah. Great reason to hate something. Tell me what's so illogical about Objective-C's message-passing syntax (which is, incidentally, quite different from its function-calling syntax; that syntax is identical to C's).
|
|
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2001
Status:
Offline
|
|
Originally posted by lenz:
OK, dont bash me too hard if I'm wrong, but I hate the syntax of obj-c. It makes way more sense to have function(parameter) than [function parameter]...I know this is insignificant, but the whole language uses illogical conventions
I don't know if it's really fair to say that ObjC sucks just because you aren't used to it. ObjC was built as a fully Object Oriented extension of C, and as a result was modelled somewhat after the worlds first (from the ground up) Object Oriented language... SmallTalk. If you have ever developed using SmallTalk you will instantly see the similarities between it and ObjC. The "message and receiver" methodology is an integral part of the true Object Oriented paradigm as Alan Kay intended, currently only SmallTalk and ObjC fully implement this idea. This is a common problem for a lot of developers though, and is largely why SmallTalk didn't catch on. The true OO paradigm really requires a different mindset than all the previous Procedural languages which have been around since FORTRAN and COBOL. Because this divergence was keeping the OO paradigm from gaining acceptance we now have languages like C++, which is a horrible bastardization of Object Orientation, and Java which still doesn't adhere stricktly to the paradigm but is a much easier transition for those who have been thinking in terms of the Procedural paradigm for so long.
Many many languages would seem strange to you, especially languages like Prolog and Lisp. Even Pascal is radically different from C/C++ in style and implementation, I mean it allows for both Lexical and dynamic scoping as well as nested procedures (functions). Just because these languages are different doesn't mean they suck, in fact Prolog and Lisp are DRAMATICALLY different from anything you've likely seen, but they are both VERY useful for many different tasks. I have written Lisp programs that are 4 lines long that would require nearly a full page of C code to accomplish the same task. It just depends on your needs. Apple is pushing very hard for developers to start thinking of developing using OO frameworks, and for that to really work well they needed to use a very OO language.
Anyhow I just finished a detailed upper division Programming Languages course last term and I just thought I'd share my knowledge and observations, I hope I didn't bore you to death
-Nathan Aschbacher
P.S. I couldn't remember my password, and I couldn't get at my e-mail so I just started a new identity
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Originally posted by bousozoku:
I have been reading through the examples given on the developer CD-ROM and I find it difficult to understand the syntax of Objective-C at the function definition/implementation level. The '+' and '-' are unclear to me. The Java plus NeXTStep/Cocoa (why do all the functions have NS in front? :-)) combination is much more agreeable at this point.
I think that, if there is a drawback to getting UNIX developers onto Mac OS X, it's going to be Objective-C as a native, more dynamic replacement to C .
First of all, + and - are used in method definitions to define whether a method is a class method or an instance method.
+ means a class method (e.g. [NSString stringWithString:@""])
- means an instance method (e.g. [myBlahString initWithString:@""])
instance methods must only be used in instances of objects.
everything is prefixed with NS because it's standard practice to prefix eveyrthing in a framework with something to avoid namespace clashes. In C++ this can be changed with "using namespace", but it's still customary. For exmaple, PowerPlant prefixes everything with L, I think. It's called NS because it was originally from NextStep, and it would be pretty pointless to go through and change everything to AC (apple cocoa) or whatever.
you should read the Objective C manual, that explains the + and -, and lots of other weirdnesses of Obj-C.
Obj-C is NOT for luring UN*X developers to Mac OS X - in fact, very few UN*X developers use Obj-C. They mainly use C or C++.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Sep 1999
Location: Ottawa, ON, Canada
Status:
Offline
|
|
Originally posted by lenz:
OK, dont bash me too hard if I'm wrong, but I hate the syntax of obj-c. It makes way more sense to have function(parameter) than [function parameter]...I know this is insignificant, but the whole language uses illogical conventions
Heh heh, you ought to try LISP.
I am so glad we had to learn LISP in university. It's the absolute best way to learn recursion.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2001
Location: Provo, UT
Status:
Offline
|
|
Not having taken the dip into Obj-C yet, I can't speak too much about it. I have to say that the syntax does look a tad ugly. If it is an extension to C, shouldn't it have at least follow the basic syntax of C? Say what you will about C++, but at least it is still pretty much C. (And you don't have to use things like exceptions or templates which are what usually cause troubles anyway)
Having said that though I should add that the extension to parameter passing isn't that different from what many developers use with the various incarnations of Visual Basic. So it isn't as if it is *that* weird. I must say that all the square brakets and so forth do throw one off a bit. It does seem a little overly verbose as well.
The original poster's comment still is valid, however. If one is porting software to the Mac, then having the most efficient framework use an unfamiliar language will throw one off. There is Carbon vs. Cocoa, but from what I've been reading Carbon doesn't have all the abilities or efficiencies that Cocoa does. (Certainly the Finder doesn't inspire confidence)
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Mar 2001
Status:
Offline
|
|
Originally posted by clarkgoble:
Not having taken the dip into Obj-C yet, I can't speak too much about it. I have to say that the syntax does look a tad ugly. If it is an extension to C, shouldn't it have at least follow the basic syntax of C?
A valid complaint! In fact, Apple did create a "modern" syntax for Objective-C that looks a lot more like Java. The OS X compiler will still compile it if you give it the right flag. The modern syntax has since fallen out of favor (and I'm glad it did, since I really appreciate the consistency of the original Objective-C syntax).
Say what you will about C++, but at least it is still pretty much C. (And you don't have to use things like exceptions or templates which are what usually cause troubles anyway)
At this point, I have to point out that Objective-C is closer to C than C++ is to C, since every C program is also a valid Objective-C program, but not every C program is a valid C++ progrm.
Having said that though I should add that the extension to parameter passing isn't that different from what many developers use with the various incarnations of Visual Basic. So it isn't as if it is *that* weird. I must say that all the square brakets and so forth do throw one off a bit. It does seem a little overly verbose as well.
The original poster's comment still is valid, however. If one is porting software to the Mac, then having the most efficient framework use an unfamiliar language will throw one off. There is Carbon vs. Cocoa, but from what I've been reading Carbon doesn't have all the abilities or efficiencies that Cocoa does. (Certainly the Finder doesn't inspire confidence)
Simply changing the syntax of Objective-C would not make the language familiar, and it would alienate those few programmers who do know the language and have Objective-C code to port.
The fact that "the most efficient framework uses an unfamiliar language" is the reason that Apple exposed the Cocoa library to Java, a language that is familiar to a lot more people. We all know how well Cocoa/Java works.
-Peter
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status:
Offline
|
|
I am in diapers when it comes to Objective-C and just plucking examples off the web and going through them. My INITIAL biggest complaint was the same that you read above, I completely understand.
I strongly suggest to give Objective-C a chance. If you give it some time, you will discover that Objective-C sticks closer to the OO paragdims than Java -and do understand that this is not easy for me to say, I think very highly of Java. Right now, my biggest Objective-C gripe is not having a good book with a comprehensive description of all the Cocoa frameworks and examples on how to use them -greedy ah?
Be as it may, learning Objective-C has been very rewarding and it's just amazing how fast I can put apps together! The whole deal with the outlets and connections is SO much more efficient than having to code with inner classes and messy event handling.
I have so much more room to experiment. Give it a shot guys, make the effort you will very pleased. My two cents. Cheers.
|
|
iMac 17" G4 800MHZ & 768 SDRAM
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
For all you confused by Obj-C folks take a read of "Object Oriented Programming, An Evolutionary Approach" by Brad J. Cox. He also wrote most of NeXTStep for Steve in the old days, that has turned into the Cocoa libraries.
I don't know if he also wrote the Obj-C or not, but he certainly had a strong influence on it's utility. The concepts are explained much better than a programming book and it's not that long. It is getting a little old though (written in '85).
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Aug 2000
Location: the chair in front of my Mac
Status:
Offline
|
|
Originally posted by Wixar:
In fact, Apple did create a "modern" syntax for Objective-C that looks a lot more like Java. The OS X compiler will still compile it if you give it the right flag. The modern syntax has since fallen out of favor (and I'm glad it did, since I really appreciate the consistency of the original Objective-C syntax).
You know where I can see a example of this code?
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Location: Stockholm, Sweden
Status:
Offline
|
|
The big problem (as I see it) with Objective-C isn't the message syntax at all but that stone age preprocessor. That thing has _no_ place in a modern oo langage! And we all have to use it! For example, as it is now you can't use exceptions without it. This is really bad.
Namespaces would be a very good thing to have by the way. Would get rid of those prefixes (NS-).
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status:
Offline
|
|
Lighten up, you can't be serious about being bothered by the "NS" prefix.
As far as the preprocessor goes, can you provide an explanation in regards to how the OO paragdim is impacted by having preprocessor? Is irrelevant isn't it?
[This message has been edited by DaGuy (edited 05-27-2001).]
|
|
iMac 17" G4 800MHZ & 768 SDRAM
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Location: Stockholm, Sweden
Status:
Offline
|
|
Lighten up, you can't be serious about being bothered by the "NS" prefix.
I'm dead serious. Not because of the NS of course but because name clashes are something you want to avoid. Having one large global namespace is bad and forces you to come up with prefixes like NS.
As far as the preprocessor goes, can you provide an explanation in regards to how the OO paragdim is impacted by having preprocessor? Is irrelevant isn't it?
Get real.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Having NS prefixes before classes is a good thing, avoids namespace clashes. It's standard practice, all frameworks do it. (MacZoop, PowerPlant, MacApp, GTK+, Qt, just to name a few off the top of my head)
Also, I don't understand what you mean by not being able to use exceptions. You can use execeptions in Cocoa - see the NSException documentation inside the Foundation reference. It goes like this:
NS_DURING
...
...
[anException raise];
...
...
NS_HANDLER
blah blah blah handle the exception
NS_ENDHANDLER
if the exception isn't handled then it is passed back up the calling chain until it reaches the top, where if it is still unhandled will cause your application to quit.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Location: Stockholm, Sweden
Status:
Offline
|
|
Prefixes are a good thing if you don't have namespeces in the language. But it doesn't eliminate the problem with everything in the same global name space. A better solution is to have a language that lets you specify a different namespace for every framework etc and inside each of these the 'prefixes' are implicit. Voila! No clashes.
Regarding the preprocessor. I never said you could not use exceptions. What I said was that you cannot use them without the idiotic MACROS, which I absolutely detest. That was just an example, and you don't have to agree with me. (Besides, using setjmp/longjmp for exception handling is *bad* but thats another matter)
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status:
Offline
|
|
You are right. We don't have to agree with you.
|
|
iMac 17" G4 800MHZ & 768 SDRAM
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Location: Stockholm, Sweden
Status:
Offline
|
|
Please stop talking about yourself in third person ;-)
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Feb 2001
Location: Portland, OR, USA
Status:
Offline
|
|
I've been coding in Objective-C now for about 8 years, love it, hope the people who think it sucks will give it a fair chance, et cetera...
That being said, I gotta agree with Zeke here, that namespaces and built in zero-cost exception handling are the two features that I would love to see added to Objective-C.
I talked to a couple guys down at WWDC last week on the compiler team, and they are very interested in putting together a standards committee and defining an ISO standard Objective-C. Namespaces and built in exceptions are the two big features on the short list for addition.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Originally posted by gregomni:
I talked to a couple guys down at WWDC last week on the compiler team, and they are very interested in putting together a standards committee and defining an ISO standard Objective-C. Namespaces and built in exceptions are the two big features on the short list for addition.
That would be great. If it was a recognised "standard", more people might be attracted to it (currently the only real community of Obj-C developers looks like Apple and people who develop for OS X - there is of course GNUstep but that's not that big at the moment, AFAICT).
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|