瞎扯淡 Apple 的工具居然有用 Ruby 写的

donghua · 2015年01月11日 · 最后由 Numbcoder 回复于 2015年01月12日 · 2890 次阅读

最近在看 Mac OS X and iOS Internals,发现 Apple 的工具居然有用 Ruby 写的。文件在:/usr/libexec/AppSandbox/container_check.rb(OSX 10.9 以上)

#!/usr/bin/env ruby
#
# Copyright (c) 2011 Apple Inc. All rights reserved.
#
# @APPLE_LICENSE_HEADER_START@
#
# This file contains Original Code and/or Modifications of Original Code
# as defined in and that are subject to the Apple Public Source License
# Version 2.0 (the 'License'). You may not use this file except in
# compliance with the License. Please obtain a copy of the License at
# http://www.opensource.apple.com/apsl/ and read it before using this
# file.
#
# The Original Code and all software distributed under the License are
# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
# Please see the License for the specific language governing rights and
# limitations under the License.
#
# @APPLE_LICENSE_HEADER_END@
#

ENV["PATH"] = "/bin:/usr/bin:/usr/sbin"

require 'ostruct'
require 'pp'
require 'optparse'
require 'tempfile'
require 'find'


class ContainerChecker
    def initialize(home, output, outIO)
        @homeDirPath = home
        @fulloutput = output
        @containerPath = File.join(@homeDirPath, "Library", "Containers")
        @outputIO = outIO
    end
# 下略

Ruby 万歳!

会不会是实习生写的?

四格缩进,打回重写

命名规则不 ruby,打回重写。

#2 楼 @blacktulip #3 楼 @realwol 这个只是一个社区的建议规范,我写 js 还用 output_io 命名。缩进和命名都是看个人或者团队。

apple 里与偶好多是 ruby 写的,比如 mdm 协议给的 demo 就是 ruby 的

#4 楼 @flowerwrong :plus1: 个人只要一致就 ok 了,团队合作,就按照团队要求来。

伯克利的教材,js 也是下划线命名。

#6 楼 @yfractal #4 楼 @flowerwrong 我一直也是这样的。写 ios,写 coffee,node 都是这样,很爽

applie 还用 lisp(scheme) 呢:

/usr/share/sandbox/ftp-proxy.sb

;;
;; ftp proxy - sandbox profile
;; Copyright (c) 2010 Apple Inc.  All Rights reserved.
;;
;; WARNING: The sandbox rules in this file currently constitute 
;; Apple System Private Interface and are subject to change at any time and
;; without notice. The contents of this file are also auto-generated and not                                            
;; user editable; it may be overwritten at any time.
;;
(version 1)

(deny default)

(import "system.sb")

(allow ipc-posix-shm
    (ipc-posix-name "apple.shm.notification_center"))

(allow mach-lookup
       (global-name "com.apple.networkd")
       (global-name "com.apple.NetworkSharing")
       (global-name "com.apple.pfd"))

(allow mach-per-user-lookup)

(system-network)
(allow network* (local ip))

(allow system-socket)

会 lisp 可以自己写一些 profile 来跑那些不是很信任的程序。

#4 楼 @flowerwrong 起码应该团队点,个人的习惯如果跟团队不一致,很容易造成额外开销。当然一个语言的统一风格也自然大家都总结起来的,多少是有优点的。

难道你们忘了还有个 MacRuby 嘛?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号