News for hackers. Stuff that matters.
Re:SwiftWasm: Run Swift in Browsers by _bxg1 on Friday May 10, 2019 @03:54PM (#19881629)
This could be really cool given that Swift is already very JavaScript-like (Edit: TypeScript, really). A JavaScript-like that you can run on the web and is just faster out of the box is appealing.

Now if only Apple would put more effort into cross-platform support for Swift...

Re:SwiftWasm: Run Swift in Browsers by matthewmacleod on Friday May 10, 2019 @06:19PM (#19882804)
You're getting a bit of flak for this, but I actually think it's a valid comparison.

While it's not intentional, but there's a fair level of similarity between the techniques I find myself using in Typescript and Swift – to the point where I've been able to transcribe some Swift code into Typescript when porting between platforms. Something to do with the "feel" of the language, maybe?

Swift is definitely one of my favourite languages to work with – something about the style of programming it invites just seems to click with me. I agree it would be really nice to use it more extensively, because so far it's just been a single-purpose language and that seems like a bit of a shame.

Re:SwiftWasm: Run Swift in Browsers by nicoburns on Saturday May 11, 2019 @07:05AM (#19885605)
I agree. And I think Rust is like JS too. I think it's the mix between functional and imperative code.

Under the hood, JS and python are very similar, bit idiomatic JS and idiomatic Python couldn't me different. To me, idiomatic Swift/Rust feels like idiomatic JS, whereas idiomatic Go is more like idiomatic Python.

Re:SwiftWasm: Run Swift in Browsers by jjtheblunt on Friday May 10, 2019 @04:10PM (#19881753)
Swift is not at all Javascript-like, I think. Interesting.
Re:SwiftWasm: Run Swift in Browsers by hellofunk on Friday May 10, 2019 @05:14PM (#19882297)
Swift is like JavaScript/TypeScript only if you don't know Swift that well...

They are so different, only very superficial comparisons of syntax would lead to such a statement.

Re:SwiftWasm: Run Swift in Browsers by _bxg1 on Friday May 10, 2019 @06:12PM (#19882753)
I don't know Swift that well, but this was my immediate impression when I spent a couple hours with it (and I've used C, C++, Java, C#, Python, etc.).

The array/dictionary literal syntax (especially dictionaries) was probably the main thing. Lots of languages have similar array syntax (though fewer have the auto-grow behavior), but I can't think of another C-like language with first-class, dedicated dictionary syntax.

C-likes also don't often have first-class functions/closures, or named function parameters (JS doesn't technically have the latter, but it effectively does with object destructuring; this is one of the syntax niceties Swift added).

I didn't mean to imply they had an overall similar set of features, so much that someone who's comfortable with TypeScript would have a pretty easy time warming up to Swift, which matters on the web.

Re:SwiftWasm: Run Swift in Browsers by hellofunk on Saturday May 11, 2019 @12:28AM (#19884563)
Syntax is ultimately a fairly minor aspect of languages. The reference and value semantics, the memory management, the type system, the language runtime, these are what really create a development experience in a particular language. And they are on nearly opposite sides of the spectrum between Swift and JavaScript. If you are only superficially doing something in the language, a somewhat trivial project or just experimenting, then they might seem more similar than they really are.
Re:SwiftWasm: Run Swift in Browsers by paavohtl on Saturday May 11, 2019 @09:09AM (#19885970)
> C-likes also don't often have first-class functions/closures

I think C is the only remaining C-like language not to have first-class functions. And there are compiler extensions for that too.

Re:SwiftWasm: Run Swift in Browsers by _bxg1 on Saturday May 11, 2019 @10:31AM (#19886362)
My understanding is that in cases like Java and C++, the lambdas aren't truly first-class; they come with limitations. I could be wrong.
Re:SwiftWasm: Run Swift in Browsers by hellofunk on Saturday May 11, 2019 @03:46PM (#19888028)
That's true about Java but not C++. C++11 introduced true lambdas, but Java's idea of lambdas is rather laughable by comparison and nowhere near as flexible.
Re:SwiftWasm: Run Swift in Browsers by bobbylarrybobby on Friday May 10, 2019 @05:54PM (#19882606)
Right, both have sort of C-style syntax. That’s pretty much the beginning and end of their similarities.
Re:SwiftWasm: Run Swift in Browsers by robbyking on Friday May 10, 2019 @04:08PM (#19881734)
How is Swift JavaScript-like?
Re:SwiftWasm: Run Swift in Browsers by _bxg1 on Friday May 10, 2019 @04:12PM (#19881765)
Syntactically it's like someone took TypeScript and said, "what are a couple of tweaks we can perform to make it slightly more ergonomic, and also how do we get rid of the garbage collector".
Re:SwiftWasm: Run Swift in Browsers by jdmoreira on Friday May 10, 2019 @05:28PM (#19882412)
No. They are both typed languages but the feature set is not even comparable. Swift is a huge language
Re:SwiftWasm: Run Swift in Browsers by _bxg1 on Friday May 10, 2019 @05:36PM (#19882477)
I'm not saying they're equivalent, I'm saying if you're used to reading TypeScript then Swift will be very familiar, syntactically. That matters if you're thinking about splitting your codebase across two languages.
Re:SwiftWasm: Run Swift in Browsers by boringuser1 on Friday May 10, 2019 @04:11PM (#19881756)
>Now if only Apple would put more effort into cross-platform support for Swift...

You made the mistake of thinking Swift is a programming language and not just the Apple API.

Re:SwiftWasm: Run Swift in Browsers by _bxg1 on Friday May 10, 2019 @04:16PM (#19881799)
Swift currently supports Linux and has unofficial support for Windows. It's open-source and compiles via LLVM. Commercially Apple has been unenthusiastic about fleshing out its support for non-Apple platforms, but the open-source community has partly filled that gap and there's lots of enthusiasm in the community. Given the recent decline in Apple's hardware sales, they could be heading for a Microsoft-like rebirth into a company that's forced to play nicer with others.

https://forums.swift.org/t/swift-as-a-cross-platform-languag...

Re:SwiftWasm: Run Swift in Browsers by boringuser1 on Friday May 10, 2019 @04:20PM (#19881849)
There is almost zero application for Swift outside of an Apple environment. I'm willing to bet there is precisely zero production code written in Swift for Windows (or Linux).

Anyhow, the Windows API (.net, C#) is better and has a brighter future and present.

Re:SwiftWasm: Run Swift in Browsers by _bxg1 on Friday May 10, 2019 @04:26PM (#19881904)
Like I said, Windows support is currently middling. I would bet there's some Linux production code in Swift, though not much. But both of these are cultural problems, not technical ones. If Apple said tomorrow, "we're going to go all-in on making Swift a universal programming language", thousands of developers would cheer and jump on-board. The main thing holding it back right now is lack of confidence in its support; people don't want to invest in a new cross-platform codebase that might have its legs cut out from under it in a couple of years.

Swift is much closer to the metal than .NET, and it has very innovative syntax features. It's more analogous to Rust than to C#. .NET is a strong cross-platform ecosystem, but it's silly to say "we don't need any others because this one's good enough". It's not even the strongest one that currently exists - probably the JVM is. It honestly just sounds like you're hating on Apple for the sake of it.

[dead]
Re:SwiftWasm: Run Swift in Browsers by dang on Saturday May 11, 2019 @02:07AM (#19884829)
Please don't be snarky or argue in the flamewar style.

https://news.ycombinator.com/newsguidelines.html

Re:SwiftWasm: Run Swift in Browsers by _bxg1 on Friday May 10, 2019 @04:40PM (#19882025)
Superficially it has a lot in common with JavaScript (really, TypeScript), but like Rust it compiles to a native binary and doesn't need a runtime environment (C# and Java do). Also like Rust, it frees the user from manually managing memory, despite lacking a garbage collector. This combination of features makes both languages very exciting. I'm not aware of any others right now that can claim the same.

I also haven't heard of it being outperformed by Java and C#; do you have a source for that claim?

Re:SwiftWasm: Run Swift in Browsers by bluk on Friday May 10, 2019 @11:55PM (#19884454)
In microbenchmarks like https://benchmarksgame-team.pages.debian.net/benchmarksgame/... / https://benchmarksgame-team.pages.debian.net/benchmarksgame/... , Swift is mostly equivalent to Java with a few outliers both for/against Swift. Rust outperforms Swift fairly consistently and sometimes quite considerably. Of course, real apps may be different.

The book iOS and macOS Performance Tuning ( https://www.amazon.com/iOS-macOS-Performance-Tuning-Objectiv... ) has pretty damning benchmarks against Swift versus Objective-C even without using any tricky optimizations (not what you originally asked but something to consider). Of course the whole book (written by a former Apple engineer IIRC) is pretty much full of performance gotchas across many Apple frameworks/APIs, but the chapter on Swift was pretty harsh and basically said Swift fails to live up to its name versus Objective-C (at least at the time the book was written).

I think most people think that Swift performs like Rust/C++/C since it doesn't have a garbage collector and imagine ARC is providing relatively free memory management, but it seems Swift performs closer to languages with a garbage collector due to the various design constraints on the language (interoperability with Objective-C, ARC isn't free, and maybe without the explicit lifetime/ownership declarations in the code like Rust, ARC can't be optimized as well).

Re:SwiftWasm: Run Swift in Browsers by _bxg1 on Saturday May 11, 2019 @10:33AM (#19886371)
That's interesting and surprising. I definitely had the perception you described toward the bottom.
Re:SwiftWasm: Run Swift in Browsers by favorited on Friday May 10, 2019 @04:22PM (#19881877)
I know multiple teams who have Swift in production on Linux servers
Re:SwiftWasm: Run Swift in Browsers by boringuser1 on Friday May 10, 2019 @04:26PM (#19881906)
Alright, well, don't do that.
Re:SwiftWasm: Run Swift in Browsers by Eric_WVGG on Friday May 10, 2019 @05:13PM (#19882290)
Why not? Dive in, the water’s great.

https://vapor.codes

Re:SwiftWasm: Run Swift in Browsers by abacadaba on Friday May 10, 2019 @06:38PM (#19882936)
ballsy slogan they got there
Re:SwiftWasm: Run Swift in Browsers by Eric_WVGG on Sunday May 12, 2019 @06:24PM (#19894973)
yeah their marketing isn't great
Re:SwiftWasm: Run Swift in Browsers by maxdesiatov on Friday May 10, 2019 @05:11PM (#19882264)
Why not?