views:

1561

answers:

6

Is it possible for the .NET CLR to support Objective-C? Are there any reasons (either from a legal or implementational) standpoint why this wouldn't be possible?

In the spirit of cross-platform application development, it would be nice to be able to write and run Objective-c applications on Windows machines. At least i think it would.

+1  A: 

No there really aren't. .NET compiles to IL (or CIL or MSIL) which is basically machine code for a virtual machine. You can program in IL like you do in assembly (not that I've seen anyone do it). If you had the experience, knowledge, and gumption there would be no problem writing an Objective-C to IL compiler. Hell, there are even functional programming languages (F#) for .NET. Besides the messaging capabilities and the libraries, it's not too different from C#, VB.NET, etc.

What an awesome idea! Objective-C# or some such.

Here's where you might start: Wikiepedia on Microsoft's IL.

SoloBold
+5  A: 

Objective-C is a strict superset of C. As such, it's got a lot of features like pointers that translate poorly onto .NET. Of course, it may be that -- in practice -- most Objective-C programs are written in such a way that they would also compile against a more tightly-defined version of the language spec that was more restrictive but could be translated into safe code.

Assuming this is the case, the method dispatch part of Objective-C is a natural fit for the dynamic capabilities of the DLR. I've actually considered creating such a port.

Curt Hagenlocher
Can C++ be compiled to .NET bytecode? If so, it should be possible to write an Objective-C compiler for .NET. (I'm not too familiar with .NET, though; I _think_ you can compile C++ for .NET, but does it actually compile to .NET bytecode, or does do something else?)
mipadi
No, arbitrary C++ can't be compiled to IL, though a weird subset of it can be. That's the source of my comment. :)
Curt Hagenlocher
Right - one of the key features of "safe" .Net code is the lack of support for pointers (we get references instead) and, in particular, pointer arithmetic. Objective-C being a superset of C means that it supports pointer arithmetic, and as such any apps that use that language feature will be nigh-impossible to convert to managed CLR code.
Dathan
+3  A: 

There should be no problems hosting Objective C ontop of the CLR. You can probably implement the runtime ontop of the DLR, or in the worst case implement your own. That is still significantly different from compiling any substantial Objective C code bases for the CLR, since the vast majority of the Objective C code you are likely to be interested in depends on Apple's frameworks.

In the end you will either need reimplement them, or, bridge Objective C over to the .NET frameworks, which would allow you to write Objective C code, but it would not be using a framework compatible with any existing Objective C code. You might want to take a look at Cocotron which is a cross compile environment that allows Mac developers to move some Objective C apps to Windows. That should provide a reasonably good example of an Objective C runtime for Windows, as well as potentially provide a few frameworks necessary to make a reasonable amount of Objective C code usable once you bring up a compiler that can target .NET

Louis Gerbarg
+3  A: 

If you mean being able to write .NET applications using the Objective-C syntax and being able to use the data structures from the Foundation frameworks (such as NSArray) this is trivial (albeit lengthy) to accomplish. It would be no different than adding support for any language.

However what makes Objective-C development great on the Mac isn't the syntax, it's the other API's that Apple provides like:

In addition to these APIs which would be much harder to implement, you also have to think about things like Bindings support and Key Value Observing which would be much much harder to implement in the CLR.

lfalin
regarding the last paragraph, hopefully it would be a Cocoa-like wrapper over WPF's data binding system and INotifyPropertyChanged.
Jimmy
A: 

As others have said, yes it's possible. Whether it's a good idea (esp. "in the spirit of cross platform development") is another matter. Again, as has been noted, the language is not much without its libraries. Since Objective C is now used almost exclusively within a Mac/ iPhone context, being able to write code in it on Windows is not going to buy you much if they are your targets.

Furthermore, you can write Objective C on Windows already - I believe gcc, which is typically used with XCode, will compiler Obj C on Windows too, as well as GnuStep.

Which just leaves whether there is an advantage to running Objective C over .Net? There are some nice features of Objective C that are not found in your typical .Net languages. Personally I really like the method name labelling of parameters. However I don't think it's enough to make it worthwhile to bring it over. Most of the things Objective C is good at, C# has it's own solutions to. Now if only they would relent on refusing to implement named arguments...

Phil Nash
A: 

Using NObjective bridge you are able to work with existing Objective-C classes in C# or create new ones. Also after final release of 'Visual Studio 2010' and '.NET 4' I'll add DLR support for NObjective.

Jack