What will it take to add Objective-C support to the .NET common language runtime?

时光毁灭记忆、已成空白 提交于 2019-12-09 08:28:37

问题


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:


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.




回答2:


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




回答3:


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:

  • Core Data
  • Core Audio
  • Quartz
  • Core Animation

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.




回答4:


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.




回答5:


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...




回答6:


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.




回答7:


What about Objective-J and Cappuccino for .Net, rather than Objective-C and Cocoa? Objective-J is just as appealing as ObjC, however, ObjJ is closer to C# than ObjC (no pointers, gc, etc.)

I recently asked about this on the Cappuccino developers forum, and they pointed me towards Jurassic (a Javascript compiler for .Net). They also said that Cappuccino works fine on IronJS. So, it looks like the components are there (ObjJ -> Javascript -> .Net), but the bridge linking them together has to be built.

Does anyone else see any value in this?



来源:https://stackoverflow.com/questions/245721/what-will-it-take-to-add-objective-c-support-to-the-net-common-language-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!