News for hackers. Stuff that matters.
Re:Lightweight API Design in Swift by sgt on Tuesday November 26, 2019 @03:17AM (#21636453)
Probably one of the most elegant languages around.
Re:Lightweight API Design in Swift by melling on Tuesday November 26, 2019 @03:57AM (#21636598)
Yes, it’s my favorite language.

Now it needs better cross platform support to be more widely accepted.

Re:Lightweight API Design in Swift by clawoo on Tuesday November 26, 2019 @04:38AM (#21636793)
And a proper IDE and a faster compiler.

Xcode is dreadful with its strange fetish for recompilation even if there were no changes and the compiler is slower with every iteration. The solution put forward for this always seems to be "buy newer hardware".

Re:Lightweight API Design in Swift by mojuba on Tuesday November 26, 2019 @04:56AM (#21636899)
Absolutely. One of the things I hate most is this thinking "run-time is more important than compile-time".

Well the compiler and the IDE are runtimes too, we developers are users too, we sometimes work on our laptops unplugged and we do want our software to be fast and efficient!

Re:Lightweight API Design in Swift by skohan on Tuesday November 26, 2019 @05:43AM (#21637116)
> "run-time is more important than compile-time"

This is a pitfall of Rust as well. I suppose there will always be a tradeoff between stronger static analysis and compilation time, and I'm firmly in the camp that I want my compiler to catch more issues so I don't have unexpected runtime failures, but iteration time matters too, and I'm hopeful improvements can be made in this area.

Re:Lightweight API Design in Swift by mojuba on Tuesday November 26, 2019 @07:31AM (#21637683)
Sometimes you introduce certain restrictions in the language just for the sake of simplifying the compiler. This is allowed, valid and will be understood by the developers.

For example, for decades most static languages required a symbol to be defined before its first usage. Removing this restiction seemed like a nice little cute convenience but the outcome of it is this horrific slowdown of the build process. Personally I would agree to the restriction if I knew the compiler could be 5x faster which is pretty realistic to achieve, it seems.

Re:Lightweight API Design in Swift by skohan on Tuesday November 26, 2019 @08:29AM (#21638066)
Those kinds of restrictions can have their own productivity pitfalls. For instance, it might be the case that requiring declaration prior to usage explicitly will speed up the compiler, but it might also mean that you can't move blocks of code around without paying careful attention to the order of declaration. I think having a permissive compiler, but also being able to profile the compilation process is a reasonable compromise.
Re:Lightweight API Design in Swift by mojuba on Tuesday November 26, 2019 @08:36AM (#21638113)
Possibly, but there are other kinds of compromises such as allowing arbitrary order only within a class, the C++ way. Or another one: the first (quick) pass treats all function and reference type definitions as forward declarations and skips the details. This way the compiler might be able to do more permissive compilation though not 100% accurate like Swift currently does.
Re:Lightweight API Design in Swift by ajconway on Tuesday November 26, 2019 @05:45AM (#21637127)
But run-time is more important, isn't that why we compile stuff with optimizations that take ages to process when building products for the end users?

Compilers are hard, compiler bugs can have a devastating effect on one's software, so it's understandable that developers may prefer to take things slow but safe.

Re:Lightweight API Design in Swift by Gibbon1 on Tuesday November 26, 2019 @06:14AM (#21637280)
My half joke is the optimizations slow down compilers. So people then try to make the compilers faster by increasing the levels of optimization. Which means they have to work harder. So they are slower.
Re:Lightweight API Design in Swift by skohan on Tuesday November 26, 2019 @05:50AM (#21637152)
I guess ideally this should be a tradeoff in the hands of the developer right? I should be able to produce debug builds quickly so that I can iterate quickly, and if I want a super-optimal release build it's fine if it takes longer.
Re:Lightweight API Design in Swift by ajconway on Tuesday November 26, 2019 @05:37AM (#21637091)
In swift things have a module-wide visibility by default, that's why it often rebuilds the entire module after a single change that could implicitly affect other files. The only viable solution at the moment is to break the project into as many small modules as you can.
Re:Lightweight API Design in Swift by skohan on Tuesday November 26, 2019 @05:58AM (#21637193)
It's also useful to profile your compile times. Sometimes the compiler is spending most of its time on some small sections of code.

For instance, I was working on a project where the use of one library constituted 80% of our compile time! The library allows you to declare autolayout constraints using operator overloads (i.e. `foo.top == container.top - 20`) and apparently the amount of type inference was just murdering our compile times. Changing libraries took this project from being awful to work on to quite pleasant.

Re:Lightweight API Design in Swift by ajconway on Tuesday November 26, 2019 @06:49AM (#21637464)
Swift also provides a compiler option specifically for debugging long compilation times: "-Xfrontend -warn-long-function-bodies=100"
Re:Lightweight API Design in Swift by gbrhaz on Tuesday November 26, 2019 @08:56AM (#21638251)
Ah, Cartography. Works great in a small project. We ended up moving to standard anchors for almost everything, with some helper methods to handle things like pinning to superviews.
Re:Lightweight API Design in Swift by gigatexal on Tuesday November 26, 2019 @04:27AM (#21636737)
I hear server-side swift is gaining traction
Re:Lightweight API Design in Swift by ngcc_hk on Tuesday November 26, 2019 @05:59AM (#21637200)
It is very easy to learn and use. Well compared with java and objective c. Learn it and push the app with v 1.0 is a bit hard but it works. In fact the app still there. Great language.
Re:Lightweight API Design in Swift by jbverschoor on Tuesday November 26, 2019 @04:50AM (#21636862)
I'ts def. one of the best designed languages, and has a ton of progress. They're also very agresive with deprecating things that should be changed.
Re:Lightweight API Design in Swift by pharaohgeek on Tuesday November 26, 2019 @08:43AM (#21638154)
I couldn't agree more. I'm anxious to see it build up a rich developer ecosystem like Java has. The availability of so many 3rd party libs for Java is a huge advantage. If Swift gets to that point I can see it taking over all of my server-side development.
Re:Lightweight API Design in Swift by skohan on Tuesday November 26, 2019 @09:05AM (#21638327)
Which types of libraries in particular do you feel are missing?
Re:Lightweight API Design in Swift by seanparsons on Tuesday November 26, 2019 @04:55AM (#21636895)
Words I never thought I'd see attributed to Swift, it's a blend of a Scala like design with Objective-C parts.
Re:Lightweight API Design in Swift by saagarjha on Tuesday November 26, 2019 @04:58AM (#21636908)
It takes many of the good parts of both and wraps it in some very nice syntactic sugar. What's not to like?
Re:Lightweight API Design in Swift by seanparsons on Tuesday November 26, 2019 @09:40AM (#21638607)
Credit where credit is due, they did unicode "right", if you need to deal with those shenanigans it's really nice.

However it also adopts a bunch of the bad parts like having variance but not really having a way to handle it. Last I remember the Equatable instance for tuples was just magic, it was impossible to rely on it with the types. Even maybe 6 months ago when I last tried this if you write some code that appends maybe 6/7 arrays together immutably the compiler would go into an exponential spin.

The project I'm working on ending up dumping it entirely and moving over to being a web project written in TypeScript because it was so bad. Part of that being a laundry list of problems with the surrounding tooling like SourceKit which may or may not still apply.

Re:Lightweight API Design in Swift by tigershark on Tuesday November 26, 2019 @04:32AM (#21636765)
F# and Kotlin seem better to me, and don’t have that hideous syntax for the closures. But it’s for sure another world compared to the awful objective c.
Re:Lightweight API Design in Swift by mojuba on Tuesday November 26, 2019 @04:50AM (#21636865)
I wouldn't say Kotlin is significantly better than Swift in terms of syntax, they are largely similar to the point you sometimes think: someone copied this from the other, I wonder who was the first.

To me personally though the showstopper for Kotlin is that it runs on Java VM. That was the design goal of course, i.e. to become a major "upgrade" of Java esp. on Android. Java VM (with its GC) is a creation of the pre-mobile era when all we had was desktop computers, ever growing processing power and an assumption that you have infinite supply of electric power. It's a different philosophy and design. I think Google's choice of using it on a mobile platform was unfortunate, though at the time (i.e. before the iPhone) many popular mobile platforms did run on Java VM so it seemed like a natural choice.

Re:Lightweight API Design in Swift by pjmlp on Tuesday November 26, 2019 @06:03AM (#21637220)
Swift's ARC implementation has a little bit of performance catchup to do in regards to tracing GCs.

https://github.com/emmericp/ixy

Re:Lightweight API Design in Swift by skohan on Tuesday November 26, 2019 @08:57AM (#21638254)
IMO this example should be taken with a grain of salt, since at a cursory glance it looks like they are leaning heavily on reference-types, which is not really idiomatic swift, and is a worst-case for tightly-looping code which this is. I would love to spend even a half hour trying to optimize this code to see what the results could be, but there is specialized hardware required to run the benchmark, so it's not really practical for 3rd parties to attempt to achieve a better result.

It's fair to say that ARC has performance issues, but the story is a bit more complex than that. By relying heavily on value types, it's possible to write Swift code which carries very little ARC cost (although there are additional issues with copy-on-write performance). Also ARC is more memory efficient than most GC solutions, so there are tradeoffs involved.

Re:Lightweight API Design in Swift by pjmlp on Tuesday November 26, 2019 @09:21AM (#21638460)
Languages with tracing GC implementations also have value types, thus they would keep winning.

Top performance reference counting implementations are tracing GC in disguise.

Re:Lightweight API Design in Swift by algerd on Tuesday November 26, 2019 @05:42AM (#21637113)
Re:Lightweight API Design in Swift by singularity2001 on Tuesday November 26, 2019 @05:59AM (#21637198)
Kotlinc takes 10 seconds to compile Hello World, 30 seconds with wasm target. Seems almost conceptually unfixable.
Re:Lightweight API Design in Swift by pjmlp on Tuesday November 26, 2019 @06:05AM (#21637228)
swiftc isn't also not that blazing fast.

For me Delphi, .NET Native, D are some of the targets to beat in compilation time.

They all share a common trait though, not built on top of LLVM.

Re:Lightweight API Design in Swift by skohan on Tuesday November 26, 2019 @09:09AM (#21638364)
I would say Rust is a better point of comparison for Swift given the emphasis both languages have on strong type systems and static analysis. Neither one is super fast, but 10 seconds for a hello world is insanely slow.
Re:Lightweight API Design in Swift by pjmlp on Tuesday November 26, 2019 @09:20AM (#21638449)
And both are slowed down by LLVM.

F#, Standard ML, OCaml and Haskell also have such strong type systems.

Re:Lightweight API Design in Swift by jbverschoor on Thursday November 28, 2019 @01:20PM (#21659246)
Swift was out before kotlin.
Re:Lightweight API Design in Swift by kitsunesoba on Tuesday November 26, 2019 @10:00AM (#21638782)
Dunno about F# as I’ve never written it, but Kotlin, while not a bad language, to me mostly feels like Swift with extra syntactic friction points. Among other things, its property getter/setter syntax feels awkward compared to those Swift.
Re:Lightweight API Design in Swift by Razengan on Tuesday November 26, 2019 @06:21AM (#21637320)
What’s hideous about Swift closures (though I guess everything has always room for improvement) and how are F# and Kotlin better?
Re:Lightweight API Design in Swift by tigershark on Tuesday November 26, 2019 @11:40AM (#21639897)
(s1: String, s2: String) -> Bool in return s1 > s2 } In nested closures you can’t use the $0 syntax, swift type inference is pretty poor compared to F# and so a lot of time I have to explicitly specify the types and the in is much less clear than => or ->. To make it even more frustrating I have to specify the @escaping attribute in a lot of methods that accept closures as an argument.
Re:Lightweight API Design in Swift by jbverschoor on Thursday November 28, 2019 @01:23PM (#21659265)
yes, because of memory management. It's a good thing.
Re:Lightweight API Design in Swift by rimliu on Tuesday November 26, 2019 @07:13AM (#21637588)
This puzzled me too. Ok, blocks in Obj-C do look, err… interesting, but closures in Swift are totaly fine.
Re:Lightweight API Design in Swift by saagarjha on Tuesday November 26, 2019 @09:45AM (#21638637)
Maybe the use of "in"?
Re:Lightweight API Design in Swift by saagarjha on Tuesday November 26, 2019 @04:48AM (#21636843)
> the awful objective c

:(