@
smdxex 再举个栗子好了,假设有如下的本地变量和类型:
Gamedata = {Mob, Persons}
Person = {HP, MP, Money, Bag}
Bag = [Items]
Item = [Name, Count]
现在要找出所有身上带着至少 5 个大师球的所有玩家。
你眼中别的程序员的代码:
MatchedPersons = []
for i = 1 to Gamedata.Persons.size
..person = Gamedata.Persons[i]
..items = person.Bag
..count = 0
..for j = 1 to items.size
....item = items[j]
....if
item.Name == '大师球'
......count = item.Count
..if count >= 5
....MatchedPersons += person
你眼中的代码:
SELECT DISTINCT Persons FROM Gamedata.Persons JOIN Items
WHERE
Persons.id = Items.person_id AND
Item.Name = '大师球' AND Item.Count > 5
别人眼中的代码:
Gamedata.Persons.select { |p| p.Bag.any? { |i|
i.name == '大师球' && i.count > 5= } }
如果你没听说过,那就去听说一下呗……