tag:blogger.com,1999:blog-34927953.post4032710692682806518..comments2023-07-09T02:39:33.734-07:00Comments on Jack Cough on Software: Comedy: Scala vs. Ruby vs. Objective CJosh Coughhttp://www.blogger.com/profile/04509343962912103631noreply@blogger.comBlogger24125tag:blogger.com,1999:blog-34927953.post-33897734529482349412012-08-15T11:44:56.896-07:002012-08-15T11:44:56.896-07:00I'll be necromancer of the year for this. But ...I'll be necromancer of the year for this. But anyway, with Apple now using LLVM 4.0 and introducing what they call "Modern Objective-C", this is how the example looks like in Objective-C instead: (@[] array literal, @{key :value} dictionary literal.)<br /><br /><br />self.computers = @[<br />@{ @"Name" : @"MacBook", @"Color" : @"White" },<br />@{ @"Name" : @"MacBook Pro", @"Color" : @"Silver" },<br />@{ @"Name" : @"iMac", @"Color" : @"White" }];<br /><br />As many lines as Ruby/Scala example ;) // ObjC and Ruby developerRoberthttps://www.blogger.com/profile/09904586713017614662noreply@blogger.comtag:blogger.com,1999:blog-34927953.post-64474035024925230232012-08-15T11:39:27.843-07:002012-08-15T11:39:27.843-07:00This comment has been removed by the author.Roberthttps://www.blogger.com/profile/09904586713017614662noreply@blogger.comtag:blogger.com,1999:blog-34927953.post-20609088195894105762011-08-24T08:09:19.699-07:002011-08-24T08:09:19.699-07:00@Jack: I think they are professional technical wri...@Jack: I think they are professional technical writers who have a shallow knowledge of the language and write books with broken code. And yes Objective-C is verbose :)<br /><br />@Rob: I also think that the releases are unnecessary and could lead to a BAD ACCESS error.Leo Gomesnoreply@blogger.comtag:blogger.com,1999:blog-34927953.post-61931983946287129122009-11-17T16:13:23.891-08:002009-11-17T16:13:23.891-08:00dictionaryWithObjectsAndKeys: and arrayWithObjects...dictionaryWithObjectsAndKeys: and arrayWithObjects: both return autoreleased objects. Releasing them would mess up the retain counts, correct?Unknownhttps://www.blogger.com/profile/09369544634982289924noreply@blogger.comtag:blogger.com,1999:blog-34927953.post-17122688413185729542009-07-29T06:49:50.312-07:002009-07-29T06:49:50.312-07:00its not pointless. first, its supposed to be funny...its not pointless. first, its supposed to be funny. since its funny to me, point achieved. <br /><br />second, i took that code directly from Beginning IPhone Development, which brings up a few questions. since there are clearly easier ways to do it in obj-c, why would they use the horrifying code instead? are they trying to scare people away? maybe obj-c just needs a good publicist.Josh Coughhttps://www.blogger.com/profile/04509343962912103631noreply@blogger.comtag:blogger.com,1999:blog-34927953.post-65266841186899424672009-07-29T03:39:24.332-07:002009-07-29T03:39:24.332-07:00or why not change the obj-c to
self.computers = [...or why not change the obj-c to <br />self.computers = [NSArray arrayWithObjects: <br />[NSDictionary dictionaryWithObjectsAndKeys: @"MacBook", @"Name", @"White", @"Color", nil], <br />[NSDictionary dictionaryWithObjectsAndKeys: @"MacBook Pro", @"Name", @"Silver", @"Color", nil], <br />[NSDictionary dictionaryWithObjectsAndKeys: @"iMac", @"Name", @"White", @"Color", nil], nil]];<br /><br />oh wait, because then this page would be pointless.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-34927953.post-61672559207604046692009-06-03T05:47:36.791-07:002009-06-03T05:47:36.791-07:00Haskell:
import Data.Map
computers = [fromList [(&...Haskell:<br />import Data.Map<br />computers = [fromList [("name", "MacBook"), ("color", "white")],<br />fromList [("name", "MacBook Pro"), ("color", "silver")],<br /> fromList [("name", "iMac"), ("color", "white")]]Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-34927953.post-63091118778629476902009-06-02T21:43:24.584-07:002009-06-02T21:43:24.584-07:00>> F# uses semi-colons for delimiters and no...>> F# uses semi-colons for delimiters and not commas?<br />Yes. Commas for tuples, semi-colons for list and array itemsmehdi.asgarihttps://www.blogger.com/profile/06255493606782049656noreply@blogger.comtag:blogger.com,1999:blog-34927953.post-78901008083224642372009-06-02T14:37:23.734-07:002009-06-02T14:37:23.734-07:00of course you have to correctly indent the python ...of course you have to correctly indent the python code :-DVictor Hogemannhttps://www.blogger.com/profile/10776588527172796582noreply@blogger.comtag:blogger.com,1999:blog-34927953.post-63379947298119671712009-06-02T14:35:16.853-07:002009-06-02T14:35:16.853-07:00Python,
computers = [
{"Name":"MacBook","Color":"...Python,<br /><br />computers = [<br />{"Name":"MacBook","Color":"White"},<br />{"Name":"MacBook Pro","Color":"Silver"},<br />{"Name":"iMac","Color":"White"}]Victor Hogemannhttps://www.blogger.com/profile/10776588527172796582noreply@blogger.comtag:blogger.com,1999:blog-34927953.post-10620174768937395042009-06-02T09:45:48.841-07:002009-06-02T09:45:48.841-07:00nice comparison, gives feel of a unified world :)nice comparison, gives feel of a unified world :)Monis Iqbalhttps://www.blogger.com/profile/02705136015120934248noreply@blogger.comtag:blogger.com,1999:blog-34927953.post-59083584407719058252009-06-02T09:09:00.538-07:002009-06-02T09:09:00.538-07:00F# uses semi-colons for delimiters and not commas?...F# uses semi-colons for delimiters and not commas?Josh Coughhttps://www.blogger.com/profile/04509343962912103631noreply@blogger.comtag:blogger.com,1999:blog-34927953.post-83593525748297559382009-06-02T03:37:23.186-07:002009-06-02T03:37:23.186-07:00The hip languages all use the same ammount of line...The hip languages all use the same ammount of lines. Cool!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-34927953.post-77711208121156539972009-06-02T03:19:09.269-07:002009-06-02T03:19:09.269-07:00Groovy:
this.computers = [
[Name: "MacBook", Colo...Groovy:<br /><br />this.computers = [<br />[Name: "MacBook", Color: "White"],<br />[Name: "MacBook Pro", Color: "Silver"],<br />[Name: "iMac", Color: "White"]]Scot McSweeney-Robertshttps://www.blogger.com/profile/05078277004789544258noreply@blogger.comtag:blogger.com,1999:blog-34927953.post-24420978480759255812009-06-01T21:34:52.197-07:002009-06-01T21:34:52.197-07:00F# :
let this.computers <- [|
...F# :<br /><br />let this.computers <- [| <br /> Map[("Name", "MacBook"); ("Color","White")];<br /> Map[("Name", "MacBook Pro"); ("Color","Silver")];<br /> Map[("Name", "iMac"); ("Color","White")] |]mehdi.asgarihttps://www.blogger.com/profile/06255493606782049656noreply@blogger.comtag:blogger.com,1999:blog-34927953.post-52769910620026242142009-06-01T20:37:02.589-07:002009-06-01T20:37:02.589-07:00I accidentally left out the color of MacBook.I accidentally left out the color of MacBook.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-34927953.post-72494692189450757522009-06-01T15:52:45.055-07:002009-06-01T15:52:45.055-07:00Actually you could change the Obj-C to:
NSDiction...Actually you could change the Obj-C to:<br /><br />NSDictionary *row1 = [NSDictionary dictionaryWithObjectsAndKeys: @"MacBook", @"Name", @"White", @"Color", nil];<br />NSDictionary *row2 = [NSDictionary dictionaryWithObjectsAndKeys: @"MacBook Pro", @"Name", @"Silver", @"Color", nil];<br />NSDictionary *row3 = [NSDictionary dictionaryWithObjectsAndKeys: @"iMac", @"Name", @"White", @"Color", nil];<br /><br />[self setComputers:[NSArray arrayWithObjects: row1, row2, row3, nil]];Martin Pilkingtonhttp://www.mcubedsw.comnoreply@blogger.comtag:blogger.com,1999:blog-34927953.post-29289547391140711542009-06-01T15:21:18.437-07:002009-06-01T15:21:18.437-07:00What is the color of the first MacBook of Clojure ...What is the color of the first MacBook of Clojure example ?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-34927953.post-14135672205424833242009-06-01T12:05:50.477-07:002009-06-01T12:05:50.477-07:00No no! Not at all :)
I was just wondering, my Rub...No no! Not at all :)<br /><br />I was just wondering, my Ruby knowledge is close to zero and I've always wondered myself why and where to use symbols in Scala. This seems like a good example.... (although the advantages of using symbols here are not really vlear... maybe because this way you make it explicit that the keys all refer to the same thing?)Anonymoushttps://www.blogger.com/profile/08969133867152074451noreply@blogger.comtag:blogger.com,1999:blog-34927953.post-59543806901739940052009-06-01T11:59:04.176-07:002009-06-01T11:59:04.176-07:00You're not wrong. The original version was actuall...You're not wrong. The original version was actually the objective c, which inspired me to write this because I found it comical. <br /><br />In Ruby, symbols for hash keys are far more common than in Scala, so I didn't use symbols for Scala. However, if you feel strongly about it, I'll change it (since I don't).Josh Coughhttps://www.blogger.com/profile/04509343962912103631noreply@blogger.comtag:blogger.com,1999:blog-34927953.post-69676874282920401412009-06-01T11:54:36.650-07:002009-06-01T11:54:36.650-07:00Actually I think the Ruby version is more similar ...Actually I think the Ruby version is more similar to this Scala version, am I right?<br /><br />this.computers = Array(<br />Map('Name -> "MacBook", 'Color->"White"),<br />Map('Name -> "MacBook Pro", 'Color->"Silver"),<br />Map('Name -> "iMac", 'Color->"White"))Anonymoushttps://www.blogger.com/profile/08969133867152074451noreply@blogger.comtag:blogger.com,1999:blog-34927953.post-34427026094429725752009-06-01T11:53:42.748-07:002009-06-01T11:53:42.748-07:00This comment has been removed by the author.Anonymoushttps://www.blogger.com/profile/08969133867152074451noreply@blogger.comtag:blogger.com,1999:blog-34927953.post-41332394217391456922009-06-01T09:33:19.483-07:002009-06-01T09:33:19.483-07:00Clojure:
(def computers [{:Name "MacBook"} {:Name...Clojure:<br /><br />(def computers [{:Name "MacBook"} {:Name "MacBook Pro" :Color "Silver"} {:Name "iMac" :Color "White"}])Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-34927953.post-50693912885003944682009-06-01T09:28:32.367-07:002009-06-01T09:28:32.367-07:00js
this.computers =
[{'name':'MacBook', ...js<br /><br /> this.computers = <br /> [{'name':'MacBook', 'color':'White'},<br /> {'name':'MacBook Pro', 'color':'Silver'}, <br /> {'name':'iMac', 'color':'White'}];<br /><br />-mfogushttp://fogus.menoreply@blogger.com