What are alternatives to Objective-C for Mac progr

2020-03-01 15:49发布

I've become very comfortable in the world of pointer-free, garbage-collected programming languages. Now I have to write a small Mac component. I've been learning Objective-C, but as I confront the possibility of dangling pointers and the need to manage retain counts, I feel disheartened.

I know that Objective-C now has garbage collection but this only works with Leopard. My component must work with Tiger, too.

I need to access some Cocoa libraries not available to Java, so that rules out my usual weapon of choice.

What are my alternatives? Especially with no explicit pointers and automatic garbage collection.

13条回答
等我变得足够好
2楼-- · 2020-03-01 16:21

You can try PyObjC to write Cocoa apps in python, or MacRuby if you are interested in Ruby.

查看更多
不美不萌又怎样
3楼-- · 2020-03-01 16:29

Look at Python and wxPython (the wxWidgets in Python).

The wxWidgets have a very elegant App-Doc-View application design pattern that's very, very nice. It's not used enough, IMO. I haven't found any wxPython examples of this App-Doc-View example, so you have to use the C examples to reason out how it would work in Python.

I'd post examples, but I haven't got it all working yet, either.

查看更多
叼着烟拽天下
4楼-- · 2020-03-01 16:32

Don't forget that you can use java as well, and i don't mean java-cocoa bridge, i mean actual java.

There's also a package from apple that provides you with access to a couple of osx features as well.

Also to comment on Shem's point, if your targeting osx 10.5 and above, you can take advantage of garbage collection.

查看更多
仙女界的扛把子
5楼-- · 2020-03-01 16:36

If you want lisp syntax then Nu is a lisp implemented on top of Objective-C http://www.programming.nu/

查看更多
Ridiculous、
6楼-- · 2020-03-01 16:37

I'm looking into Mono too. Objective-C is a little too bizarre for me at this point. Too many years doing C/C++, Java, C#, Perl etc. I suppose. All these seem pretty easy to float between. Not so for Objective-C. Love my Mac but afraid it will take too much precious time to master the language.

查看更多
▲ chillily
7楼-- · 2020-03-01 16:38

What do you mean by "component?" Do you mean a chunk of code or a library you are going to hand to other people to link into their apps? If so then it is not realistic to use any of the bridged languages at this time. While a lot of the bridges are very nice, they almost always have complications and issues that most app developers will not be willing to deal with to use a single component, especially if it involves bringing in a substantial runtime.

The bridges are most valuable to bridge other language libraries into your Objective C app. While you can write fairly complete apps using them, doing so often requires a better understanding of Objective C than simply writing an Objective C application, since you need to understand and cope with the language, object model, threading, and memory allocation impedance mismatches that occur.

This is also why many people argue that even if you are quite familiar with a language, trying to learn Cocoa using that language through a bridge is generally more difficult that learning it using Objective C.

Finally, much of the recent support for bridged languages was due to "BridgeSupport," a feature was added in Leopard. Even bridges that predate that have been migrating towards, sometimes in such a way that using the bridged language on Tiger and Leopard can have substantial differences. Also, there is currently no bridge support for iPhone, and most bridged languages will not work on it, if that is an issue.

Ultimately, if you are writing a library that is going to be linked into other apps, you need to run on Tiger and Leopard, and you need to access Cocoa only APIs I think you will find using any non-Objective C solution quite difficult.

查看更多
登录 后发表回答