News for hackers. Stuff that matters.
Re:Go for Objective-C developers by sdegutis on Wednesday February 12, 2014 @02:05PM (#7226495)
> If software development is about reducing mental strain on a programmer, then garbage collection is something that goes a long way to that.

Go's GC has its own caveats that you have to watch out for. It doesn't really save you from having to think about your object graph or architecture design.

Re:Go for Objective-C developers by Moto7451 on Wednesday February 12, 2014 @02:57PM (#7226870)
I thought the GC point was kind of interesting seeing as Objective C does/did have Garbage Collection (if you're an OS X developer). It's been deprecated and ARC is the replacement. There's been a bit of discussion about this in the past. Maybe if the first iPhone had come with the same hardware we're looking at today the story would be different but I tend to agree with the reasoning behind not supporting GC on iDevices. I feel like the hoops (some types of) Game developers have to jump through on Android even with todays hardware is validation of Apple's reasoning.

http://www.cocoabuilder.com/archive/xcode/322876-why-arc-ove...

http://daringfireball.net/linked/2011/09/19/the-unfamiliar

http://stackoverflow.com/questions/2484079/how-can-i-avoid-g...

Re:Go for Objective-C developers by pjmlp on Wednesday February 12, 2014 @04:06PM (#7227295)
Apple failed to develop a stable GC for Objective-C, there were lots of issues when linking with libraries that did not make use of it.

Plus the underlying C part, didn't allow for more than a plain conservative GC.

ARC works by generating the retain/release calls the developers would write anyway with NeXTStep/Cocoa framework.

So while it is a good solution for Objective-C, it isn't because it thrumps GC, but rather due to Apple's failure with a stable GC.

Re:Go for Objective-C developers by mpweiher on Wednesday February 12, 2014 @05:15PM (#7227731)
The failure to develop a stable and performant GC is part of the reason. Another part is that such a GC is very difficult for C/Objective-C (one could say impossible or close enough to it as to not make a difference).

However, that's not all of it. The iOS teams wouldn't touch the GC with a 10 foot pole, even had it worked, and with good reason. As the parent poster pointed out, GCs make performance and memory consumption unpredictable, especially on memory-constrained devices.

And yes, phones are memory-constrained, despite the 1/2 - 1GB of memory, because you are also managing some potentially very large assets (retina class images, ...). Especially without virtual memory, where having an unexpected spike in memory consumption can get you killed, having unpredictable memory consumption is a non-starter...and the pain you have to go through on Android to avoid GC problems is significant (for example real-time OCR via the video camera overlaid onto the video stream).

It's interesting that Android appears to be moving away from JIT to AOT with libart, I am very curious as to how that works out. My guess is that at least a subset of developers, those with stringent requirements, would also welcome more predictable memory management solution.

Re:Go for Objective-C developers by pjmlp on Thursday February 13, 2014 @03:12AM (#7230098)
True, although WP doesn't not seem to have the performance issues of Android.

WP7 was full .NET with JIT.

WP8 is WinRT/.NET with AOT compilation.

Both seem to perform much better than Android and on par with iOS.

Although I do conceded that on WP8 there is a mix of reference counting(WinRT) and GC (.NET).

Google was supposed to present more information about ART at FOSDEM, but they canceled the presentation on the last minute. So still no information what they plan there, besides AOSP source code.

Xerox PARC systems already had GC enabled programming languages (Cedar/Lisp/Smalltalk) and they surely were less powerful than today's phones.

Re:Go for Objective-C developers by sdegutis on Wednesday February 12, 2014 @04:13PM (#7227368)
I would argue a step further and say that it's because Apple chose the wrong solution for an OOP language with C-compatibility. They could have invented a language more like C# for NeXTSTEP, but they chose the route with easier C compatibility. Now they're paying the cost of taking that early shortcut.
Re:Go for Objective-C developers by comex on Wednesday February 12, 2014 @04:29PM (#7227469)
It goes both ways - they're still reaping the benefits of making it very easy to interface with low-level native code, too (plus sidestepping GC variability).
Re:Go for Objective-C developers by Moto7451 on Wednesday February 12, 2014 @08:21PM (#7228727)
Given the development timeframe for NeXTSTEP, I don't think that a managed language would have been a likely choice. Remember, this is when your average barn burner workstation came with a 33MHz 386 Class CPU and 4-8MB of memory. The NeXT Computer came with a 25MHz '030 and 8MB of memory.
Re:Go for Objective-C developers by pjmlp on Thursday February 13, 2014 @02:44AM (#7230033)
They could, as Xerox PARC machines were not as powerful and offered:

- Lisp OS

- Smalltalk OS

- Mesa/Cedar (a GC enabled systems programming)

Re:Go for Objective-C developers by Touche on Wednesday February 12, 2014 @04:56PM (#7227624)
They still can. All of their competitors are constantly researching new languages but we never hear a peep of any of that from Apple. Presumably the design-driven culture prevents big projects like a new language from ever getting anywhere.
Re:Go for Objective-C developers by sdegutis on Wednesday February 12, 2014 @05:34PM (#7227854)
They're making pretty significant advances with Clang and LLVM and have pretty much caught up to GCC in performance and surpassed it in usability. So they're not doing nothing, for sure. But they're pouring all that effort into Objective-C, which will still has the inherent problem of C compatibility. Granted it's evolving (i.e @import), but it can only go so far without breaking compatibility completely like C# did.
Re:Go for Objective-C developers by Touche on Wednesday February 12, 2014 @06:27PM (#7228193)
I'm talking about language design. Clang and LLVM are not languages (well, not user-written languages).
Re:Go for Objective-C developers by sdegutis on Wednesday February 12, 2014 @06:39PM (#7228259)
So then I think we're on the same page: Apple's putting their money into just tooling rather than language design plus tooling.
Re:Go for Objective-C developers by d0 on Wednesday February 12, 2014 @02:10PM (#7226527)
This is true of GC in all languages.

Many a time I've seen people shrug off issues as "GC will handle it" in C# projects. Usually accompanied with the sound of many a developer crying whilst trying to work out what has gone wrong in production when 256Gb of RAM across several nodes disappears instantly. Memory ballooning, long GC pauses, reference leaks, swapping, VM over commitment are all waiting to hang you.

Re:Go for Objective-C developers by jamra on Wednesday February 12, 2014 @02:37PM (#7226730)
Can you link to any article about this? I haven't been able to find a good read on this subject.
Re:Go for Objective-C developers by aaronblohowiak on Wednesday February 12, 2014 @02:43PM (#7226772)
if you have a very large slice of Structs and then you end up with only a pointer to one of the Structs, the entire slice will be retained. This is also true for slices of Byte.

For non-gophers, a slice is roughly a bounds-checked Vector.

Re:Go for Objective-C developers by jamra on Wednesday February 12, 2014 @02:56PM (#7226856)
I get the idea, but I am wondering more on what kind of code will cause too much data to be retained and how to code around it.

What you just described is how memory is allocated, but can this cause it to be retained outside a function body?

Re:Go for Objective-C developers by Someone on Wednesday February 12, 2014 @04:19PM (#7227404)
A typical use case in Java is/was (1) reading a huge file line by line or parsing it as XML, and filtering it. Java's substring is like go's slices in that it is constant-time, but retains the entire string. Consequently, your code that filters out 1‰ of a 1GB XML file may keep hold of the entire file's content.

In Java, you code around it by doing

   new String( line.substring( x, y);
String's constructor will copy the characters to a new buffer. I guess go will have something similar. Problem, of course, is that that means copying the objects. That can especially be an issue if the objects are mutable.

An alternative in Java is to do

    s = s.intern();
But that comes with its own problems. 'intern()' decreases memory usage, but is slow, and library writers cannot know whether it is a good idea to use it or not because they cannot know what is more important to the code calling the library: speed or memory.

(1) Oracle is going to change/has changed this after measuring its impact. It turns out that the two extra fields that each string needs to keep track of what part of a buffer contains its characters more or less compensate for the decrease in memory usage that sharing strings brings.

Re:Go for Objective-C developers by MBCook on Wednesday February 12, 2014 @09:24PM (#7228934)
Interning had other problems. Until some of the more recent JVMs, interning strings was permenant. The memory could never be reclaimed until you restarted the JVM. It was basically a programmer defined memory leak.

Why? My understanding is that when you interned a string you were given something like a constant token to reference it. This did two things:

1. Equality was trivial. Instead of taking to strings and comparing each character, it could just see if the constants were equal. For strings you know you'll see often this could be great source of speedups. 2. You could end up saving a ton of memory. Let's say that string you're interning is 250 character long. Instead of taking up 250 unicode characters plus overhead, it's now... let's say... 8 bytes. Maybe you saved a few hundred bytes. Now multiply a few hundred bytes by a few fields times 10 million records in memory and that's nothing to sneeze at.

Interning is definitely optimization and not part of normal Java development.