The Joel on Software Discussion Group (CLOSED)

A place to discuss Joel on Software. Now closed.

This community works best when people use their real names. Please register for a free account.

Other Groups:
Joel on Software
Business of Software
Design of Software (CLOSED)
.NET Questions (CLOSED)
TechInterview.org
CityDesk
FogBugz
Fog Creek Copilot


The Old Forum


Your hosts:
Albert D. Kallal
Li-Fan Chen
Stephen Jones

Objective-C vs. C#

Can someone please explain to me how C# is better than Objective-C and more appropriate for general purpose application development? If not, then why is one in .NET and the other isn't?
Lies of Society Send private email
Monday, March 07, 2005
 
 
One is in .NET and the other isn't because one was written by Microsoft and the other wasn't.  'Not-invented-here syndrome'.  Besides, Microsoft desperately needed a language to compete against Java and, ideally, to replace VB6, and so C# was born.  It's easier to market a new language than an old one.

That's not to say that C# isn't better than Objective-C, mind you.  I'm taking no stand on that, though I'd expect it would have some evolutionary improvements.
Chris in Edmonton Send private email
Monday, March 07, 2005
 
 
Garbage Collection?

Wider support for things like GUI libraries (that in turn have wider support ie: WinForms, Gtk#, Avalon coming)?

Standard DB library available (ADO.Net, WinFS if/when it ships). What ever happend to DbKit and EOF (the later went Java and got real expensive IIRC)?

More people familar with it + easier transition from Java because of similarities.

Just off the top of my head.
Chris Altmann Send private email
Monday, March 07, 2005
 
 
C# is proprietary in the sense it was invented at MS and they are known as its daddy, Obj-C is not. MS always tries to go proprietary.

That said, C# is a fine language. Obj-C is more OO. C# is compiled to byte code, Oxy-C is compiled to machine instructions, but uses message dispatching whose overhead probably compares to the overhead of bytecode.

I don't think one is distinctly better than the other. They both are at the same level of abstraction.
Rich Rogers
Monday, March 07, 2005
 
 
does O-C have (first-class) pointers?
Sassy Send private email
Monday, March 07, 2005
 
 
I don't think I could affort first-class pointers, I'll take coach-class myself.

Okay, what's a "first-class" pointer?  One that "really" points to heap memory space?

And why would you need one?  Isn't a run-time-environment controlled 'handle' good enough?
AllanL5
Monday, March 07, 2005
 
 
"Okay, what's a "first-class" pointer?  One that "really" points to heap memory space?"

yes.

"And why would you need one?  Isn't a run-time-environment controlled 'handle' good enough?"

Depends on who you ask, no?
Sassy Send private email
Monday, March 07, 2005
 
 
Objective-C is a direct superset of C, which means any piece of ANSI C code can be compiled by any Objective-C compiler without modification (unlike C++). So yes, it has "first class" pointers, because C has them.

Objective-C is basically C with a Smalltalk-like object system. That means all objects are of the same type (id), late binding is the rule instead of being the exception, and object behavior is invoked by messaging.

Take a look at this article and try to tell me with a straight face that you'd rather use C#: http://www.gnustep.org/resources/ObjCFun.html
Lies of Society Send private email
Monday, March 07, 2005
 
 
So that means every language in .NET is better than every language not in .NET, huh?

I've been watching language flamewars for decades.  I had no idea that Microsoft's contribution to programming would be to come up with a simple way to figure out which language is best!

*runs off to port all the C programs on his computer to JScript.NET*

Monday, March 07, 2005
 
 
OP: let me put on my straight face as you asked. I would choose C# today, no doubts. And I used Objective-C for 3 years.

Objective-C used to be a great language - about 10 years ago. I'd say its main problem now is unsafety (no sandboxed/"managed" mode). C compatibility is a burden after all. There is a reason why Java and C# dropped it.

Most importantly, Objective-C is still a proprietary language, belonging to Steve Jobs & Co. No open standard, no defined evolution path.

So why would MS support competitor's proprietary language, let alone depend on it? After troubles with Sun and Java, it would be silly for MS to consider that seriously.
Dmitri Chatokhine
Monday, March 07, 2005
 
 
Objective-C is an open standard. The compiler that comes on the Mac is not even Apple, but gnu. (gcc to be precise). You can compile Obj-C on any platform you like, right now.

Where is the C# compiler for Mac? Where is the C# compiler for Sun? Where is the C# compiler for SGI?
Rich Rogers
Monday, March 07, 2005
 
 
Mono runs on OS X, doesn't it?

I don't know of any .NET runtimes for Sun or SGI, but it's theoretically possible.
Josh
Monday, March 07, 2005
 
 
Both languages have their advantages and disadvantages.  C# is basically Java plus everything Java should have had originally.  Event handlers, delegates, generics ...C# is definately a very nice language with garbage collection and other nice perks that make programming fairly easy. The downside is that C# is still a very MS platform only language.  Mono has gone to great lengths to solve this problem, but C# is still very much a language for Visual Studio .NET.

Obj-C is current used by Apple to make applications using their Cocoa framework.  It's very easy for C programmers to make the transition to Obj-C, and has things like the autorelease pool to make memory leaks a bit easier to avoid.    I have an iBook I use at home, and therefore have done some work in Xcode 1.5 with Obj-C.  I also use visual studio at work to develop ASP.NET web apps in C#.

Both languages serve their purpose well, and any good programmer should be able to use either one and get work done fairly quickly.  But I'll give you one big reason why I like Obj-C: method calls.  Which one of these is easier to understand?

C#:  circle.create(10, 0, 0);

Obj-C:  [circle createWithRadius:10
                  withCenterAtX:0
                              Y:0  ]
Larry Myers Send private email
Monday, March 07, 2005
 
 
objective-c is apple (really next-step) development; c# is microsoft's answer to java; they are in no way related. Both suck thoug, maybe thats the one thing they have in common.

el
Lemon Obrien III Send private email
Monday, March 07, 2005
 
 
Larry writes:

"Which one of these is easier to understand?

C#:  circle.create(10, 0, 0);

Obj-C:  [circle createWithRadius:10
                  withCenterAtX:0
                              Y:0  ]"

Well I don't know -- the C# DOES look pretty simple to me.

(Was that the wrong answer? ;) )
Peter Sherman Send private email
Tuesday, March 08, 2005
 
 
> Microsoft desperately needed a language to compete against Java and, ideally, to replace VB6...

