什么是“最佳实践”?在 Smalltalk 中使用 Symbol 的便携方式?
以可移植方式在 Smalltalk 中使用符号的“最佳实践”规则是什么?我主要使用 squeak 和 pharo,我知道它们都允许 'foo' = #foo 和 #foo = 'foo' 为真,而其他 Smalltalks 则不允许。我知道符号用于识别,不应该用来代替字符串。但是,至少可以安全地假设符号对象是一个可以发送诸如 copyWith: 或 do: 之类的消息的集合,还是必须先将其转换为某种集合?
任何建议将不胜感激。
What are the "best practice" rules for using symbols in Smalltalk in a portable way? I use squeak and pharo mainly and I know they both allow 'foo' = #foo and #foo = 'foo' to be true while other Smalltalks don't. I understand Symbols are for identification and shouldn't be used in place of strings. But is it at least safe to assume that a symbol object is a collection that can be sent messages like copyWith: or do:, or must you convert it some kind of Collection first?
Any advice would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们在 Seaside 中遵循的规则是不要混合符号和字符串。这样你就可以避免这个问题。并非在所有平台上符号都是 String 的子类,因此您必须小心使用 #copyWith: 或 #do:。
我仅将符号用作与其他符号进行比较的廉价标记。我不会将符号用于其他用途。
The rule we follow with Seaside is not to mix Symbols and Strings. Like this you avoid the problem. Not on all platforms a symbol is a subclass of String, so you have to be careful with #copyWith: or #do:.
I use symbols only as a cheap token that you compare with other symbols. I wouldn't use symbols for anything else.