C语言的'块'除了它自己是一级作用域之外和普通的代码没有区别。
至于Ruby的'块',你确定你学过Ruby?
Ruby的'块'比较复杂,简单来说,你可以认为它等同于C语言的函数,而不只是一个C语言的‘块’。
关于 RubyMotion 我已经写过很多文章了,但如何混用Objective-C与Ruby还从未涉及到。实际上你能在RubyMotion项目中使用Objective-C代码,也可以在传统Objective-C的App中使用Ruby代码。也许你一次听来觉得像黑魔法一样,所以来一起看看下面这些示例。Objective-C in Ruby
很多iOS开发者在现有的Objecive-C代码中存在大量深层的备份日志,这样就为项目手动转换为 RubyMotion 带来了很大的痛苦。然而幸运的是现在仅仅只需要将编译好的Objective-C代码添加到我们的新RubyMotion应用里。
比如我们要在 RubyMotion 应用中使用 Objective-C 形式的 CYAlert 类:
// CYAlert.h
#import <UIKit/UIKit.h>@interface CYAlert : NSObject
+ (void)show@end
// CYAlert.m
#import "CYAlert.h"
@implementation CYAlert
+ (void)show {
UIAlertView *alert = [[UIAlertView alloc] init]
alert.title = @"This is Objective-C"
alert.message = @"Mixing and matching!"
[alert addButtonWithTitle:@"OK"]
[alert show]
[alert release]
}@end
为了在RubyMotion应用中能正常使用,这里需要将CYAlert的两个文件都放置到类似 ./vendor/CYAlert 里面,然后在 Rakefile: 中告诉 RubyMotion 使用vendor_project创建那个文件夹。
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'MixingExample'
# ./vendor/CYAlert contains CYAlert.h and CYAlert.m
app.vendor_project('vendor/CYAlert', :static)
end
那么现在在 AppDelegate 中,我们这样使用 CYAlert:
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
CYAlert.show
true
end
end
Python与Java的区别学习起来Python要比Java简单快速的多,java从c++这样的系统语言中继承了很多语法和复杂性,而Python的语法非常简洁,大大提高编写效率。
Python与C#语言的区别
Python是解释型语言,不需要额外的编译过程,而C#必须编译后执行。另外,Python程序全部是开源的,但是C#就不是了,Python程序可以跨平台,不需要修改就可以运行在Windows和Linux等系统平台。
Python &C++,Perl
Python比C++等这类语言,更容易学习,语法规则简单,语意化,易读易懂,容易维护。
Python &Ruby
Python与Ruby确实有些相似,但是前者比后者更加成熟,语法的可读性是后者没法比的。与Ruby和Java不同的是,面向对象编程在python里不是必选的,这就更加增加了这门语言的灵活性。Ruby语言只适合编写,但是维护的时候你会非常头疼,更不用说多人编写和维护的项目代码了。