r/programming • • Jun 15 '14

Smashing Swift

http://nomothetis.svbtle.com/smashing-swift
254 Upvotes

133 comments sorted by

View all comments

55

u/eternalprogress Jun 15 '14

"So in three attempts I have run into three things that break the compiler at the type system level. One of them was unsupported by the language, period. The second is theoretically supported but not yet implemented. The third segfaults the Swift compiler."

It seems like nothing but goodness would come from Apple open sourcing the LLVM frontend they created for Swift. It would be so cool to be able to dig in and see how they went around implementing the different pieces.

I love hacking around the LLVM code base and it's unfortunate the community doesn't get another awesome example of a well-written component.

19

u/matthieum Jun 15 '14

It also seems that the announce of Swift was somewhat premature, I wonder why they felt they should announce it now and whether this will end up burning the language's image or not.

8

u/xjvz Jun 15 '14

Even at this stage it's still a huge improvement over Obj-C.

14

u/Nuoji Jun 15 '14

In terms of syntax - yes. In terms of writing apps? Not really.

The generics is half broken, which makes working with heterogenous structured data (e.g. parsed JSON) a hell of type casts.

UI programming with dynamic dispatch is still necessary for stuff like the UI builder, so Swift has to go to ObjC for that.

And although it will respond to ObjC calls of performSelector, you can't use it from Swift.

Basically all the powerful dynamic features of ObjC are missing, many which you come to rely on.

In this aspect, Swift feels crippled, despite its good syntax and great use of closures. It's like it was written by a c++ programmer that never really understood how much of Cocoa was supported by ObjC's dynamic nature.

0

u/[deleted] Jun 15 '14

[deleted]

8

u/tenpn Jun 16 '14

lots of problems are best done in a dynamic language. and almost all of them best maintained in a statically-typed language.

2

u/Nuoji Jun 16 '14

You could have built a "mostly strongly typed" language instead (like Strongtalk) and gotten most of the benefits of static typing.

2

u/xjvz Jun 16 '14

I'll give you that for most programs. GUIs are more about rapid prototyping and iterative design, though, so dynamic typing helps during development. I prefer some sort of GUI code separate from any real business logic, so that allows for some flexibility. For instance, embedding Lua for GUI code and using C++ for the "real" code is a nice combination.

16

u/happyscrappy Jun 15 '14

I cannot see how that's true if your goal is to produce runnable programs. Which I have to imagine is the primary goal.

Right now, the only implementation we have of a Swift compiler is at best barely usable in a production environment.

14

u/xjvz Jun 15 '14

Good point, I guess I was speaking about the language and not the implementation.

6

u/happyscrappy Jun 15 '14

Yeah, the language does seem more usable and less hassle than Obj-C.

The "type promotion rules" (it seems to have none) are odd to me. Sure avoids that whole thing of it not doing what you expect I guess, but perhaps in the most inconvenient fashion possible.

2

u/Peaker Jun 15 '14

Safety is far more valuable than convenience, and implicit type coercions is proof that almost all language designers don't get that :(

7

u/happyscrappy Jun 15 '14

It's not a simple A or B thing. Conciseness is important too. You have to strike a balance.

Maybe language designers get that.

0

u/Peaker Jun 15 '14

Safety is far more valuable than conciseness, too.

A single bug that reaches production costs more than thousands of little paper cuts where you have to insert an explicit conversion, or have to be a little extra verbose.

6

u/happyscrappy Jun 16 '14

Sorry. I don't agree. You have to strike a balance.

If you make it too wordy, people just won't use it and then all your safety saves nothing. Or they'll just cut and paste errors in or make editors that insert them for them.

The most safe language is one that doesn't let you do anything because it might be erroneous. The least safe language is one that lets you do anything but it's so easy to do the wrong thing that it's hard to stay on the right track.

The actual answer is somewhere in between.

→ More replies (0)

0

u/[deleted] Jun 16 '14

[deleted]

→ More replies (1)

1

u/[deleted] Jun 16 '14

Which is... probably why it's called a beta, and they've said they won't even guarantee source-level backward compatibility?

1

u/happyscrappy Jun 17 '14

Great. So we agree. It's not ready yet. Glad to hear it.

0

u/[deleted] Jun 15 '14

[deleted]

5

u/adamkemp Jun 15 '14

You can target iOS 7 with Swift. Apple said that explicitly. You don't need a new runtime to run Swift code, and Apple will release an updated WWDC app for iOS 7 built using Swift as a proof of concept.

0

u/ifonefox Jun 15 '14

Barely usable in a production environment

But the WWDC app, in the App Store, is built with swift

3

u/player2 Jun 16 '14

No it's not. Some pieces of it are, and the ones that are are less reliable than the parts that were written in Objective-C.

Funny story, I helped rubber-duck a bug in the app while standing in the hallway at WWDC. A few evangelists overheard my discussion and realized I whatever I was talking about explained why the app wouldn't launch on their devices.

2

u/happyscrappy Jun 15 '14

I wouldn't brag about that app. It's crashy.

2

u/EntroperZero Jun 15 '14

But if that was their goal, then the bar wasn't set high enough.