赞 | 0 |
VIP | 2 |
好人卡 | 27 |
积分 | 1 |
经验 | 26327 |
最后登录 | 2019-10-13 |
在线时间 | 953 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 110
- 在线时间
- 953 小时
- 注册时间
- 2007-4-25
- 帖子
- 805
|
各种压力的猫君 发表于 2011-9-19 01:54 ![]()
变量命名不就是英语么 = = b 找你的说法应该改成 “增加键值” “删除键值”…… 不成?
缩进风格的话, ...
又岂单单是英语而已。这段脚本所用单词固然是英语,但其中又有不少缩写,如 packdw 中,dw 即“双字”的缩写,此处若命名为“packdword”或“pack_dword”则单词仍“是英语”,却已与 registry.rb 中命名不同。此一巧。
找你的说法应该改成 “增加键值” “删除键值”…… 不成?
不然,中文命名自来便为众人所不屑。`OpenKey' 是匈牙利命名风格,但 Ruby 编程多用 `_' 分割标识符中单词,至不济也可用 CamelCase 命名为“openKey”,这段脚本恰好便用了匈牙利命名法,此二巧。然顾及 Windows API 函数以匈牙利命名法命名,此处在 Ruby 中也用一致的命名倒也合情合理。
缩进风格的话,咱也是习惯按照默认脚本风格进行缩进的……
缩进风格不仅决定“每加深一代码层级空几格”,亦决定“在代码行过长时如何换行”。仆所言“缩进风格”,是指下端代码的换行方式:- check RegQueryInfoKey.call(hkey, 0, 0, 0, subkeys, maxsubkeylen, 0,
- values, maxvaluenamelen, maxvaluelen, secdescs, wtime)
- [ unpackdw(subkeys), unpackdw(maxsubkeylen), unpackdw(values),
- unpackdw(maxvaluenamelen), unpackdw(maxvaluelen),
- unpackdw(secdescs), unpackqw(wtime) ]
复制代码 此三巧。
此外,check 调用时不加括号,四巧。以空格分离数组元素与 `[' 、`]',五巧。局部变量 `maxsubkeylen' 等以 pre-standard C 命名风格命名,六巧。
不知谁言是?
绝无此事。仆举出代码风格一项,只为一个“巧”字耳。
那是不是以后原创脚本都不能用API了因为API是既有的而且其他人的脚本里有一模一样的调用方法?
不知是谁于何处说过“以后原创脚本都不能用API了”?作如是浅见者,仆欲一见。;P
API 的使用合法性这取决于 API 以何种软件许可发布,用户以何种形式使用 API 。[1] 仆之前曾言道 Ruby 是在部分 GPLv2 + Ruby 许可下发布的软件,其中有明文说明如何进行二次开发是合法的,详见十楼,不再赘述。F/OSS 许可下的 API 只要付出少量的代价(如 copyleft)便能免费使用,但私有(商业)许可下的 API 则需要付费使用,如苹果的 Cocoa API。主楼里在 66RPG 发布脚本的那位作者若是自 Ruby 发布的 registry.rb 中提取了代码,并进行(将 dl 的使用替换为 Win32API 的)二次开发,便算作对源文件的修改而不是原创,故 Ruby 许可的开头条款生效:
You can redistribute it and/or modify it under either the terms of the GPL
version 2 (see the file GPL), or the conditions below: [...]
既然该作者没有以 GPLv2 发布那段脚本,就须得包含 Ruby (1.9.3 之前的版本)发布时附带的条款,即:
1. You may make and give away verbatim copies of the source form of the
software without restriction, provided that you duplicate all of the
original copyright notices and associated disclaimers.
2. You may modify your copy of the software in any way, provided that
you do at least ONE of the following:
a) place your modifications in the Public Domain or otherwise
make them Freely Available, such as by posting said
modifications to Usenet or an equivalent medium, or by allowing
the author to include your modifications in the software.
b) use the modified software only within your corporation or
organization.
c) give non-standard binaries non-standard names, with
instructions on where to get the original software distribution.
d) make other distribution arrangements with the author.
3. You may distribute the software in object code or binary form,
provided that you do at least ONE of the following:
a) distribute the binaries and library files of the software,
together with instructions (in the manual page or equivalent)
on where to get the original distribution.
b) accompany the distribution with the machine-readable source of
the software.
c) give non-standard binaries non-standard names, with
instructions on where to get the original software distribution.
d) make other distribution arrangements with the author.
4. You may modify and include the part of the software into any other
software (possibly commercial). But some files in the distribution
are not written by the author, so that they are not under these terms.
For the list of those files and their copying conditions, see the
file LEGAL.
5. The scripts and library files supplied as input to or produced as
output from the software do not automatically fall under the
copyright of the software, but belong to whomever generated them,
and may be sold commercially, and may be aggregated with this
software.
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.
然作者并未包含任何声明,则有违软件许可。
[...] 因为API是既有的而且其他人的脚本里有一模一样的调用方法?
有一模一样的调用方法并无碍,这属“使用库”,不算修改、二次发行代码。主楼提及的脚本作者乃是以与 Ruby 发行版中相同的代码实现了相同的接口。
[1] 用户若以二进制形式使用 API,便不存在源代码复制的问题。 |
|