News for hackers. Stuff that matters.
Re:Introducing Swift by Udo on Monday June 02, 2014 @02:55PM (#7835150)
As someone who always disliked Objective C, I think Swift looks very promising. I'll check it out right away :)

Software-wise, I feel these current WWDC announcements are the most exciting in years.

Looking at the Swift docs right now, I can see many interesting inspirations at work: there's some Lua/Go in there (multiple return values), some Ruby (closure passed as the last argument to a function can appear immediately after the parentheses), closure expressions, strong Unicode character support, a very very neat alternative to nullable types with "Optionals". Operators are functions, too.

It has the concept of explicitly capturing variables from the surrounding context inside closures, like PHP does, instead of keeping the entire context alive forever like Ruby or JS.

Hell there is even some shell scripting thinking in there with shorthand arguments that can be used as anonymous parameters in closures, like "sort(names, { $0 > $1 } )".

Inside objects, properties can be initialized lazily the first time they're accessed, or even updated entirely dynamically. Objects can swap themselves out for new versions of themselves under the caller's nose by using the mutating keyword.

There is the expected heavy-weight class/inheritance scheme which accommodates a lot of delegation, init options, bindings, and indirection (as is expected for a language that must among other things support Apple's convoluted UI API). But at least it's syntactically easier on the eyes now.

Automated Reference Counting is still alive, too - however, it's mostly under the hood now. Accordingly, there is a lot of stuff that deals with the finer points of weak and strong binding/counting.

Swift has a notion of protocols which as far as I can tell are interfaces or contracts that classes can promise to implement.

I think generally there are a few great patterns for method and object chaining, function and object composition in here.

The language has C#-style generics, and supports interesting type constraint expressions.

Re:Introducing Swift by tptacek on Monday June 02, 2014 @04:12PM (#7835985)
I really don't see the Golang influence at all. The multiple- return- value semantic is closer to Ruby's than to Golang's; you're returning a tuple, which happens to have natural syntax in the language.

Defining Golang features that don't exist in Swift:

- Interface types with implicit adoption (Swift takes explicit protocols from ObjC)

- Error types

- Relatedly, the "damnable use requirement" and its interaction with error types and multiple value returns (ie, the reason Golang programs in practice check errors more carefully than C programs).

- Slice types

- Type switching (though, like Golang, it does have type assertions)

- "defer"

- Of course, CSP and the "select" statement.

Swift features that don't exist in Golang:

- Generics

- Optionals

- A conventional, full-featured class-model

Of the languages you could compare Swift to, Golang seems like one of the biggest reaches. Even the syntax is different.

(I like what I've read about Swift and expect to be building things in both Golang and Swift, and often at the same time).

Re:Introducing Swift by Udo on Monday June 02, 2014 @04:30PM (#7836137)
This comment surprises me. It's factual but it's not really a response to an actual claim I made. Did you really perceive that I alleged an extreme similarity to Go in my comment? If so, it certainly wasn't intentional. I just said certain features reminded me of different languages, I didn't mean to assert these languages are actually incorporated into Swift.
Re:Introducing Swift by tptacek on Monday June 02, 2014 @04:39PM (#7836202)
No, no, I don't object to your comment. You're just not the only person I've seen making the comparison to Golang, and so I had a big comment bottled up. :)
Re:Introducing Swift by Udo on Monday June 02, 2014 @04:41PM (#7836224)
Ah OK, I understand :)
Re:Introducing Swift by georgehaake on Monday June 02, 2014 @09:04PM (#7837588)
My hat is off to you gentlemen. Such civility. Good day to you Sirs. Good day.
Re:Introducing Swift by jiyinyiyong on Monday June 02, 2014 @09:52PM (#7837706)
Including me, I think some syntaxes of Switft look like Go, while they actully don't share the same vision. Go tries to be a language great for system programming so it introduces channels, interfaces. But Swift want to help GUI programming and it needs the whole class system but without crazy stuffs like channels.

But for others aspects that are not related these two(class system, concurrency), I would say they look quite similar.

Re:Introducing Swift by pjmlp on Tuesday June 03, 2014 @02:54AM (#7838488)
For Go to be great for systems programming, the unsafe package needs a few more primitives and better control over the GC.
Re:Introducing Swift by tptacek on Tuesday June 03, 2014 @12:29PM (#7841152)
I don't know what this means. I've used Golang successfully for USB drivers, emulators, web and database servers, testing tools, a debugger, and cryptography. It seems evidently suited for systems programming as it stands.

Someone is always going to be out there saying that any language isn't ready for prime time because it lacks feature-X.

Re:Introducing Swift by ScottBurson on Monday June 02, 2014 @07:44PM (#7837250)
Multiple return values are, of course, much older than Ruby or Go(lang). The first language I used with them was Zetalisp (Lisp Machine Lisp) in 1979, though at about the same time, with the release of v7 Unix, C gained the ability to pass or return structs by value. Xerox PARC's Mesa appears to have had them a few years earlier. I don't know of any earlier examples.

I'm surprised not to hear Python mentioned, as it also has a tuple syntax.

Re:Introducing Swift by mythz on Monday June 02, 2014 @05:58PM (#7836747)
It does share Go's `func` keyword, parens-free conditionals, optional semi-colons
Re:Introducing Swift by mseepgood on Monday June 02, 2014 @07:22PM (#7837148)
That's really not a lot. The optional semicolons could also be influenced by BCPL or JavaScript.
Re:Introducing Swift by awalton on Tuesday June 03, 2014 @01:09AM (#7838248)
Yeah, it's only the entire basic Syntax of the language they copied.

Yes, Swift's semantics are different (since it's essentially a domain-specific language designed to make writing Cocoa apps faster), but syntax-wise a Go programmer feels right at home reading Swift.

Re:Introducing Swift by coldtea on Tuesday June 03, 2014 @11:23PM (#7843864)
>Yeah, it's only the entire basic Syntax of the language they copied.

Because, the keyword for function, keyword, parens-free conditionals and optional semi-colons are "the entire basic syntax" of Go, right?

Those are some of the most inconsequential details of Go syntax (all three of them), and of course all existed ages before Go.

Python has no semicolons and parens-free conditionals for one.

Re:Introducing Swift by iv_08 on Tuesday June 03, 2014 @01:30AM (#7838295)
If you mean by "entire" the spelling of one keyword and the omitting of parentheses. Everything else seems to be more related to C and various Action/ECMAScript like scripting languages.
Re:Introducing Swift by nardi on Monday June 02, 2014 @04:19PM (#7836045)
> - Interface types with implicit adoption (Swift takes explicit protocols from ObjC)

Objective-C has informal protocols, and so does Swift.

Re:Introducing Swift by curveship on Monday June 02, 2014 @06:14PM (#7836839)
Informal protocols and implicit interfaces are not the same thing. In particular, implicit interfaces are type checked statically at compile time, while informal protocols are checked dynamically at runtime.
Re:Introducing Swift by tomlu on Monday June 02, 2014 @05:31PM (#7836563)
I'm assuming OP means structural typing, which Objective-C does not support.
Re:Introducing Swift by rayiner on Monday June 02, 2014 @07:38PM (#7837226)
Not just generics, but pretty fleshed out generics, with type variables constrained by class or protocol.
Re:Introducing Swift by stcredzero on Monday June 02, 2014 @04:17PM (#7836036)
(I like what I've read about Swift and expect to be building things in both Golang and Swift, and often at the same time).

How about a blog series where a developer implements something in Golang and/or Swift, then you explain how it's insecure? Then the developer tries to fix it and you explain something else that's insecure. Rinse, repeat.

Re:Introducing Swift by chc on Monday June 02, 2014 @10:19PM (#7837792)
I thought that was called "Hacker News comments."
Re:Introducing Swift by jamra on Monday June 02, 2014 @05:50PM (#7836688)
Perhaps if you take language features directly, it's not a good comparison with Go.

There are some things that did strike me as similar. The approach Go takes is to bring C language to a more modern world (i.e. C without some of the language burdens that we know so well). Swift is attempting to do the same. The way it does type inference is nice.

var x = "Hi" reminds me of Go's const types. The ARC usage reminds me of Go's garbage collection (even though it's not the same thing). Basically, the parts that it omits from C are similar to the parts that Go takes out of C even though the language itself is different... thankfully.

Re:Introducing Swift by mseepgood on Monday June 02, 2014 @07:30PM (#7837189)
> The approach Go takes is to bring C language to a more modern world

Like all the other thousands of languages with C based syntax.

> var x = "Hi" reminds me of Go's const types

Why does it remind you of Go and not of all the other languages that use 'var x = "Hi"' like JavaScript, ActionScript, C#, Scala, Kotlin?

> The ARC usage reminds me of Go's garbage collection

Why does it remind you of Go and not of all the other languages with garbage collection?

Re:Introducing Swift by jamra on Tuesday June 03, 2014 @04:00AM (#7838630)
It reminds me of Go in what it omits from C. There are similarities. Go feels like a mix between python and C.

I haven't gotten to Swift in a deep enough way, but it looks like it tried to tackle the same problems with the exception of concurrency. There are differences such as classes and generics in Swift. There are also similarities such as functions as first class citizens (or so it appears so from the closures section of the free book).

All in all, it reminds me of Go just a bit. It doesn't remind me of all of those other languages that I do not know.

Re:Introducing Swift by rayiner on Monday June 02, 2014 @07:58PM (#7837312)
> Why does it remind you of Go and not of all the other languages with garbage collection?

You sound old. ;)

Re:Introducing Swift by djhworld on Tuesday June 03, 2014 @03:04AM (#7838504)
I think the style of defining functions is similar to Go. Not a carbon copy, but it "feels" Go-ish.
Re:Introducing Swift by zenojevski on Monday June 02, 2014 @04:48PM (#7836264)
From a user's point of view, it's basically straight out of the Rust book, all the gravy with also relaxed ownership and syntax.

It has it all [1]: static typing, type inference, explicit mutability, closures, pattern matching, optionals (with own syntax! also "any"), generics, interfaces, weak ownership, tuples, plus other nifty things like shorthand syntax, final and explicit override...

It screams "modern!", has all the latest circlejerk features. It even comes with a light-table/bret-victor style playground. But is still a practical language which looks approachable and straightforward.

Edit: [1]: well, almost. I don't think I've caught anything about generators, first-class concurrency and parallelism, or tail-call optimization, among others.

Re:Introducing Swift by stormbrew on Monday June 02, 2014 @06:58PM (#7837038)
I don't really see anything but a superficial resemblance to rust, where both are borrowing ideas from the same place. Where Rust really differs from modern algol-family-languages-learning-from-30-year-old-functional-programming-research is in its strictness.

The optional type stuff is good, and it will definitely be a net safety improvement, but it's by no means attempting to approach a panacea to safety like Rust's strict static analysis does.

Particularly that Swift gives you really simple outs in the form of the '!' unwrap and 'as' (should be 'as!' at least imo) downcast-and-unwrap operators that result in run-time errors and will probably be seen as unremoveable code-smell in a couple of years.

Re:Introducing Swift by kibwen on Monday June 02, 2014 @05:25PM (#7836525)
Indeed, I'm not sure what Swift's concurrency story is yet. Other than that it's encouragingly similar to Rust (we're evolving in the right direction!), but not quite as low-level.
Re:Introducing Swift by mkehrt on Monday June 02, 2014 @05:43PM (#7836653)
I'm sure that the main mechanism will be the existing dispatch queue libraries Apple's other languages use.
Re:Introducing Swift by pjmlp on Monday June 02, 2014 @06:50PM (#7837005)
Most likely use the Grand Central Dispatch that is already part of iOS and Mac OS X.
Re:Introducing Swift by Pacabel on Monday June 02, 2014 @06:35PM (#7836937)
The similarity to Rust should scare the hell out of Rust's creators and proponents.

Swift could very well render Rust almost totally irrelevant within the OS X and iOS sphere of software development. If we end up eventually seeing Swift implemented for other platforms, then the chances of Rust's long-term success diminish even more.

Things might have been different had a stable, even if somewhat imperfect, initial version of Rust had been released by now, thus allowing it to gain some adoption and traction.

I hope that the "But Rust isn't targeting those developers!" argument isn't used to try to justify this mistake, as well. Rust is already facing stiff competition from languages like Go, C++11, C++14, Scala and even Java 8.

With the announcement of Swift, Rust's niche and audience are getting smaller, further preventing the widespread adoption that's necessary for a programming language to become truly successful.

Re:Introducing Swift by kibwen on Monday June 02, 2014 @06:50PM (#7837002)
Oh hello again, Pacabel. I'm familiar with your game by now. :)

We're not scared in the slightest. I'll reconsider when Swift has inline ASM, allocators, linear types, move semantics by default, region analysis, and a type system that guarantees freedom from data races (oh, and when the code is open-sourced, and targets both Linux and Windows as a first-class citizen).

Swift isn't intended to be a systems language: it's an application language. Anyone who's capable of choosing Swift as of today was just as capable of choosing Objective-C yesterday. And as the Rust developers themselves have discovered over the past two years, deciding to become a systems language doesn't happen overnight.

(In fact, on a personal note, I'm ecstatic that Swift has been announced. ADTs! Optional types! Pattern matching! Think of how many features are no longer alien to people who want to learn Rust! And hell, the syntax is incredibly similar as well, which further reduces friction. As a hardcore Rust contributor, I want to shake the hand of each and every one of Swift's designers.)

Re:Introducing Swift by pohl on Monday June 02, 2014 @07:51PM (#7837283)
Swift isn't intended to be a systems language

FWIW, Swift is categorized as a systems language in the opening pages. But, then, so does Go in its FAQ. To Swift's credit, at least it has deterministic memory management through ARC.

Re:Introducing Swift by mzl on Tuesday June 03, 2014 @01:34AM (#7838304)
While having some support for garbage collection is good, reference counting is not is a rather expensive way to implement that for applications. This becomes especially bad in multicores since it may dramatically increase the number of writes to shared object cache lines.
Re:Introducing Swift by pohl on Tuesday June 03, 2014 @08:58AM (#7839823)
Wouldn't a lot of that be mitigated, though, by using tagged pointers in place of RC structs where possible? Seems like an obvious optimization.
Re:Introducing Swift by mzl on Wednesday June 04, 2014 @02:39AM (#7844293)
Not really sure what the tag in the pointer would be used for. Could you give an example.

In general, reference counting has the problem that it needs to update the reference count. If you have a read-only data-structure these updates to the references will introduce writes that may severely impact performance since a write introduces cache consistency communication, while reads are communication-free.

Re:Introducing Swift by pohl on Wednesday June 04, 2014 @08:51AM (#7845240)
Yeah, you're right. I didn't think it through when I asked. I conflated this scenario with the technique they use to put small objects like NSNumber on the stack.
Re:Introducing Swift by vor_ on Monday June 02, 2014 @08:49PM (#7837532)
> Swift isn't intended to be a systems language: it's an application language.

It may not be ready as a systems language in its pre-1.0 form, but the Swift book claims that it's "designed to scale gracefully from ‘Hello World’ to an entire operating system", so Apple appears to have big goals.

Re:Introducing Swift by jsmthrowaway on Monday June 02, 2014 @09:13PM (#7837612)
I'm thinking about starting the "Rust contributor points out how Rust is a systems language and $language is an applications language" drinking game. At least now they'll focus on Swift instead of Go. I don't mean this to be rude; I've just noticed a similar set of usernames in threads about certain !Rust languages playing the underdog position and always feeling like they need to compare.

Given Rust's PR, speaking of that -- not a thread about Go passes without at least three pcwalton comments these days -- I actually broke down and gave it a try. I wrote a little Hello World server and then got lambasted by a friend of mine for not working functionally, since, in his words, "Rust is a functional language and the fact that it supports other paradigms is a mistake." I rm -rf'd and ignore it for now, but I look forward to it stabilizing and maybe coming back to it.

Rust has potential but the PR needs to ease up just a little. There is room for more than one language in the world.

Re:Introducing Swift by nnethercote on Tuesday June 03, 2014 @12:11AM (#7838093)
> not a thread about Go passes without at least three pcwalton comments these days

Well, every thread about Go inevitably has numerous comments comparing it to Rust, often erroneously, and pcwalton is one of the primary Rust developers.

Re:Introducing Swift by jsmthrowaway on Tuesday June 03, 2014 @01:58AM (#7838371)
A fair point.
Re:Introducing Swift by ben0x539 on Monday June 02, 2014 @10:07PM (#7837753)
Sign me up for a "someone gets indignant about rust developers responding to other people's comments about rust" drinking game.

(small-time rust contributor here too)

Re:Introducing Swift by jsmthrowaway on Tuesday June 03, 2014 @01:55AM (#7838360)
I think you should look up what "indignant" means, then, for the benefit of all of us, demonstrate the anger in my comment that was not put there unconsciously by the reader.
Re:Introducing Swift by dbaupp on Monday June 02, 2014 @11:37PM (#7838007)
Rust is not a functional programming language. Your friend is just wrong for taking you to task about that.
Re:Introducing Swift by VeejayRampay on Monday June 02, 2014 @07:10PM (#7837096)
I saw a lot of people mention ADT in relation to Swift but I haven't found examples in the documentation book I downloaded from Apple. Would you be kind enough to provide the example you saw? EDIT: My bad, page 40 in the section about protocols (unless I'm missing something).
Re:Introducing Swift by tel on Monday June 02, 2014 @11:25PM (#7837979)
It's on the bottom half of the page about enumerations. Typically languages have product types, but lack true sum types. Swift's enums provide such leverage.

That said, Swift's types are a bit less than recursive, so there's a bit of niggling still before you get to the affordances of something like Haskell's `data`.

Re:Introducing Swift by VeejayRampay on Tuesday June 03, 2014 @12:06PM (#7841000)
Thank you.
Re:Introducing Swift by jsmthrowaway on Monday June 02, 2014 @07:29PM (#7837182)
It's interesting that inline assembly is your first bullet point, since there's nothing I can think of that ruins a code file more than inline assembly in a host language. Put that crap in a .S file and link it in like everything else, for crying out loud. The one time you need inline assembly is when you don't want to build a function frame, such as a tight loop, but come on.

Also, even in systems, I can think of about once a decade I even need to write assembly, so... maybe grasping at straws a bit?

Re:Introducing Swift by pcwalton on Monday June 02, 2014 @08:09PM (#7837354)
I wouldn't lead with inline assembler as the selling point of Rust. The main selling point of Rust is memory safety without garbage collection; it still is the only industry language that allows this (as reference counting is a form of GC).

That said, I think inline assembler is an important feature:

> It's interesting that inline assembly is your first bullet point, since there's nothing I can think of that ruins a code file more than inline assembly in a host language. Put that crap in a .S file and link it in like everything else, for crying out loud.

That's too slow. You need to give the optimizer more information than that, and the overhead of the procedure call can be significant.

> The one time you need inline assembly is when you don't want to build a function frame, such as a tight loop, but come on.

But that's a very important use case.

> Also, even in systems, I can think of about once a decade I even need to write assembly, so... maybe grasping at straws a bit?

It's all over the place in the Linux kernel.

Re:Introducing Swift by jsmthrowaway on Monday June 02, 2014 @09:09PM (#7837603)
> But that's a very important use case.

For Rust. I didn't make the comparison to Rust, I merely was intrigued by the choice of features and in which order to defend the comparison made by someone else. I see Rust and Swift as targeting entirely different things, at least at first (which means that Swift can certainly evolve inline assembly if it is so needed), and any comparison at this stage is pointless.

> It's all over the place in the Linux kernel.

Cool, that's one piece of software. I'll save you the next few: drivers and a couple files in a game engine. You're disputing my point how, exactly?

Re:Introducing Swift by kibwen on Monday June 02, 2014 @09:32PM (#7837656)
I'm confused that you seem to think that my bullet points are ordered from most to least important. It seems like quite a strange thing to attack! I'm sorry to disappoint you, but I do not run these comments by a team of editors first. :)

That said, judging by your other comments, you seem to be of the impression that the Rust team has some sort of vendetta against Go, and have concocted a vendetta in kind. Again, I must sadly disappoint you, but I strive to encourage a culture of respect in all the forums that I visit (and moderate).

Re:Introducing Swift by jsmthrowaway on Tuesday June 03, 2014 @01:47AM (#7838340)
If you find my comments disrespectful and think I'm implying you have a vendetta, you skimmed them and are disrespecting me by putting words in my mouth. I've simply noticed a trend of most commentary from Rust contributors taking the underdog position and participating in picking apart other (ostensibly) competing languages, and I think you guys should stop doing that.

The last sentence of the comment to which you hint is my thesis. There is no subtext. It's easy to perceive negative opinions as attacks and create an adversary from the person writing the opinion, but it's also a little bit disingenuous. It also, conveniently, creates a platform upon which nobody can disagree with you lest they be hostile and aggressive. You can then exit on the "high ground," as you've done here.

I meant no ill will. Best of luck, I guess.

Re:Introducing Swift by haberman on Monday June 02, 2014 @08:38PM (#7837479)
> The one time you need inline assembly is when you don't want to build a function frame, such as a tight loop, but come on.

This is hilarious. Like anyone would ever use inline assembly in a tight loop.

Re:Introducing Swift by Pacabel on Monday June 02, 2014 @07:49PM (#7837277)
My apologies, I didn't realize that expecting a programming language to have a stable syntax, stable semantics, a stable standard library and at least one stable and robust implementation before using it seriously in industry was merely a "game".

Perhaps this is news to you, but those of us who work on and are responsible for large-scale software systems tend to take such factors very seriously.

This may sound harsh, but it really doesn't matter what features and benefits Rust could potentially bring to the table if the lack of stability makes it unusable in practice today. A programming language that can't be seriously used might as well not even exist.

I don't doubt that Apple will have Swift available in a seriously usable form by this fall, and it's very likely that it will see rapid adoption soon after. I'm afraid I can't say the same about Rust and its supposed by-the-end-of-2014 1.0 release, given its current lack of stability and the rapidly-approaching end of the year.

Re:Introducing Swift by BrandonM on Monday June 02, 2014 @08:26PM (#7837428)
You seem to desire both stability and a faster 1.0 release. The realistic choices are:

    1. Release fast and iterate
    2. Release fast and be stuck with mistakes
    3. Release slow
Option #1 breaks stability, so that's out.

Swift appears to be taking option #2 (Apple doesn't commonly break APIs, do they?), but we can't even really be sure because it hasn't been developed in the open the way that Rust has. It's possible that it's been in development as long as Rust, and we simply haven't heard about it yet. Either way, option #2 is a perfectly reasonable one to go with; it has served Java quite well (for a loose definition of fast), though it has required some creative approaches to language improvements.

Rust is taking option #3. C has been around for over 40 years now. If Rust hopes to supplant it, it seems reasonable to take a few extra months (or even an extra year) to put out a solid version 1 that won't hamstring the language or force a breaking change down the line.

Re:Introducing Swift by kainosnoema on Monday June 02, 2014 @10:11PM (#7837771)
Apple just announced in the Platform State of the Union that they won't guarantee source compatibility until Swift is released along with iOS 8 (changes to the language will require source conversions), so I believe they're taking a route closer to option #1.
Re:Introducing Swift by taharvey on Wednesday June 04, 2014 @09:44PM (#7849708)
No I'd say Apples approach was: methodically develop until very polished first, then announce after. You just didn't get to see the 0.1, 0.2, 0.3... versions.

This is actually nice, because knowing about languages years before they are production ready probably just slows developer adoption because nobody is quite sure when they should trust there development process to a new language.

Re:Introducing Swift by coldtea on Monday June 02, 2014 @08:39PM (#7837483)
>My apologies, I didn't realize that expecting a programming language to have a stable syntax, stable semantics, a stable standard library and at least one stable and robust implementation before using it seriously in industry was merely a "game"

You also didn't realize that you just built the biggest strawman ever in the above sentence.

Enough with the "I want a stable Rust now". Rust, like any other language, takes years to stabilize. You just happen to see it happen in the open, whereas most other languages you get them at their 1.0 release.

>This may sound harsh, but it really doesn't matter what features and benefits Rust could potentially bring to the table if the lack of stability makes it unusable in practice today. A programming language that can't be seriously used might as well not even exist.

They could not give a flying duck about it being "seriously used today".

They'll start to care AFTER they release it as 1.0. They only released this 0.x versions to solicit ideas and improvements, not to get programmer's to adopt it.

Re:Introducing Swift by Pacabel on Monday June 02, 2014 @08:50PM (#7837536)
Well, we aren't actually seeing stabilization when it comes to Rust.

Assuming this stabilization actually does happen, whether it happens in public or private is irrelevant.

What matters is that we've seen C++ stabilize. We've seen Go stabilize. We've seen Scala stabilize. And now we'll likely see Swift stabilize, well before Rust does. They are all serious competitors to Rust.

As these other languages continue to evolve, but at the same time remaining usable, the relevance of Rust will continually decrease. It may still have drawing power today. A few years from now, it will have less appeal.

Re:Introducing Swift by enneff on Monday June 02, 2014 @10:08PM (#7837757)
This is silly. Rust is on a similar time frame to Go in terms of stabilization (~2.5 years after release).

It's hard to make a comparison against Swift, which is a proprietary language developed for years behind closed doors. Presumably they're at 1.0 from the first day by design. You can't do that with open source languages.

Re:Introducing Swift by TheHydroImpulse on Monday June 02, 2014 @11:54PM (#7838054)
* Scala has been around since 2004 (public release) -- 10 years ago. (Not sure when the first stable release was but more than 3 years.) * Go in 2009 (public) -- 6 years ago. 1.0 (first stable release) was released in 2012 so it took 3 years to stabilize. * C++ in 1983 -- 31 years ago. ... It's been a long time. * Clojure in 2007 -- 7 years ago. The creator took 2 1/2 years before releasing it to the public. * Rust in 2012 -- 2 years ago.

It's pretty absurd to expect Rust to be stable right from the get go. The difference in all this is that most of those languages were closed before being released. Rust was open at a pretty early state.

Re:Introducing Swift by iv_08 on Tuesday June 03, 2014 @01:34AM (#7838308)
You're probably right, but I think I've heard of Rust in public in 2010 and that it was started by Graydon in 2007.
Re:Introducing Swift by kibwen on Tuesday June 03, 2014 @01:47AM (#7838341)
Rust had been stewing around in Graydon's head for years, but he was never paid to work on it until 2009 (part-time, at that point). And he didn't have any paid employees to help him until 2010 (that would be pcwalton). And as far as I'm concerned, Rust development didn't actually start in earnest until mid-to-late 2011, when the compiler began bootstrapping. And the Rust that we know and love today didn't begin to take shape until 2012, when borrowed references started taking shape.

Personally, I consider the 0.1 release in January 2012 to mark Rust's "birthday". Everything prior to that was just gestation. :)

Re:Introducing Swift by BrandonM on Monday June 02, 2014 @09:46PM (#7837696)
I can't tell if you like Rust or hate it. If you hate it, and you are right, then it will simply fade away and your comments will serve nothing more than being able to say, "I told you so." If you are wrong, then you end up looking a bit silly.

If you like it, perhaps you should be a little patient and give the creators the benefit of the doubt. No one wants a Rust 3.0 fiasco.

It's hard to encounter language issues without implementing a large project in the language. I am happy that they're taking the time to let the implementation of Servo help inform the design of Rust.

Re:Introducing Swift by pcwalton on Monday June 02, 2014 @08:04PM (#7837336)
Rust's raison d'être is memory safety without garbage collection. Swift requires garbage collection to achieve memory safety. (Reference counting is a form of garbage collection.)

In other words, Rust is about safety with zero overhead over C++, and Swift is not zero-overhead. So the people who need Rust are not going to use Swift for Rust's domains. That's fine, as Apple wanted a language for iOS and Mac app development with tight integration with Objective-C, and from what I've seen they've done a great job of developing one.

> Things might have been different had a stable, even if somewhat imperfect, initial version of Rust had been released by now, thus allowing it to gain some adoption and traction.

Why are you so insistent that we freeze an unsafe version of a language that's designed for safety?

Re:Introducing Swift by dbaupp on Monday June 02, 2014 @08:08PM (#7837352)
> Why are you so insistent that we freeze an unsafe version of a language that's designed for safety?

Pacabel has made a career of complaining about Rust being unstable.

Re:Introducing Swift by nnethercote on Monday June 02, 2014 @08:48PM (#7837528)
At least he/she hasn't derailed the thread by complaining about every other project that Mozilla is working on. I count that as progress!
Re:Introducing Swift by Pacabel on Monday June 02, 2014 @08:22PM (#7837410)
Are you honestly suggesting that Rust is stable at this point?

I think that the recent, and very disruptive, ~ and box changes should completely dispel that notion.

I'm merely pointing out the reality of the current situation, which some in the Rust community do not wish to acknowledge, for whatever reason. The situation has yet to change, so what I'm saying is still valid, and will remain so until some actual improvement does take place.

Now that we see yet another serious competitor in the form of Swift, what I've had to unfortunately be saying for some time now becomes more and more relevant. If Rust is to become relevant, it will need to be usable, and that will need to happen very quickly.

Re:Introducing Swift by dbaupp on Monday June 02, 2014 @08:34PM (#7837456)
No, I'm not suggesting that Rust is stable. It wasn't even slightly implied by what I said. I was just pointing out that you're a broken record on this topic, to the point of being a troll (you seem to just ignore the meat of any response you get and only focus on the current state of Rust).

To be crystal clear: no-one is suggesting that Rust is stable and no-one is suggesting it is ready for adoption (if they are, they are wrong). However, being unstable now is very very different to not ever being stable.

In any case, Swift is only tangentially a Rust competitor as kibwen demonstrated.

Re:Introducing Swift by Pacabel on Monday June 02, 2014 @08:44PM (#7837509)
Resort to name-calling if you really must. None of that will change reality.

Rust is not stable, as you yourself have readily admitted. What I've unfortunately had to be pointing out for such a long time now is absolutely correct.

We've been told that we can expect Rust 1.0 by the end of the year. As each month passes, it becomes less and less likely that we will actually see this. We are still seeing significant change, even as recently as the past month.

I think Rust could potentially be very useful. But that requires stability, and that in turn is something that appears more and more elusive each day.

It's easy to say that Swift isn't a competitor to Rust, but the reality is that it is. And unlike Rust, it will very, very likely be usable for serious apps within a few months. It will see the adoption that Rust could have had, had it been usable, further reducing Rust's future changes.

Re:Introducing Swift by dbaupp on Monday June 02, 2014 @09:23PM (#7837635)
What have you been pointing out for so long? That Rust is unstable? That many people/companies won't use Rust while it is unstable? That there are other languages people can use instead?

All of those are highly uncontroversial and universally acknowledged by experienced Rust users.

Also, I don't understand how you have lept from Rust being unstable now, to Rust never being stable.

A 1.0 release by the end of the year doesn't seem at all unreasonable to me; I think you are expecting more from it than what the Rust team is looking for (and have stated publicly repeatedly): stabilising the core language.

Of course, a stable release of that form will still mean some libraries may be unstable (and so that Rust would be unsuitable for many corporate developments). These libraries will be stabilised progressively and iteratively.

Re:Introducing Swift by coldtea on Monday June 02, 2014 @08:47PM (#7837520)
>Are you honestly suggesting that Rust is stable at this point? I think that the recent, and very disruptive, ~ and box changes should completely dispel that notion.

No, he merely suggests that you bored a lot of people by repeating that it's unstable, instead of accepting the fact and using something else.

If being unstable is that bad, then by all means, go and use a stable language.

Re:Introducing Swift by Pacabel on Monday June 02, 2014 @08:55PM (#7837553)
I, and many others, do use something else. That's the big problem facing Rust, whether or not its creators wish to admit this fact.

There are numerous alternatives to Rust that offer many of its benefits, but they're usable today. We can rely on them today, tomorrow, and likely for some time to come.

And by this fall, we'll likely have Swift as yet another option to add to our growing list.

I think Rust has a lot of potential. But each month that goes by squanders that potential. It has less and less of a chance of making a real impact the longer it isn't usable, especially while its competitors keep evolving.

Re:Introducing Swift by coldtea on Wednesday June 04, 2014 @07:51AM (#7845025)
>I, and many others, do use something else. That's the big problem facing Rust, whether or not its creators wish to admit this fact.

Yeah, and I listen to Rihanna instead of Jay Farrar. Obviously that's the big problem Jay is facing, and he should sound more like Rihanna to cater to my taste.

Re:Introducing Swift by pcwalton on Monday June 02, 2014 @08:31PM (#7837448)
> Are you honestly suggesting that Rust is stable at this point?

No, he didn't say that anywhere.

Re:Introducing Swift by Pacabel on Monday June 02, 2014 @08:15PM (#7837374)
I think you may be aiming for a level of safety, or perhaps a notion of "perfection", that isn't practically obtainable.

The recent, and rather disruptive, box changes are a good example of this. We see change, and those of us with existing Rust code sure do feel the change, but very little convergence seems to be happening.

Based on past trends, I would not be at all surprised if problems are found with the new approach as it becomes more widely used, and some other approach is then attempted.

Wheel-spinning is something that can quite easily happen with ambitious software projects. It's not a new phenomenon. But when facing ever-increasing competition, and other real-world constraints, it's often better to aim slightly lower and at least be mostly usable in practice.

A memory-safe programming language that can't actually be used is pretty much irrelevant. It's better to accept some slight amount of imperfection if that means it can actually be used.

Re:Introducing Swift by pcwalton on Monday June 02, 2014 @08:23PM (#7837413)
> I think you may be aiming for a level of safety, or perhaps a notion of "perfection", that isn't practically obtainable.

I believe it is, as the basic structure and rules of the borrow check (which is the part of Rust that's truly unique) have proven themselves to be quite usable. The usability problems remaining are implementation and precision (e.g. issue #6393), not big problems that will require large redesigns.

> The recent, and rather disruptive, box changes are a good example of this. We see change, and those of us with existing Rust code sure do feel the change, but very little convergence seems to be happening.

Yes, it is. The number of outstanding backwards incompatible language changes is decreasing. People who do Rust upgrades notice how the language is changing less and less.

> A memory-safe programming language that can't actually be used is pretty much irrelevant. It's better to accept some slight amount of imperfection if that means it can actually be used.

"Some slight amount of imperfection" means not memory-safe. Java didn't settle for that, C# didn't settle for that, Swift isn't settling for that, and we aren't settling for it.

Re:Introducing Swift by girvo on Monday June 02, 2014 @09:02PM (#7837574)
This is an honest question: Why do you seem to care so much? Rust is in my view a great project, that yes isn't quite there yet but is making great progress. I'm looking forward to using it when it is stable, and pcwalton and the other contributors are developers that I've looked up to for a number of years: I have nothing but faith in them.

At the end of the day, if Rust fails, well that will be a shame. But I'm seeing nothing that shows that it might, so I'm truly struggling to understand why you seem so upset by a new modern language trying to tackle big problems in ways that have never been done before. That's a good thing, as far as I'm concerned.

Re:Introducing Swift by Pacabel on Monday June 02, 2014 @09:14PM (#7837616)
Having been in industry for a long time, I think that something like Rust would be hugely beneficial. It very well could solve some very real problems.

I bring this up again and again because I'd rather not see Rust fail. I'd much rather see a slightly flawed Rust that's actually usable in the short term, rather than a continually changing Rust that nobody will seriously adopt.

Rust has been in development for years now. That's a very long time in the software industry. A few years of development time without a stable release is understandable. But it's getting beyond that now.

Rust isn't quite there yet, but each day it edges closer to a Perl 6 type of disaster. Perl 6 offered some intriguing ideas, but it just isn't usable, and that's a shame. Meanwhile, other competitors have arisen and blown past it, rendering it far less useful were it ever properly implemented.

Given the increasingly stiff competition that Rust is facing, I suspect we'll see it end up like Haskell or D. Something usable is eventually produced, but it never sees the truly widespread adoption that it could have seen, had it been usable earlier on. It's not as bad as Perl 6's situation, but it is still unfortunate.

Re:Introducing Swift by nnethercote on Tuesday June 03, 2014 @12:25AM (#7838142)
> Given the increasingly stiff competition that Rust is facing, I suspect we'll see it end up like Haskell or D. Something usable is eventually produced, but it never sees the truly widespread adoption that it could have seen, had it been usable earlier on.

I don't have much to say about D, but the history of Haskell implied by this sentence is hilariously wrong.

Go watch Simon Peyton Jones' talk about the history of Haskell: http://research.microsoft.com/en-us/um/people/simonpj/papers.... As well as being wonderfully entertaining, it explains the actual history of Haskell: it was designed to be a language with which various academic groups could do functional programming language research. The fact that Haskell has gradually grown more popular and now has mainstream appeal and some industrial users is quite a surprise to its creators.

Re:Introducing Swift by TheHydroImpulse on Tuesday June 03, 2014 @01:18AM (#7838270)
> Rust has been in development for years now. That's a very long time in the software industry. A few years of development time without a stable release is understandable. But it's getting beyond that now.

Not for programming languages. These take years and years. Take a stab at any of the most popular languages. They weren't created 1-3 years ago. It takes time, and that's a good thing.

Re:Introducing Swift by taharvey on Wednesday June 04, 2014 @09:47PM (#7849720)
reference counting != garbage collection. Garbage collection take CPU and lots of memory. Reference counting just ++ the pointer count on allocation, and -- on free. Essentially no overhead.
Re:Introducing Swift by stormbrew on Monday June 02, 2014 @07:00PM (#7837047)
C++ moving to a 3 year standard cycle is a much bigger 'threat' to rust. But really, the fact that there's so much actual investment in improving mainstream languages from various well-funded sources is probably a rising-tide-lifts-all-boats kind of thing.
Re:Introducing Swift by Pacabel on Monday June 02, 2014 @07:16PM (#7837119)
Yes, I do agree that the situation is improving across the board.

But as an industry, we need practical solutions that are available now, even if somewhat flawed. We need languages we can use today, and know that the code we write today will still compile fine next week and next year, if not a decade or more from now.

Modern C++ is getting pretty good at offering this, while offering far a greater degree of safety. Go isn't bad, either. Scala has its drawbacks, but it's often a reasonable option, too. The key thing to remember is that all of these languages have offered developers a stable target, and they are seriously usable in the present.

Given the announcement of Swift, and given that Apple will very likely deliver on it by the fall, we very well could see it becoming a major player during 2015.

The safety benefits that Rust could theoretically or potentially offer are virtually useless to huge swaths of the industry as long as the predictability of a stable release just isn't there. The longer this wait goes on, the better the competition becomes, and the less relevant Rust will unfortunately become in the long term.

Re:Introducing Swift by pcwalton on Monday June 02, 2014 @08:08PM (#7837349)
> But as an industry, we need practical solutions that are available now, even if somewhat flawed. We need languages we can use today, and know that the code we write today will still compile fine next week and next year, if not a decade or more from now.

By this logic we shouldn't invent any new programming languages at all. There's no such thing as a "practical solution that's available now"; everything takes time to develop.

> Modern C++ is getting pretty good at offering this, while offering far a greater degree of safety. Go isn't bad, either. Scala has its drawbacks, but it's often a reasonable option, too. The key thing to remember is that all of these languages have offered developers a stable target, and they are seriously usable in the present.

You aren't going to use those languages if you want memory safety without garbage collection. Because they can't offer zero-overhead memory safety without breaking existing code.

Re:Introducing Swift by DanielRibeiro on Monday June 02, 2014 @04:07PM (#7835948)
Swift's environment is also very similar to Elm's time travel debugger: http://debug.elm-lang.org/

Direct link to Elm's demo similar to Bret Victor's: http://debug.elm-lang.org/edit/Mario.elm (video: https://www.youtube.com/watch?v=RUeLd7T7Xi4)

Re:Introducing Swift by AlexanderDhoore on Monday June 02, 2014 @04:43PM (#7836241)
I immediately thought about that as well. I wonder how they pull it off? Swift is not a functional language, so they just save every single variable, or what?
Re:Introducing Swift by seanmcdirmid on Monday June 02, 2014 @04:54PM (#7836310)
Time travel debugging has existed for a long time, and it's not limited to functional languages; the most obvious way they could do this is through checkpointing.
Re:Introducing Swift by cwp on Monday June 02, 2014 @05:36PM (#7836610)
Checkpointing is a natural fit with the Cocoa API, which uses an event loop. Just save the state of the application after each event is handled.
Re:Introducing Swift by gtrak on Wednesday June 04, 2014 @01:41PM (#7846992)
Just a hunch, LLVM uses Static-Single-Assignment, which is just that, saving every single variable change.
Re:Introducing Swift by seanalltogether on Monday June 02, 2014 @03:05PM (#7835271)
He mentioned the desire to drop the "C" from objective-c, but I'm curious what this means for using c/c++ libraries now. Do they need to be wrapped by objective-c before being visible in swift?
Re:Introducing Swift by quonn on Monday June 02, 2014 @04:14PM (#7836009)
Swift uses a special "bridging header" to expose Objective-C code to Swift. This header will presumably be processed by the Swift compiler.

In the other direction, XCode will automatically generate an Objective-C header to expose your Swift code to Objective-C.

Re:Introducing Swift by outworlder on Monday June 02, 2014 @04:18PM (#7836039)
The ibooks guide references a "Using Swift with Cocoa and Objective-C" document. Is that where you got your information?
Re:Introducing Swift by FreezerburnV on Monday June 02, 2014 @03:08PM (#7835317)
It seemed like it could interoperate with C just fine based on the slide talking about all three. Also because it uses the Objective-C runtime and compiles to native, it might just see C functions as normal functions. Though what little I've looked at the free book hasn't given me any hints about that yet.
Re:Introducing Swift by sv3nss0n on Monday June 02, 2014 @05:04PM (#7836372)
"You cannot import C++ code directly into Swift. Instead, create an Objective-C or C wrapper for C++ code."
Re:Introducing Swift by Udo on Monday June 02, 2014 @03:30PM (#7835572)
I suspect that as long as it compiles to LLVM, anything goes.
Re:Introducing Swift by pjmlp on Tuesday June 03, 2014 @03:01AM (#7838498)
I hope so. Another stab on C's back.
Re:Introducing Swift by josephjrobison on Monday June 02, 2014 @06:05PM (#7836794)
Is it realistic to try to dive right in to the 500-page book they provided without a computer science background, just HTML/CSS/PHP self-taught experience, to learn the language? Or should I take other steps first?
Re:Introducing Swift by krenoten on Monday June 02, 2014 @06:14PM (#7836840)
Reading a book cover-to-cover is, for me, a bad way to learn a language. I usually pick things up very quickly when I try to implement things using them that I am both familiar with and faced with annoying issues stemming to the language they are currently implemented in. If you don't have one of those, think about something you hate, and fix it with this.

If the book is good documentation, then use it. But you may benefit from focusing more on problems than completing a book.

Re:Introducing Swift by lugg on Monday June 02, 2014 @06:27PM (#7836890)
Just read the first paragraph and conclusions if the have them, of each chapter. This will give you a good idea of what's there when you need it. Then I'd jump straight into tutorials.

Honestly skimming 500 doesn't sound horribly hard to me. I've done that a few times to pick up something new. As ap said you won't learn the language like that but you will have a good reference to go and learn from after the fact.

After that you could probably work through the examples in said book, or at least the interesting ones.

P.S. above steps is all I really learnt from my cs degree.

Re:Introducing Swift by cnp on Monday June 02, 2014 @06:51PM (#7837008)
Skimming through it has been great. It's quite well-written and you'll get a lot of the concepts that the lang introduces even if the extent of your programming education is JS. Give it a try :)
Re:Introducing Swift by josephjrobison on Monday June 02, 2014 @06:48PM (#7836995)
And is this the exact same language - http://www.cs.cornell.edu/jif/swift/doc/index.html
Re:Introducing Swift by cschmidt on Monday June 02, 2014 @07:48PM (#7837268)
No, it is completely unrelated. That is the other language called Swift.
Re:Introducing Swift by stormbrew on Monday June 02, 2014 @07:02PM (#7837063)
The copy I have is only 366 pages, but it's 'converted' from the ebook so I'm not sure if that's a factor. A lot of the pages are dedicated to an examination of the grammar that's probably not relevant for a language overview and the rest is really readable and easily skimmed for interesting details. It's broken up with simple and clear examples every few paragraphs as well.

Definitely take a look through it. You definitely don't need to be a language nerd to understand it.

Re:Introducing Swift by golergka on Monday June 02, 2014 @07:53PM (#7837290)
I'm 20% in, and you certainly should give it a try. It's very well-written, explains basic concepts really well, and has a lot of examples. It also has a good flow from the basc features to more advanced ones.
Re:Introducing Swift by josephjrobison on Tuesday June 03, 2014 @12:15AM (#7838115)
Great, thanks - will give it a shot!
Re:Introducing Swift by hrktb on Tuesday June 03, 2014 @05:13AM (#7838892)
I think it's a good idea only if you execute code in parallel, following all the examples. Otherwise there's a lot of notions than already exist in Objective C that are glossed over and would be pitfalls for people new to the runtime.
Re:Introducing Swift by CCs on Monday June 02, 2014 @07:13PM (#7837108)
I think everybody can see their own favorite language in it... and that's a good thing.

For me it looks like Scala + a sprinkle of C++14 :)

Re:Introducing Swift by CCs on Wednesday June 04, 2014 @02:58PM (#7847431)
There are others too with "looks like Scala":

Jacob Leverich https://leverich.github.io/swiftislikescala/

Den Shabalin http://www.scribd.com/doc/227879724/Swift-vs-Scala-2-11

Re:Introducing Swift by anilmujagic on Tuesday June 03, 2014 @04:59AM (#7838830)
Indeed, I also think it's most similar to Scala.
Re:Introducing Swift by curveship on Monday June 02, 2014 @06:35PM (#7836936)
> It has the concept of explicitly capturing variables from the surrounding context inside closures, like PHP does, instead of keeping the entire context alive forever like Ruby or JS.

Just as a point of fact, javascript -- at least the v8 implementation I'm most knowledgeable of -- doesn't "keep the entire context alive forever." Only variables used in the closure are allocated into the closure (i.e. on the heap), the others are allocated on the stack and disappear as soon as the function returns.

I don't use iTunes so can't read their book, but I wanted to ask: you say that ARC is still their GC strategy, correct? So reference cycles are still an issue? I'm surprised at this. I can see reference counting being a strategy for moving a non-GC'd language to GC (like Objective-C), but to start a new language with that constraint is surprising.

Re:Introducing Swift by Udo on Monday June 02, 2014 @07:01PM (#7837053)
> Only variables used in the closure are allocated into the closure

I'm not sure that's true. Look at the following code:

  var x = 123;

  var f = function(xname) {
    eval('console.log('+xname+');');
  }

  f('x');
It's a dynamically named variable. Clearly, f() has access to the entire context that surrounds it, not just the objects explicitly used in the function code. In this example, the compiler could not possibly have known I was going to access x.

This means in Javascript, as well as in Ruby, when you hand a closure to my code, I can access the entire environment of that closure.

Contrast that with Lua, for example, where the compiler does indeed check whether an outer variable is being used and then it imports that variable from the context only.

PHP does it most explicitly, forcing the developer to declare what outer objects they want to have available within the function.

Re:Introducing Swift by curveship on Monday June 02, 2014 @07:41PM (#7837241)
> In this example, the compiler could not possibly have known I was going to access x.

Right, but it knew you were going to use eval, and to support that, it had to allocate all local variables in the closure. That's why you saw this behavior. The same would happen if you used a 'with' construct.

Re:Introducing Swift by Udo on Monday June 02, 2014 @07:48PM (#7837265)
> Right, but it knew you were going to use eval, and to support that, it had to allocate all local variables in the closure.

Wow, so there is actually special handling in the engine for this? So it does static analysis whenever it can, but not in these two cases?

Re:Introducing Swift by curveship on Monday June 02, 2014 @07:57PM (#7837307)
Yes, the V8 compiler bails out of several optimizations if your function uses eval. You can see this in the profiler: functions which V8 wasn't able to optimize will have an alert sign next to them, and if you click it, it'll tell you what the issue was.
Re:Introducing Swift by anonymoushn on Monday June 02, 2014 @08:35PM (#7837460)
This is a bit troublesome!

  function f() {var x = 99; return function(a,b) {return a(b)};}
  f()(eval, 'console.log(x);')
  ReferenceError: x is not defined
  function f() {var x = 99; return function(a,b) {return eval(b)};}
  f()(eval, 'console.log(x);')
  99
  undefined
Re:Introducing Swift by curveship on Monday June 02, 2014 @08:45PM (#7837511)
Yep, this is as per spec: http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.2 . "Indirect" calls to eval (i.e. assigning eval to another variable, like you did by passing it as a param) are evaluated in terms of the global environment. "Direct" calls, like in your second example, use the local environment.
Re:Introducing Swift by Udo on Monday June 02, 2014 @08:00PM (#7837319)
Very cool, thanks for clearing that up!
Re:Introducing Swift by coldtea on Monday June 02, 2014 @08:52PM (#7837542)
Yes, and in articles describing it (v8), they explicitly warn you to not use "eval" or "with" for the performance impact.
Re:Introducing Swift by Sheepshow on Monday June 02, 2014 @07:11PM (#7837103)
In your example, X is still in scope when f('x') is called. It doesn't require closure to work.
Re:Introducing Swift by Udo on Monday June 02, 2014 @07:32PM (#7837204)
I think you misunderstand what I'm trying to say. The point is not that x should be out of scope (why would it be?)

The original assertion by curveship was that the outer context is not kept alive for the function, and that f() only gets access to the variables it explicitly imports from the outer context. And I thought this might be wrong, so I cooked up the example.

Again, this is not about scope. This is about the fact that the function itself keeps a reference to the entire context it was created in, as opposed to just the things it explicitly imports.

In this, it appears, Javascript works exactly as Ruby, which again makes the entire outer context available through the binding facility.

I'm sorry if that wasn't clear from my description.

Re:Introducing Swift by pjmlp on Monday June 02, 2014 @07:02PM (#7837062)
Swift reuses the Objective-C runtime, so it had to be compatible in terms of memory management.
Re:Introducing Swift by curveship on Monday June 02, 2014 @08:18PM (#7837388)
OK, thanks. I guess that makes sense. Now that the website is working, I see that they're aiming at fairly seamless interop between Swift and Objective-C, so I guess they need a similar memory strategy.
Re:Introducing Swift by kevingadd on Monday June 02, 2014 @07:40PM (#7837239)
This is not accurate. SpiderMonkey and V8 still retain the entire outer scope if any of the variables are used.

See here for an example: https://www.meteor.com/blog/2013/08/13/an-interesting-kind-o...

This bug is still not fixed. There's an issue open for it on the V8 tracker, I believe. It seems to have not gotten fixed in either engine because it's a difficult problem that affects a small subset of JS applications.

Re:Introducing Swift by curveship on Monday June 02, 2014 @08:14PM (#7837369)
So go ahead and run his test. Things have changed :). Memory builds up 1mb/second, then after a few seconds, you'll see it drop back to zero, as the GC runs.

V8 has seen a lot of really nice optimizations to closures over the last year. My favorite is that closures are no longer considered megamorphic.

Re:Introducing Swift by kevingadd on Monday June 02, 2014 @08:37PM (#7837473)
Oh wow, when did that land? I was getting hit by that leak with JSIL in the last couple months. Can you link to the commit?
Re:Introducing Swift by curveship on Monday June 02, 2014 @08:57PM (#7837564)
Not sure the date. I first noticed the change back in April, when I was profiling some code. Ask vegorov: http://mrale.ph/blog/2012/09/23/grokking-v8-closures-for-fun... .
Re:Introducing Swift by krsna on Monday June 02, 2014 @11:12PM (#7837951)
I agree that Swift looks quite promising, though I'm a bit surprised that it doesn't offer any concurrency primitives like Go does. I only say this because "The Swift Programming Language" e-book claims that "it’s designed to scale from 'hello, world' to an entire operating system."