Is Ruby or Python not suitable for iPhone or Mac app development because of speed, and any compiler that can help boost the speed? [closed]
I am reading a little bit on Objective-C, and since it comes from Smalltalk, like Ruby does,开发者_开发技巧 so I wonder, is it true that if using Ruby, (if Apple change XCode to support it), to develop iPhone or Mac app, it is not suitable really because of the speed? For example, Angry Birds probably isn't as smooth as it is now if using Ruby, vs if Objective-C, it is compiled and running as machine code.
But currently, is there any way of compiling Ruby or Python code into machine code so that it is running in the similar speed zone as Objective-C programs can?
On desktop those are fine languages to use, and for Python you could use py2app to deploy your app. You wouldn't want to write low-level graphics routines in an interpreted language, but that's what libraries like PyGame are for.
(Not that this is a particular advantage, but note that one of the most popular 2D game frameworks on iOS is a port of a 2D game framework for Python: http://cocos2d.org/ )
Until recently the iOS developer terms specifically disallowed running an interpreter, so nobody used Ruby or Python on iPhone. Apps programmed in those languages will probably start showing up, but you won't find much about that just yet.
Ruby/Python can be fast enough for Mac and even iOS development. It depends on performance requirements for your applications. It should be acceptable for most use cases.
Apple is developing Ruby implementation specifically targeted for Mac application development - MacRuby. Another option would be to use RhoMobile, a mobile development framework using Ruby. Also OS X is bundled with Python and PyObjC library by default, which enables developing cocoa applications with python.
Possible ways to speed up your Python applications:
- Use Cython. A python-like language, that compiles to c, to ease interoperability with c code.
- Use Pyrex or Shedskin. The former compiles a subset of python to C, the latter to C++.
- Use PyPy or Psyco. Both compile Python code to machine code on the fly.
For Ruby you might want to look at Rubinius - Ruby implementation that compiles to native code on the fly.
Python and Ruby themselves are not too fast, but many programs today are written to basically do none of the heavy lifting alone. For instance, if you want to save a PNG file as a JPG, you are certainly going to use the built in system calls to do it. In that case it does not really matter if it takes 0.00001 seconds in Obj-C, or 0.001 seconds in Python to process the mouse click, when the optimized system code to convert the image is the exact same code in both programs, and takes, say 1/2 a second to run. On the other hand if you are making a low level data munger of your own design, then you might want some C. Basically all languages that you would use on a Mac allow you to write something in C, and call it from that language, so even that does not slow you down.
Pick the language for the task based usually on what everyone else is doing for that problem, intersected with your abilities.
精彩评论