Yes to the former and no to the latter.

The point was to KILL OFF Visual Basic, not replace it.  VB's success has galled the C crowd for over a decade, no less so among Microsoft's C bigots than anywhere else.  I wouldn't be surprised to find that Microsoft's C johnnies used the promise of a "new and improved VB 7" as a way to hoodwink Uncle Bill into getting more company resources for their pet project though.  Speaking of Bill, he's got to be seething privately, but he's smart enough not to cry over spilt milk - there is no putting that genie back into the bottle now.  It has to rank as one of his biggest personal failures though.
Arlo Rempher
Tuesday, March 08, 2005
 
 
Peter: it does?  (I've never used C# or ObjC, but it doesn't to me.)  For double or nothing, what are the bounds of the rectangle created by rectangle.create(5,5,10,10)?
not Larry
Tuesday, March 08, 2005
 
 
One interesting difference is that Apple produces Objective C, and which small developers love because it makes them so productive (I've heard people who've done Mac and Windows programming say it takes 5x more work to do the same thing on Windows), but Apple also uses it themselves: just about every app they ship is written in Objective C.

OTOH, Microsoft produces C#/.NET, which small developers like because it makes them more productive than C++, but AFAICT Microsoft doesn't actually use it themselves, at least for any non-trivial projects.  Word and Excel and Powerpoint and Internet Explorer are not written in C#/.NET, and may never be.

This may not *necessarily* be a bad thing about C#, but it would be enough to raise a red flag for me.  When you write a library or framework, you often don't learn what it needs to be able to do until you use it yourself to implement a non-trivial program.  (It's "eating your own dogfood", but for a library.)

Objective-C (and Cocoa) has been used for several major applications, so I know it's capable of that.  C# has been used for a lot of little one-offs and little free programs and shareware, so I don't quite trust it (yet).  As Joel says, "a good architect only uses tools that can either be trusted, or that can be fixed".

Tuesday, March 08, 2005
 
 
"Word and Excel and Powerpoint and Internet Explorer are not written in C#/.NET, and may never be."

I agree with that "may never be" because it would require a rewrite to get those into C# and, from being on this site, we all know that complete rewrites are bad.

However, from what I understand Microsoft is doing a lot of new development in C#/.NET and, of course, all of their web development is done ASP.NET.  There is definitely a divide between old Win32 development and new C# development -- and Microsoft is essentially doing the same thing as 3rd parties developers.

