News for hackers. Stuff that matters.
Re:Swift UTF-8 String by ilovecaching on Friday March 22, 2019 @12:04AM (#19459518)
Is anyone using Swift outside of Apple specific stuff professionally? When they first announced swift it felt like it might catch on as general purpose gced language. The language itself is quite beautiful in a lot of ways (although being OO was obviously an awful step backwards). But it feels like it's still just the crazy language Apple uses, just like Objective-C was.
Re:Swift UTF-8 String by phamilton on Friday March 22, 2019 @12:24AM (#19459589)
We've been eye-ing it for a while at remind.com. Our hangup has been that we're heavily aws focused, but https://github.com/amzn/smoke-aws is looking promising.

We're interested because it's one of a handful of statically typed functional programming languages. Haskell/Ocaml are great as ML type languages, but it's a big paradigm shift for a team to jump into. Rust still has a pretty decent learning curve. Swift seems to have landed nicely in the "anyone can pick it up" territory. Kotlin is also in that territory, but the JVM is a beast.

For now, we're heavily focused on Typescript as the statically typed functional language, and we leverage types pretty aggressively (conditional types, discriminant unions, etc). Our iOS devs bring a lot of the Swift style over to our backend Typescript systems and from what I've experienced I think Swift absolutely will have a place in backend development.

Re:Swift UTF-8 String by cageface on Friday March 22, 2019 @12:31AM (#19459620)
Swift is a nice language but I think the reliance on ref counting is going to limit its adoption. You have to work a lot harder to avoid reference cycles in Swift than you do in a garbage collected language. Unless GC latency is a deal breaker for your problem domain it’s not worth the extra effort.

My money is on Rust for really low level stuff and Kotlin for anything where JVM overhead is acceptable.

Re:Swift UTF-8 String by saagarjha on Friday March 22, 2019 @12:40AM (#19459663)
It really depends on what you're doing. A lot of the time, neither garbage collection pauses nor reference cycles are an issue; and when they are it's typical that one or the other will solve the issue.
Re:Swift UTF-8 String by cageface on Friday March 22, 2019 @02:41AM (#19460110)
If GC pauses aren't an issue for your app then you're better off with a full-blown GC because it's a lot easier to code for. Reference counting, as used in Swift, forces you to think a lot about cases where you might be creating reference cycles and memory leaks. GCs can figure this out for you and take that burden off the programmer.
Re:Swift UTF-8 String by millstone on Friday March 22, 2019 @04:19AM (#19460453)
One of the major advantages of reference counting is that it's easier to integrate with other languages. For example you can manipulate Swift objects from C via CoreFoundation, which then allows them to be used from C++, Rust, whatever.

GC'd languages have some support (JNI, etc) but they require handles, pinning, write barriers, etc. which ends up being more complicated and less flexible.

Re:Swift UTF-8 String by cageface on Friday March 22, 2019 @05:29AM (#19460794)
Right, which is one of the reasons it makes sense for Apple to use it, since they have a lot of lower level C API to interact with.

For more general purpose backend work this is not usually a major consideration though, which is one of the reasons I predict most backend work will continue to be done in a GC language.

Re:Swift UTF-8 String by saagarjha on Friday March 22, 2019 @03:38AM (#19460296)
Yes, but reference counting doesn't have unpredictable pauses, which can be important in certain situations. That's what I was trying to say above.
Re:Swift UTF-8 String by WanderPanda on Friday March 22, 2019 @04:34AM (#19460525)
I would assume good debug-tooling should make spotting such cycles quite easy, why is this even considered a problem?
Re:Swift UTF-8 String by cageface on Friday March 22, 2019 @05:25AM (#19460778)
It’s not easy and iOS developers spend a lot of time explicitly breaking ref cycles in code and tracking down resource leaks. I’ve seen a lot of code from experienced iOS devs that gets it wrong.
Re:Swift UTF-8 String by myko on Saturday March 23, 2019 @10:07AM (#19470496)
What kinds of mistakes do you see? Forgetting to use capture lists entirely? Using them improperly? Not making delegates weak properties?
Re:Swift UTF-8 String by phamilton on Friday March 22, 2019 @02:45AM (#19460130)
> You have to work a lot harder to avoid reference cycles in Swift

It depends on how you use it. As I understand it, if you use enums everywhere it all sort of works out. If you start mixing in structs, there are certainly a lot of minefields.

Re:Swift UTF-8 String by ilovecaching on Friday March 22, 2019 @12:51AM (#19459715)
What do you see as the advantage of Rust or ref counting?
Re:Swift UTF-8 String by cageface on Friday March 22, 2019 @02:46AM (#19460131)
I've just read the Rust docs and not written any code so I'm probably the wrong person to ask but Rust's ownership rules seem to make it possible to eliminate a lot of dynamic allocations in the first place.

Ref counting can beat GC if you're in a domain where GC pauses can be an issue. Things like games, for example. Although I understand state-of-the-art GCs can also be fast enough to use for these kinds of applications in some cases now. Ref counting can also be more memory efficient than GCs.

Re:Swift UTF-8 String by pjmlp on Friday March 22, 2019 @04:37AM (#19460537)
Ref counting can also be slower than tracing GC when getting rid of complex data structures, heavy multi-threaded code and can lead to stack overflows if destructors are incorrectly written.
Re:Swift UTF-8 String by pjmlp on Friday March 22, 2019 @01:56AM (#19459949)
The JVM is indeed a beast in available tooling, libraries and production monitoring.
Re:Swift UTF-8 String by repolfx on Friday March 22, 2019 @04:50AM (#19460598)
Kotlin has an LLVM backend these days and can compile to native binaries. It's more Swift-like, then.
Re:Swift UTF-8 String by ilovecaching on Friday March 22, 2019 @12:50AM (#19459711)
I don't really consider a language to be functional without a concise application and composition operator (also automatic currying and partial application). How can you be functional if you don't have the basic operators for combining and applying functions?
Re:Swift UTF-8 String by bgorman on Friday March 22, 2019 @01:29AM (#19459861)
If you have automatic partial application you lose the ability to have multi-arity functions. Functional programming is about functions, not operators. In Clojure you can compose and partially apply functions with the normal functions "comp" and "partial".

https://github.com/clojure/clojure/blob/clojure-1.9.0/src/cl...

https://github.com/clojure/clojure/blob/clojure-1.9.0/src/cl...

Re:Swift UTF-8 String by lkschubert8 on Friday March 22, 2019 @11:38AM (#19463584)
Automatic currying and partial application are really just nice to haves though. You can manually do both as long as the language supports higher order functions.
Re:Swift UTF-8 String by ilovecaching on Friday March 22, 2019 @12:51AM (#19459713)
It looks like Swift has automatic currying though, so that's pretty close.
Re:Swift UTF-8 String by dbaupp on Friday March 22, 2019 @02:33AM (#19460082)
It doesn't have automatic currying. What code/docs are you getting that impression from?
Re:Swift UTF-8 String by plorkyeran on Friday March 22, 2019 @11:32AM (#19463522)
Swift used to have a special syntax for defining automatically curried functions, but it was removed in Swift 3: https://github.com/apple/swift-evolution/blob/master/proposa...
Re:Swift UTF-8 String by dbaupp on Friday March 22, 2019 @10:26PM (#19468673)
Indeed, and the compiler still had the relicts of that functionality at least until Swift 4. I'm wondering how they got the impression Swift still has currying, given it sounded like a recent "discovery".
Re:Swift UTF-8 String by bbrian on Friday March 22, 2019 @12:16AM (#19459562)
Google are beginning to use it for Tensorflow: https://www.youtube.com/watch?v=s65BigoMV_I

There's a course currently running in University of San Francisco run by Fast.ai which is using Swift-Tensorflow taught by Chris Lattner for two lessons: https://www.usfca.edu/data-institute/certificates/deep-learn...

Not exactly what you asked, but pertinent.

Re:Swift UTF-8 String by ilovecaching on Friday March 22, 2019 @12:48AM (#19459702)
I don't expect that will do very well. ML is already crowded, and Python is already solidly at the top. Having worked in ML myself, no one would switch if it meant dealing with a real statically typed language they could hack away at easily in a repl or jupyter notebooks, or access mypy, numpy, scikit, etc. ML is an ecosystem of tools that are all in Python currently.
Re:Swift UTF-8 String by jimmy_dean on Friday March 22, 2019 @01:23AM (#19459842)
Just a side-note. Swift comes with an repl and has support in Jupyter and Google Colab for whatever that's worth. As you mentioned the numerical computing ecosystem is just not anywhere close to Python or even Julia. There is a silver lining in that Swift has pretty decent Python interoperability.
Re:Swift UTF-8 String by orbifold on Friday March 22, 2019 @08:22AM (#19461827)
In Swift you can just write

import Python

var np = Python.import(“numpy”)

And can then use numpy as you would normally. Same goes for plotting.

Re:Swift UTF-8 String by sooheon on Friday March 22, 2019 @12:08AM (#19459534)
Jeremy Howard and Chris Lattner are starting to push Swift for Tensorflow:

- https://www.github.com/tensorflow/swift

- https://www.fast.ai/2019/03/06/fastai-swift/

Re:Swift UTF-8 String by pjmlp on Friday March 22, 2019 @01:54AM (#19459943)
They must push it really well for it to ever be considered an alternative to Julia, ML.NET, Python/C++, Deeplearning4j on Windows.
Re:Swift UTF-8 String by peferron on Friday March 22, 2019 @12:57AM (#19459749)
Sibling comments mention Chris Lattner. For readers that might not know him, he's the main inventor of Swift. Him pushing Swift should not necessarily be taken as a sign of general community enthusiasm.

I would love to see more Swift on the backend. It's surprisingly hard to find a language that's concise, expressive, statically typed, and easily accessible to beginners. Swift checks all these boxes.

That being said, it's much easier to succeed on the front-end when the only competitor is Objective-C (see: JavaScript), than on the backend when the competitors are Go, Rust, Elixir, Python, Node, C++, Java and more, all with large ecosystems already in place.

Swift may succeed in a niche, and "Swift for TensorFlow" appears to be an attempt at that, but I don't think it will become ubiquitous (call it traditional HN negativity).

Re:Swift UTF-8 String by the_duke on Friday March 22, 2019 @03:41AM (#19460305)
Swift is a great language.

The main problem for me is that it's still very Apple centric. Other platforms are still very second class.

For Linux, there are only Ubuntu packages. Even on Arch which is usually front of the pack with these things, there are only brittle third party (AUR) packages.

Windows support is even worse.

Re:Swift UTF-8 String by pjmlp on Friday March 22, 2019 @01:50AM (#19459924)
He started a podcast last year to promote Swift outside Apple platforms, it lasted three episodes.
Re:Swift UTF-8 String by saagarjha on Friday March 22, 2019 @03:40AM (#19460302)
Which podcast are you talking about?
Re:Swift UTF-8 String by pjmlp on Friday March 22, 2019 @03:43AM (#19460317)
Re:Swift UTF-8 String by saagarjha on Friday March 22, 2019 @03:44AM (#19460321)
As far as I can tell, that podcast was started earlier this year, and is still active?
Re:Swift UTF-8 String by pjmlp on Friday March 22, 2019 @03:56AM (#19460374)
Right, I was wrong about the start date, on my mind it was started in December.

As for being active, no signs of life since 08th February, more than one month without updates.

Re:Swift UTF-8 String by saagarjha on Friday March 22, 2019 @04:02AM (#19460389)
There's still stuff going on on the GitHub repository: https://github.com/SwiftCommunityPodcast/podcast
Re:Swift UTF-8 String by pjmlp on Friday March 22, 2019 @04:34AM (#19460524)
So in one and half months they haven't found time nor a volunteer willing to do another podcast?

My favourite podcasts have weekly and bi-weekly updates.

Re:Swift UTF-8 String by BigWhale on Friday March 22, 2019 @08:35AM (#19461918)
Yeah, he can't even release a podcast episode whenever you want him to. Does he not know he won't make it to your list of favorite podcasts? Why does he even wake up? Lattner is such a loser.
Re:Swift UTF-8 String by pjmlp on Friday March 22, 2019 @08:41AM (#19461969)
If he cares about actually grooming a community outside Apple platforms, maybe.
Re:Swift UTF-8 String by Razengan on Friday March 22, 2019 @01:05AM (#19459780)
For me, it's the best language for game development that I've seen ever since I wanted to make my own games as a kid.
Re:Swift UTF-8 String by ta7775466 on Friday March 22, 2019 @01:15AM (#19459812)
They'll need to do an awful lot more on their IDE for that to happen.

That GUI drag'n'drop onto code... ugh.

Re:Swift UTF-8 String by accatyyc on Friday March 22, 2019 @04:21AM (#19460460)
That's just a convenience thing. I've worked in Xcode for nearly 10 years and I never use that feature. Good feature for teaching though. But if you hate it, just don't use it.
Re:Swift UTF-8 String by eridius on Friday March 22, 2019 @12:23AM (#19459586)
Unless you consider reference counting to be a form of GC¹, Swift is not a GC'ed language.

¹It technically is, but most people don't mean reference counting when they say GC.

Re:Swift UTF-8 String by pjmlp on Friday March 22, 2019 @01:52AM (#19459932)
It doesn't matter what people think, rather CS definition.

Software Engineering is not about what people think, rather what is technically correct.

Re:Swift UTF-8 String by arebours on Friday March 22, 2019 @02:53AM (#19460155)
Well.. what is technically correct depends on a definition. And there are customary/practical definitions too. And sometimes definitions are tainted by context, like in "is this gc or ref counting language".
Re:Swift UTF-8 String by pjmlp on Friday March 22, 2019 @03:41AM (#19460306)
Which should be "is this tracing GC or ref counting language".

Naturally when in some juriditions one is allowed to call themselves engineers after a 6 months bootcamp we land in such customary/practical definitions.

Re:Swift UTF-8 String by eridius on Friday March 22, 2019 @01:32PM (#19464803)
Even wikipedia admits that most people mean tracing GC when they say GC.

What exactly are you trying to accomplish here?

Re:Swift UTF-8 String by pjmlp on Friday March 22, 2019 @03:28PM (#19466025)
Advocating learning CS properly.
Re:Swift UTF-8 String by eridius on Friday March 22, 2019 @01:31PM (#19464794)
It certainly does matter because the question is what did the grandparent mean.
Re:Swift UTF-8 String by pjmlp on Friday March 22, 2019 @06:11PM (#19467477)
Some people want to improve their skills, others don't.