Live data from Hacker News

WWDC 2018 What's New in Swift Recap

roadfiresoftware.com

31–40 of 45 posts

Re: WWDC 2018 What's New in Swift Recap

#31

>>New hashing algorithm >>Hash values vary from run to run (so don’t depend on hash values or order) I must be reading this wrong. One of the requirements for a good hash function is determinism - specifically that any given value in the input space maps to exactly one value in the output space.

Note that you can disable this feature, however in most cases it's probably best not to -- the new hasher functionality is actually really cool and a good improvement on the old behavior. If you want to disable it, I think it's a compiler flag.

[* said as someone who's implemented probably a ton of poor hash functions in their time]

Re: WWDC 2018 What's New in Swift Recap

#32
post #10

> Swift 5 (Early 2019): > binary compatibility with future Swift releases I bet this doesn't really happen, though it probably makes the day when it really happens closer. (I don't just mean they might miss the date, but that (1) they miss the date by a lot; and/or (2) they drop binary compatibility from Swift 5; and/or (3) they claim they've achieved binary compatibility but it doesn't out to be true for long, less…

They do provide a public dashboard for tracking progress to ABI stability: https://swift.org/abi-stability/

Whether it turns out there are things missing from that list, who knows, but they're definitely getting closer.

Re: WWDC 2018 What's New in Swift Recap

#34

What was bad about arc4random?

Nothing inherently wrong with it, but it's not available on all platforms that support Swift. The new Random APIs use arc4random() under the hood on Darwin IIRC. There's also no direct equivalent to arc4random() in the new API - you always have to pass a range, which discourages people from using % to reduce the range and introduce modulo bias.

Ah. Like Linux, I guess. Thanks for the info.

Re: WWDC 2018 What's New in Swift Recap

#35
post #31

>>New hashing algorithm >>Hash values vary from run to run (so don’t depend on hash values or order) I must be reading this wrong. One of the requirements for a good hash function is determinism - specifically that any given value in the input space maps to exactly one value in the output space.

Note that you can disable this feature, however in most cases it's probably best not to -- the new hasher functionality is actually really cool and a good improvement on the old behavior. If you want to disable it, I think it's a compiler flag. [* said as someone who's implemented probably a ton of poor hash functions in their time]

I believe the compiler flag just disables the random seed - you can still use the new hasher API

Re: WWDC 2018 What's New in Swift Recap

#36

What was bad about arc4random?

Nothing inherently wrong with it, but it's not available on all platforms that support Swift. The new Random APIs use arc4random() under the hood on Darwin IIRC. There's also no direct equivalent to arc4random() in the new API - you always have to pass a range, which discourages people from using % to reduce the range and introduce modulo bias.

”but it's not available on all platforms that support Swift”

I think that’s a weak argument. arc4random’s source code isn’t platform specific, complex or large and is available under a permissive license, so they could easily put it in the runtime.

I would think they added this because of the modulo argument you give and to give it a better name (there’s nothing wrong with ‘arc4random’ for _a_ random number generator, but _the_ random number generator on a platform should have a simpler name)

Re: WWDC 2018 What's New in Swift Recap

#37
post #14

Earlier quoted context omitted.

The hashing algorithm can be deterministic however hashing relies on a seed. In most cases you want that to be random to prevent certain side channel attacks. For swift, hashing will be deterministic for the lifetime of the program.

wait, hashing relies on a seed?! isn't that a salt/pepper? to be "deterministic for the lifetime of the program" sounds like a pepper is being applied, not that the hash algorithm is different.

This is a more accurate description. The hashing algorithm is 100% deterministic, but the inputs include a random seed from the start of the program to prevent various side channel attacks and to prevent folks from erroneously relying on hashmap ordering.

Re: WWDC 2018 What's New in Swift Recap

#38
post #26

Earlier quoted context omitted.

It isn't too hard to setup two-way binding with KVO if you wanted to. You can have one way binding, you can have binding with a transformer function to go from a number to a string etc. Here's a playground where I did this a while back. You get type safety and nice syntax too. https://gist.github.com/desugaring/828e9880f747678ac5912a070...

It might as well be KVO under the hood, no problem. It's just that annotations can be really handy to indicate a ton of stuff that would otherwise be lines of code. I use it in other languages all of the time.

yeah, I'll agree here. Being able to slap an annotation on a method in C# is one of the major pluses. [Authorize] in ASP.NET MVC (Core as well I believe?), the various ones in Entity Framework, etc. Very useful.

Re: WWDC 2018 What's New in Swift Recap

#39
post #27
post #3

Earlier quoted context omitted.

Vapor apparently gets favorable reviews by those who drank the Kool-Aid: https://vapor.codes/ Never tried it though. I don't select stacks primarily based on programming language.

Vapor looks like the best so far but it's still early days. In theory it has the potential to be extremely fast and memory efficient, but for example they only just got a couple TechEmpower benchmarks up a couple days ago and they ranked very low (#162 on the json test).[1] It goes without saying simplistic benchmarks like this are flawed but at the same time, you have to start somewhere. [1] https://www.techempower.…

JSON performance is super important for a server, far more than for the usual macOS or iOS clients. JSON parsing might be based on the basic JSON parser found in Swift, which isn't fast at all, rather easy to use and secure instead.

It's not super up-to-date but you can see there's definitely some competition even on Swift level in terms of JSON performance. https://github.com/bwhiteley/JSONShootout

Swift JSON encoding/decoding should approach C/C++ levels of performance when optimized for speed.

Re: WWDC 2018 What's New in Swift Recap

#40
post #12

Is there a plan for c++ Interop in swift. Or have they decided that using the obj-c bridging layer is enough.

It's on the list of things that would be nice someday, but it will take a lot of time to get right, and it's not a high enough priority right now. There's a handful of other significant features that will come first, like ABI stability, Ceylon/Rust style ownership checking, first-class concurrency/atomics (async/await, etc.).

That said, Swift's C interop will work if you write an `extern "C"` interface to your C++. Obviously it's not ideal, but people have done projects like llvm-swift[0], with LLVM obviously being a C++ project.

[0]https://github.com/llvm-swift/LLVMSwift

Post reply on HN