Apple is using the same API from 1992 and some of their apps (mail.app for example) are probably direct decendants of original NeXTStep applications.  So really, they haven't made a big switch to a new API -- they are simply promoting a different, fully complete but updated, OS for their platform.
Almost Anonymous Send private email
Tuesday, March 08, 2005
 
 
> Peter: it does?  (I've never used C# or ObjC, but it
> doesn't to me.)  For double or nothing, what are the
> bounds of the rectangle created by
> rectangle.create(5,5,10,10)?

I agree with Peter, the C# one does look easier to understand to me. I suppose that I might be biased since I am so used to the C++ syntax, and the Obj-C stuff seems rather strange.

But if you think that rectangle.create(5,5,10,10) is not descriptive enough, then you could fix it by adding a thing called a "comment".

Furthermore, the C# circle example is not really optimal, you could do something more like this:

circle.create( Point(5,5), 10 );

Is that hard to understand?

Creating the rectangle would be similar, if creating a rectangle by bounding width or height was important to you, then you would have a method for creating it that took a point and a width and height, not a bunch of separate values like you have given in your example. You seem to have chosen some designs in your examples, that are harder to understand - that doesn't mean that C# is hard to use, it means that your design there is not very good.
Michael
Tuesday, March 08, 2005
 
 
"Well I don't know -- the C# DOES look pretty simple to me."

I was kidding when I said this; although I don't mean such kidding to mean that the Objective-C was any better or any worse than C#.  Most IDE's will allow the user to move the mouse over a parameter in a parameter list and will show a little pop-up window of what a parameter's name is.  In such a case, the C# code is actually more "pithy" -- even though I'm not a C# fan, and this isn't meant as an endorsement of C#.  In other words, the relative readability between both forms is perceptual and subjective, and varies with people and with IDE's.  The same for the readability of the rectangle() statement.

Hence, I was only kidding when I said what I said.  I was playing "idiot savant", with more "idiot" and less "savant".

In other words, yours (and others) "perceptual mileage" may vary...

(Also, as an aside -- A circle can be drawn a whole bunch of different ways.  The Objective-C doesn't seem to allow specification of degrees or radians, or how much of the circle to draw, what to color it, which type of line segment to use, whether or not to draw it opaque (and the degree of opacity), the z-order, any kinds of clipped images to be painted inside it, any geometric shape to be circumscribed around it -- and the list goes on and on.)

And neither does C# to the best of my knowledge. (I don't program in either language, so I claim ignorance of both.)

In other words, maybe it's all relative.

Show me a programming language that understands WHY you need to draw a circle in the first place, and then suggests appropriate parameters depending on the context of your circle.  Then I'll be impressed.  Maybe AutoCAD or ProEngineer would be the closest two so far, but even so, "I am not impressed".

Respectfully,

Peter

;)
Peter Sherman Send private email
Tuesday, March 08, 2005
 
 
As far as OS X uses Obj-C, this circle example is actually an interesting one. In OS X, only the masochists use the Obj-C drawing routines. There is only one object - the Bezier curve. Creating a circle with Obj-C apis involves setting up a rectangle, then creating a special bezier curve initialized from the rectangle as an oval. If you want to create an arc, then you better be damn good at trigonometry and translating desired arcs into bezier coordinate space.

The less insane use the Quartz 2D API, which is part of Carbon's CoreGraphics API and is not easily available from Cocoa without a lot of messing around antics to access Carbon APIs from Cocoa. Not fun.

C# and .NET wins hands down really if you are trying to actually program something. Obj-C is nice, but the fact is that the Mac APIs are unbelievably horrible of you want to do anything interesting.
Rich Rogers
Wednesday, March 09, 2005
 
 
ANd for those curious here is the actual code from Apple's own documentation showing how to draw a simple circle in Obj-C:

NSRect aRect = NSMakeRect(0.0, 0.0, 50.0, 50.0);
aPath = [[NSBezierPath bezierPath] appendBezierPathWithOvalInRect:aRect];

This, my friends, is the real code. Now, you tell me if the C#/.NET example is more or less readible than this.
Rich Rogers
Wednesday, March 09, 2005
 
 
Well so you create your own Circle class that does the rectangle and bezier stuff.  That's a one-time effort.  Should Apple (really NeXT) made this part of the standard library?  Arguable, but either way it's not such a big deal.
AMS Send private email
Wednesday, March 09, 2005
 
 
I don't think I'm in the minority of application writers when I say that in my career I've needed to draw circles manually exactly... zero times.  And I've needed to manage my own canvas at all...  once.

Damning a framework because it takes three lines to draw a circle is pretty myopic unless it's representative of what the framework is designed for, which in this case it's not.
Jonathan Ellis
Wednesday, March 09, 2005
 
 
For God's sake, the contrived circle example could have easily been written like this:

[ Circle newWithRadius: 100 atX: 0 y: 0 ]

instead. In Smalltalk it would have been this:

Circle newWithRadius: 100 at: 0@0

or simply:

Circle radius: 100 at: 0@0.

(Sending the "@" message to a numeric object with another numeric object as the argument creates a new instance of the Point class with the receiver becoming the x coordinate and the argument becoming the y coordinate.)
Lies of Society Send private email
Wednesday, March 09, 2005
 
 
Almost Anonymous: Yes, I completely understand *why* they're doing it.  That doesn't change the result, though: ObjC/Cocoa has been used for years to build a lot of large real-world applications, and (AFAICT) C#/.NET hasn't.

I've been burned before, so having to be a guinea pig is not my idea of "appropriate for general purpose application development".  :-)
pretty much anonymous
Wednesday, March 09, 2005
 
 
We could argue all week about whether 1 or 2 lines to make a circle in $(LANGUAGE) is worse than the genocide.  That's not helpful.

The point is that by using keywords for all method arguments, you increase readability.  I can skim a page of Obj-C and know exactly what it does.  I can't do that for C# -- though if I was using your IDE I could hover over each method call and get kind of the same effect, by only taking about 10x as much time.

(No, comments are not the same.  Unless you have a programming team where everybody comments every argument of every method call.  And maybe not even then, because comments tend to be off to the side.)

I've seen (countless times in countless languages) functions that take ints (as above) or bools.  Nobody can figure out what o.do_stuff(true,true,false) does, or if the arguments are in the wrong order.  (Search your nearest program for a function that takes bools: that's a good place to find ambiguous code!  I always have to comment those extra-verbosely.)

