TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Go for Objective-C developers

53 点作者 mergesort超过 11 年前

6 条评论

pornel超过 11 年前
I don&#x27;t feel like I&#x27;ve learned much about Go from this article.<p><pre><code> make(chan bool, 1) </code></pre> what is that 1 for? Why is it not using constructor sytnax shown earlier? (`Chan{bool}` or `BoolChan{1}`?)<p>`go function` is nice, but in ObjC there&#x27;s `dispatch_async()` and `NSOperationQueue`. Go does some magic with green threads, segmented stacks and whatnot, but the article doesn&#x27;t elaborate.<p>And for an Objective-C developer Go&#x27;s lack of proper interoperability with Cocoa is disappointing:<p><a href="http://stackoverflow.com/questions/6322194/cocoa-bindings-for-the-go-language" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;6322194&#x2F;cocoa-bindings-fo...</a><p>BTW:<p><pre><code> (CGRect){0, 0, 320, 480} </code></pre> is valid in ObjC (doesn&#x27;t apply to classes though).
评论 #7227534 未加载
sdegutis超过 11 年前
&gt; <i>If software development is about reducing mental strain on a programmer, then garbage collection is something that goes a long way to that.</i><p>Go&#x27;s GC has its own caveats that you have to watch out for. It doesn&#x27;t really save you from having to think about your object graph or architecture design.
评论 #7226870 未加载
评论 #7226527 未加载
评论 #7226730 未加载
dengnan超过 11 年前
Before any insightful discussion, may I suggest that we do not discuss generics?
评论 #7226640 未加载
评论 #7226698 未加载
评论 #7227031 未加载
higherpurpose超过 11 年前
Could Go be used to replace Java on Android eventually? If he&#x27;s already comparing it to Objective-C, and since it already has garbage collection, it might not be a terrible idea, and it should make it easier for new programmers wanting to develop for Android, since Go is an easier language to learn than Java and much less verbose.
评论 #7227137 未加载
评论 #7227345 未加载
评论 #7227656 未加载
jamieomatthews超过 11 年前
Great article! I&#x27;d like to see a part 2 to this article where you go a bit more in depth into some differences, with examples of both golang code and objectiv-c code. Thanks!
gilgoomesh超过 11 年前
As an Objective-C developer, I simply don&#x27;t think Go solves the same problems as Objective-C – comparing the two seems very apples and oranges to me. If I ever start using Go, it won&#x27;t be as a direct replacement for Objective-C.<p>I don&#x27;t mean to attack the author (I enjoyed the article) but most of Go&#x27;s &quot;advantages&quot; are also disadvantages when used in an Objective-C&#x2F;Cocoa environment.<p><i>First heading from the article: &quot;Not traditionally object-oriented&quot;</i><p>The problem with this is that much of Objective-C is focussed on the AppKit&#x2F;UIKit view-hierarchy. As the Rust developers noticed when trying to implement the HTML DOM in their Servo project, large hierarchies of similar entities are cumbersome and require repeating yourself often if you don&#x27;t have access to traditional subclasses. Rust eventually added single inheritance (despite earlier pushing for a purely Go-like compositional interface approach).<p>Compositional interfaces are a good thing... but so is data and behavioral inheritance. Taking one of these things away makes the language poorer, not richer. Yes, compositional interfaces would be good in Objective-C but a lack of inheritance in Go isn&#x27;t a perfect world either.<p><i>Second heading from the article: &quot;Type inference&quot;</i><p>For the mostpart, this is a point in Go&#x27;s favor. Although the author might not realise that with ARC in Objective-C you can actually just duck type if you want (type as &#x27;id&#x27;) and the ARC compiler will do type inference behind your back to track memory so you still get all the compile-time checks and other type inference advantages<p><i>Third heading from the article: &quot;Garbage collecting&quot;</i><p>Ignoring the technical problems with Apple&#x27;s GC implementation for Objective-C, there were three real reasons why garbage collection sucked badly: (1) it used too much RAM (standard GC drawback), (2) it was slow (because it used too much RAM – it was otherwise efficient), but most critically: (3) it removed deterministic deletion which is critical in Cocoa.<p>Cocoa relies on its destructors to perform actual work. With GC, you suddenly can&#x27;t rely on destructors being invoked when you need them. The idea that GC &quot;reduc[es] mental strain&quot; does not apply if instead of transparent lifecycle management with ARC, you suddenly need completely manual &quot;dispose&quot; methods everywhere.<p><i>Fourth heading from the article: &quot;Native concurrency&quot;</i><p>Apple&#x27;s approach to native concurrency is that you should use libdispatch. It&#x27;s slightly more verbose than prefixing a function with &quot;go&quot; but it handles all that go&#x27;s built-in concurrency handles and actually much more. I think, from its exclusion, that the author is unfamiliar with libdispatch. I&#x27;ve not seen evidence that go has any built in advantages over libdispatch.<p><i>Fifth heading from the article: &quot;Packages&quot;</i><p>On namespaces: yes, they allow for ways around conflicts. But there is a double edged sword here: names in different namespaces are going to conflict. If you&#x27;ve used a large library like .NET, you&#x27;ll know what I mean: lots of different classes in different namespaces conflict so that you can&#x27;t simply say &quot;using XXX&quot; for each namespace and instead you have to reference the whole path. Instead of NSTimer you have to use System.Timers.Timer or System.Threading.Timer – a two letter prefix is now fourteen or seventeen letters.<p>Also... it is <i>really</i> annoying attempting to follow sample code when the sample code omits all the namespace inclusions. You&#x27;re trying to learn the API from the code but the code doesn&#x27;t explain what API it&#x27;s using forcing you to trial and error hunt around for the correct namespace.
评论 #7228629 未加载
评论 #7228377 未加载