News for hackers. Stuff that matters.
Re:Server APIs Project by duaneb on Tuesday October 25, 2016 @04:15PM (#12791273)
How is the memory management? That was always the downside of objective-c. Does it allow aliasing memory?

If not, I don't see a huge amount that it actually improved over C++. Why should I use swift for server stuff over c++/go/rust?

Re:Server APIs Project by adamnemecek on Tuesday October 25, 2016 @04:27PM (#12791370)
> How is the memory management?

Swift has both, reference types (heap allocated, refcounted) and value types (stack allocated (mostly)). Collections are copy on write which is actually really dank. You don't really think about memory management much (compared with Obj-C). And if you do, I usually wrap it in some sort of abstraction so that I can write it and forget it.

The only modern language out of the three you mention is Rust. Swift is very similar to Rust but a bit higher level (but it seems like the languages will converge, a lot of the planned feature are creeping into Rust space). Swift is also simpler, but this is due to the fact that it's for a somewhat different purpose. A lot of the concepts are the same modulo the syntax. Rust was a major source of inspiration after all.

Writing it feels like writing this C++, JS, Python, Haskell hybrid. It's like the first language I actually enjoy writing (Rust is a better language but I'm not quite fluent).

That being said Swift isn't perfect but I things are getting fixed really quickly.

Re:Server APIs Project by pcwalton on Tuesday October 25, 2016 @06:19PM (#12792250)
I wouldn't say Swift is simpler than Rust. The complexity is just in different places. For instance, Swift leans on OO quite heavily (as it has to for compatibility with Objective-C), and as a result its typechecker is quite a bit more complex: it's a full constraint solver as opposed to Rust's typechecker, which has a much simpler "expansion/contraction" heuristic. Of course, on the other hand, Rust has the whole lifetime system that complicates things.
Re:Server APIs Project by Gankro on Wednesday October 26, 2016 @12:26AM (#12793881)
Yeah totally agreed. Swift is rife with way more special behaviours/magic to try to smooth over sloppy programming and just make stuff work. There's even a standard term for pushing a problem into the compiler: compiler heroics. Where heroics fall down, the language needs extra annotations to help the compiler out (@escaping closures is the most obvious).

Swift also has a lot of slightly more ergonomic but otherwise largely unnecessary features: initializers vs static funcs, guards vs ifs, throws vs returning an enum, fileprivate vs private.

Moving to working on Swift from Rust has led to me really appreciating how simple a lot of Rust really is. There's a lot of "oh it's literally just X".

But the lifetime thing is a huge empowerer of Rust being simpler everywhere else. It means a lot more stuff can be "just X", because X can be made safe.

Re:Server APIs Project by paulddraper on Tuesday October 25, 2016 @06:30PM (#12792337)
Why is COW collection "dank"?
Re:Server APIs Project by bluejekyll on Tuesday October 25, 2016 @09:46PM (#12793283)
And is "dank" good or bad?
Re:Server APIs Project by steveklabnik on Tuesday October 25, 2016 @09:51PM (#12793303)
It usually means "good", though some people use it in an ironic sense to imply something is bad. Kinda like how "bad" can also mean "good" in the right context, but in reverse.

Here I took it to mean "good."

Re:Server APIs Project by paulddraper on Tuesday October 25, 2016 @11:01PM (#12793572)
The definition I am aware of is undeniably negative: "disagreeably damp, musty, and typically cold"
Re:Server APIs Project by steveklabnik on Tuesday October 25, 2016 @11:16PM (#12793634)
Ha! I was so used to the... one I'm used to, that I forgot this obvious one. Seems like my analogy to "bad" was appropriate.

"dank" as in "dank memes" as in "a word stoners use to describe good weed" is how I'm taking it to be used here.

Re:Server APIs Project by paulddraper on Wednesday October 26, 2016 @12:54PM (#12798152)
Ah, well, I wouldn't know anything about that then ;)
Re:Server APIs Project by smitherfield on Wednesday October 26, 2016 @11:28AM (#12797241)
It comes from stoner culture, where it's a sign of high quality when the psychoactive plant matter is still damp and smelly.
Re:Server APIs Project by pjmlp on Tuesday October 25, 2016 @06:12PM (#12792204)
> If not, I don't see a huge amount that it actually improved over C++.

One advantage, from the point of view of someone that likes using C++, is being a safer programming language.

C++ has several features that allow to write safe code, but they only work when working solo, or in a team that accepts and makes use of modern C++.

If you cannot control the team on how they write C++, or the libraries being used, than there is a high probability of the code base just look like "C compiled with C++".

Of course this also applies to Go and Rust vs C++.

Re:Server APIs Project by duaneb on Tuesday October 25, 2016 @06:19PM (#12792251)
> One advantage, from the point of view of someone that likes using C++, is being a safer programming language.

How so? Last I checked swift doesn't have garbage collection (but does have refcounting, which is nearly as good, but still requires modifying algorithms with cycles), and only offer syntactic sugar over existing null pointer semantics (as opposed to the memory ownership guarantees provided by rust). Isn't this the exact same feature set offered by modern C++ with owned_ptr and shared_ptr?

Go + rust both have guaranteed memory safety unless you go out of your way to disable safeguards. How hard is it to shoot yourself in the foot with swift, memory wise? Do you still have to fall back on autorelease pools for tight inner loops, like in objective-c?

Re:Server APIs Project by seandougall on Tuesday October 25, 2016 @11:56PM (#12793767)
It sounds like you're used to manual reference counting in ObjC, which genuinely is a pain. Swift (and modern ObjC) use automatic reference counting, which is much more robust and less dependent on autorelease pools. For one thing, class instances get released when they no longer have a strong reference -- so to answer your specific question, you can totally instantiate a class for just one iteration of a loop. Plus, Swift makes much better use of value types, so you're less reliant on heap allocations in the first place.

I personally cringe whenever I have to go back to a GC and relinquish all control over object lifecycle.

Re:Server APIs Project by pjmlp on Wednesday October 26, 2016 @06:42AM (#12795401)
> I personally cringe whenever I have to go back to a GC and relinquish all control over object lifecycle.

I think it is a matter of which language and which GC.

A few do offer the possibility to control allocation, and sadly a few others that were good at it died in the late 90's.

Re:Server APIs Project by pjmlp on Wednesday October 26, 2016 @01:26AM (#12794066)
No, because in C++ they are optional.

If you work in a team or use libraries, specially binary ones, you have zero guarantees that the code quality and how the memory is managed.

In Swift, RC is compulsory and manually managing memory requires asking the compiler for permission all the time, so there are minimal set of guarantees how the memory will be managed.

Modern C++ is great, and many in the community do push a lot for improving the quality, unfortunately I keep seeing the working enterprise developers just outputting C code compiled with a C++ compiler instead.