And while changing the method (above) to take a Point object does help, it doesn't help in the (actually fairly common) case where type alone doesn't determine how an argument is used.  (Is this string a literal string, or a regexp?)  (Of course, you could write new classes and new methods for each one, but that means in practice you end up with a lot more code that you don't really need.)

Another take on it:
http://www.cocoadevcentral.com/articles/000082.php#5

Wednesday, March 09, 2005
 
 
> [ Circle newWithRadius: 100 atX: 0 y: 0 ]

Is this really what the syntax is like?

It seems utterly bizarre to me that stuff like "new" is run together with "WithRadius" forming a kind of compound keyword.

Then the, x y doesn't use "with", it uses "at" - how do you know when to use one or the other?


> Circle radius: 100 at: 0@0

This is also really weird, the x@y notation looks really strange, the common way to list coordinates in mathematics is with a comma in between them, so something like "x,y" looks  far more natural to me.
Michael
Wednesday, March 09, 2005
 
 
> <..> it doesn't help in the (actually fairly common)
> case where type alone doesn't determine how an argument
> is used.  (Is this string a literal string, or a regexp?)

I'm not really following you here - are you talking about when you're trying to understand already written code, or are you talking about when you're writing brand new code?

Anyway, if you're reading existing code, if that code is well written with descriptive names for the variables, that creates a sense of context of what is being passed as that argument. It's a way of building comments directly into the code.

If you're writing brand new code, then I'd say that often times it would be better for the thing that you're calling to be factored out into more separate entry points instead of only one single method that is hard to understand and use.

> but that means in practice you end up with a lot
> more code that you don't really need.)

I guess you're talking about hte factoring-out mechanism here. I don't find that it generates a lot more code than you really need at all, it's even easy to have a core function behind the scenes that is more complex and takes multiple-meaning arguments. Having easier to use smaller functions that delegate to other ones is not a big burden, I don't find that small helpers like that are a burdensome amount of code or anything, they tend to be really small.
Michael
Thursday, March 10, 2005
 
 
It seems "utterly bizarre" because you've never seen it before, dumbass. You've been raised on an unhealthy diet of C++/Java/C#, so no wonder anything different throws your little mind for a loop.

Smalltalk and Objective-C have message-driven object systems. That means you create objects and send them messages to invoke their behavior.

In the above examples, the message is not "new" or "newWithRadius", it's newWithRadius:atX:y:. The colons and keywords are all part of the message.

"the x@y notation looks really strange"

It's SHORTHAND. "x@y" is equivalent to "Point x: x y: y". All numeric objects respond to the "@" message by sending themselves and the argument to Point using the "x:y:" message, which creates a new Point object.
Lies of Society Send private email
Thursday, March 10, 2005
 
 
> It's SHORTHAND

Hmmm... Well, so much for being verbose and self-documenting as was claimed earlier in this thread.

I'm sure it works fine, but you're delusional if you think that "x@y" is some kind of wonderful crystal clear syntax.

Also, just so you know, the "x,y" syntax for points has been common in mathematics for a long time, it's not just specific to C++/Java/C#.

Saying Point( 10, 10 ) resembles regular mathematics notation closer than Point x: 10 y: 10 does. I don't think that the latter one is especially bad (way better than x@y, anyway), but I still prefer the former.
Michael
Thursday, March 10, 2005
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz