(Highly geeky post ahead. You’ve been warned!)
I have found the very message that summarizes the beauty of Cocoa in a single word; see by yourselves, hereunder in line 47:
“The four magic constants of the apocalypse: Nothing, Null, Empty, and Error.” Verity Stob
4 Comments
#1. Paul Barry 07.08.2008
class Person
attr_accessor :first_name, :last_name, :age
def to_s
“Name: #{first_name} #{last_name}, #{age} years old”
end
end
map = {”first_name”=>”Teto”, “last_name”=>”Rodriguez”, “age”=>34}
puts map.inject(Person.new){|p,(k,v)| p.send “#{k}=”, v; p}
#2. Adrian 07.08.2008
Thanks for your comment Paul! I still prefer the ObjC version though :)
#3. Paul Barry 07.08.2008
Seriously? You prefer 53 lines of code over 9? And consider that this is doing it the “hard way”. You can easily hide away the complexity of the last two lines in the Ruby way and make it part of the object’s constructor, as is done in Rails:
Person.new(:first_name => “Teto”, :last_name => “Rodriguez”, :age => 34)
I don’t see how it could get anymore beautiful than that. I agree that compared to C, ObjC is beautiful, but there’s too much line noise in ObjC:
Person* person = [[[Person alloc] init] autorelease];
When compared to Ruby:
Person.new
#4. Adrian 07.08.2008
OK, let’s put things in context. Ruby is Ruby, and I love it for what I can do with it in Rails. The “level of noise” is purely subjective, as you can have an even shorter variant “Person()” in Python… I think that, as a compiled language, ObjC does great things, and it provides a level of flexibility that other similar languages (C++, to name its closest cousin) do not offer.
Not to mention speed of execution.
And by the way, the original comment was about the “beauty of Cocoa” and not of ObjC specifically ;)
Thanks for your input!
Commenting