154 points · by doener · 8y ago · 239 comments
”One of the best and most annoying things about Objective-C is that it has C in it. This has been hugely important for Objective-C in practice, because if you run into a performance problem with objc_msgSend, you can always rewrite that algorithm in C. That’s really, really, really important for Objective-C being successful in both in the days of NeXT on 16 MHz processors and also today for the low-level code that people are writing.”
This is indeed a great thing about Objective-C: it’s an improved C with a tight set of runtime features that help build interactive applications.
There’s a need for such a language, and I’m sad that so much of the rhetoric from Apple and the Swift community is working on the assumption that Obj-C should be completely replaced by Swift.
Swift is not a compact language like Objective-C. It’s more like C++ in how it tries to incorporate every programming paradigm that can possibly fit. The heavy focus on complex upfront typing is not necessarily the best choice for iterative app development.
Swift is useful in many places, but personally I found Objective-C’s “Smalltalk-flavored C” to hit a sweet spot for my GUI needs where integrating with C and C++ libraries is usually required all over the place.
> The fundamental problem was Objective-C was built on top of C. C inherently has pointers. It has uninitialized variables. It has array overflows. It has all these problems that even if you have full control of your compiler and tool stack, you just can’t fix. To fix dangling pointers, you would have to fix lifetime issues, and C doesn’t have a framework to reason about that, and retrofitting that into a compatible way into the system just wouldn’t really work.
If you took away C from Objective-C, you couldn’t use C arrays on the stack, for example. And if you couldn’t do that, there’s entire classes of applications where the performance just wouldn’t be acceptable. We went around, around, around. We said the only way that this can make sense in terms of the cost of the disruption to the community is if we make it a safe programming language: not “safe” as in “you can have no bugs,” but “safe” in terms of memory safety while also providing high performance and moving the programming model forward.
Microsoft, Apple, Google have the luxury to impose moving away from C on their platforms.
On other platforms you have developers that won't touch any kind of Safe C even at gun point.
I suspect that the move to swift would never have happened without LLVM. And I wouldn’t be surprised if llvm’s cross language compatibility was specifically attractive to Apple because it let them have their cake and eat it too - write a new language but keep legacy C code whenever that’s the best option.
A lot of C's endurance is related to programmer psychology, so it would be futile to design a better C.
C++, Rust, Go, Java will continue to drain the pool of C developers until it's only used for maintenance of existing projects.
This is why it's extremely irksome to see people recommend mixing C and e.g. Python for speed, or other such Frankenstein's monsters - it's just prolonging the agony of whoever will maintain that.
Would you mind naming a few such classes?
Why would arena allocation, or evrn good generational GC fail to deliver the performance when quick allocation / deallocation of (large) arrays is required?
I find that this assertion holds about as much water for Swift as it does for Rust, Swift is not even remotely close to C++'s in terms of complexity, and that's with building in mechanisms for performant memory safety, a concept which C++ literally just shits on to this day and for the foreseeable future.
But once you learn to use the more advanced features, your code just gets easier to write and maintain. I enjoy that I can pickup new language features in Swift one at a time, figuring out where each adds its best value, and occasionally refactoring to take advantage as part of my ongoing efforts to minimize code debt.
It’s not even close. Swift is (still) minimalist by comparison to C++.
C is really good at exploiting those, while at the same time giving programmers a feeling of power.
I just cannot enjoy Swift at all. When I go back to Objective-C its just such a joy to write.
And I feel like I can write in Swift nearly as fast as Objective C. Objective C was always so baroque, when I define a method or variable and declare the exact same thing in a header file? Properties syntax?
I actually switched when Swift 1.0 came out (just after writing a twenty thousand line simulation engine in Objective C). It was so lightly baked I was starting to regret my decision for a couple months until version 1.2 released, only then could I ship my app commercially. Since then every release has only gotten better, and the rough edges are entirely gone. The only thing I miss from Objective C is compile time, and now just barely given how much faster the compiles have gotten.
Is this a joke? This sounds like "the language is wrong because it didn't completely ape C"
I do have times when writing Swift where I miss some bit of Obj-C, but those are rare and are becoming fewer as the language develops.
A major feature of Swift is that it forces you to deal with error conditions and missing values. In practice you do the right thing once and early in your code, and you can write the majority of your code with guarantees that prevent major classes of bugs. Swift is not perfect, still changing, and many complain about being forced to write safe code, but it is absolutely the right move of Apple to make for their platform.
It depends on what you are building. For an app it is not a big deal to be slower. But you will not write a kernel in Swift as you will lose performance all over the place.
Python/Javascript/Lua are used as scripting languages to create video games. But the 3D engines are written in C or C++.
Each tool has its use.
That used to be the argument against C and C++ in the 80 and 90's regarding 16 bit home computers.
Any serious developer would know that Assembly was the only proper way to write software that required real performance.
Yet a couple of decades later.
> But the 3D engines are written in C or C++.
There is a world between every single string, array and numeric operation being a possible source of memory corruption and being forced to explicitly write unsafe code.
I have been using mostly safe languages since the 80's.
They only get in the way of cowboy programming, which is a very good thing for anyone that praises quality in software development.
C would no longer be around if companies got properly sued for each CVE exploit.
The default code you write in swift is safe. You spend less time worrying about its correctness, which means you can focus on solving higher level problem and less time debugging.
When people call swift pedantic, for example, and I take time to ask for the specifics, I mostly get "not familiar to me", or "I'm used to shooting myself in the foot and unwilling to consider alternatives". So my patience has run out.
After working exclusively in it for a while now I can't help but cringe at the practices which I see encouraged in most other languages.
Also, if Swift is so much better and is supposed to be safer to use why are apps much slower and buggier than I ever remember? My iOS devices went from instant in iPhone 1.0 to pathetic and almost not useable at times on an iPhone 6 Plus, which would still be an awesome phone for my uses (using it as an iPod essentially and the occasional call) except it's slow and buggy. Even answering the phone is no longer instant. I could have sworn I remember when Jobs introduced the iPhone he was bragging how instant everything was. What would he say now and why are apps much less stable if Swift is supposedly that much of a benefit and greater than Objective-C
I think the idea is to make common things easy and uncommon things possible.
For speed of UI response, loading times, cursor and input latency we're at best no further forward. Quite often we're in an objectively worse situation. With a tiny few exceptions, no one cares about code or data sizes any more and that is reflected in what's delivered.
That's quite apart from the rise of web apps and the slowness that necessarily introduces.
Plus, low-level languages like C are sometimes the only way to go if you are writing for embedded systems with slow CPUs.
Mikroelektronika has Basic and Pascal compilers, in addition to C, for all those slow CPUs that are market relevant.
https://www.mikroe.com/compilers
And they aren't the only ones still alive.
Firefox is on a course to remove C++ from safety critical areas and replace those with Rust.
Edit: to be clear this is based on the blog posts I’ve read from Mozilla about the introduction of Rust in different areas of Firefox. I know nothing of firm plans.
I think this is the root of my dislike of Swift. "Assembling" together the best ideas, which may only be 'best' within a specific context does not suggest the kind of design principles I am looking for in a language.
I was looking for a quote and it seems it was Antoine de Saint Exupéry who said something like "It seems that perfection is attained not when there is nothing more to add, but when there is nothing more to remove."
So I contrast Lattner/Swift with Hickey/Clojure: a small set of coherent design choices that lead to a language that is simple but deep. It's by no means all things to all women and that's a good thing.
Surely every language designer including Hickey thinks they are assembling the best set of features for their goals.
I see Hickey as having a specific, focused, goal about enabling simplicity (given his specific meaning for that word) and yes I totally agree that every designer, including Hickey, does as you say.
What I was trying to get across was that I don’t see the guiding principle that guide the selection of those “best” features to include so much as “there’s this great stuff” that we must include.
Does that make more sense? Or should I put down my shovel?
† http://www.win.tue.nl/~evink/education/avp/pdf/feel-of-java....
He appears to have specific aims and seems unafraid to make the necessary compromises to achieve them.
Non nullable default types, defer, patterns are great ideas.
Virtual by default, associated protocols instead of generic protocol, Exception handling designed based on how objc passes nserror, Generic instantiation is done at runtime, not by the compiler, so field access and even defining locals involves needless math,
All things with a lot better alternatives at the time swift was designed.
I didn’t see a reason to design a new language when Objective-C could be improved (for those that think it needs improved).
--------------
Swift ... really is designed and optimized for, as a programmer, you can spend the least amount of time to get to a working program as fast as possible.
Getting to a working program includes the time it takes to debug something, to iterate and develop and fight the type system, and all the other things you have to do. But that time you spend having to fight the type system or figure out optionals or things like that pays itself back because your program works more often. You’re actually not spending time chasing own dangling-pointer bugs
Swift really does not support quickly iterating on a design. It demands that you sit down with your plan fully-formed, ruler and protractor in hand. Due to its strictness, changes ripple very quickly across even a small codebase.
Realized you need another enum case? You can't compile again until you touch all your switches. Protocol would be more expressive with an associated type? Stop what you're doing and write some type eraser boilerplate. Function needs to signal an error condition? Try/do/catch anywhere you call it, right now, before you run again. Need to put another type into that array? Write a new protocol and add some conformances.
Changing a interface as you work in Swift immediately creates a sea of red marks, which hinders the ability to experiment.
You're right that this strictness helps write ~correct~ safe code, and I appreciate that. But it's a tradeoff; there's a real cost in developer productivity/creativity. And I believe that it does not help produce the best design. It takes too long to get to running, which makes it too costly to heavily revise based on what you learn as you build.
EDIT: Actually, I want to go even further, and strike out "correct" in the paragraph above. Swift helps at a certain level of correctness, which is really not much higher than the type system -- it would be better to call this "sound" code, rather than "correct".
The overall point that I'm trying to make is that at the level of application/business logic -- which is the whole point of the program, after all -- Swift does not help with correctness. In fact, it can be detrimental, because, unless/until you understand your use cases well enough to actually lift them into the type system, at that upper level it blocks exploration without adding rigor.
I find the opposite to be the case. You assume that compile errors are a net negative for speed of development and expressivity. Instead I find that the compiler reminds me upfront of all the places I would need to update anyway in due time. In a dynamic language those inconsistencies would be found hours/days later and usually after lengthy debugging. Instead I find myself making large sweeping changes in the design very frequently, because I trust the compiler to warn of any logical inconsistencies.
You have to admit at that this point it boils down to subjective preference. You sound averse to the swift style of doing the right thing up front, and using the compiler to help you stay consistent. I personally tired of the hidden and unacknowledged costs of unsafe language, and compilers that allow your design to degenerate into an unmaintainable ball of mud over time. I'm ok with swift being an acquired taste and a technical advantage of folks who get it.
With the exception of the associated types thing which is a language limitation that would be nice to see resolved eventually, the others can be resolved with a combination of automatic refactoring (add new enum cases, etc) and a compiler mode where type errors compile down to runtime traps without preventing you from running the program. (And faster compilation in general would help as well!) These are both non-trivial to design and implement well, but I think it’s a good future direction for statically typed languages that will give them many of the benefits of dynamic languages during the prototyping phase.
I realized recently that I actually do like static typing, as long as the cost is low. (I really like TypeScript)
Sorry, I don't want to reason about the "shape" of my application state vector before I've written it... but that's what Swift's static type checking forces me to do... Design my app and it's data model at the same time.
Call me a lazy software hippie I guess.
In C++ -Wswitch is a valuable tool to find the former, but there is no way to find the latter. This makes writing correct exception handling code much much harder, so having Swift's strict behaviour would be great from my perspective!
It sounds to me that you want to use a few days of exploratory coding to save a few hours of design work. If this type of exploration is needed, then it could be done in another language which supports it and then when the design is in decent shape it can be ported to Swift.
Swift is not detrimental to the correctness of the business logic. It offers you a bedrock at the type sustem level on which to build that.
Lattner used rhetorical slight of hand to assert, in effect, "you 'working quickly' developers need first to adopt my values; only then can you be admitted to the conversation." C.f. Yegge on liberal-vs-conservative developers. [1] Lattner (along with you) is adopting a position towards the conservative end of the spectrum, which is cool. What's not cool is gaslighting the existence of a liberal perspective.
[1] https://plus.google.com/u/0/110981030061712822816/posts/KaSK...
A program that executes and performs some I/O is a very very low bar to pass. The next step is not being ready for wide-scale production, in fact the IEEE Software Engineering Body of Knowledge aims to define the many steps required for that and it's a lot of them. Developing by the seat of ones pants is fine for personal projects, but not for publicly used software.
And why should what developers "want" be the main criteria that should be used to choose programming languages? It's certainly important that developers are able to extract some satisfaction from their work, but that doesn't mean we should sacrifice other important goals just for the personal comfort of developers.
Also, you really could have phrased this to be a little less inflammatory.
Here it seems like Apple's culture of secrecy just hurt them for no reason. No really, Apple, you can just tell people what your plan is.
https://www.reddit.com/r/swift/comments/8zb9y1/state_of_swif...
I'm playing with rust to solve my use case, but is certainly hard. Is very unlikely you can build a team of mixed developers and use it. Swift is more forgiving, yet you can get great results anyway.
They could have cleaned up all Objective-C and built a much nicer language, instead we get a improved Java / C++.
somePoint.moveBy(x: 2.0, y: 3.0)
as opposed to [somePoint moveByX: 2.0 y: 3.0];
most Objective-C code would get rid of the space too [somePoint moveByX:2.0 y:3.0];
Its just painful to type extra characters that don't do anything and don't help readability. Plus the weird splitting of the moveByX is still odd.I still am mystified why they didn't just start with:
somePoint.(moveByX: 2.0 y: 3.0)
to keep it inline with Objective-C and start working on giving the method names an overhaul that would benefit everyone including the Objective-C programmers.I’ve run into a lot of programmers that worked with ObjC as they would Java or C++, that is, using very small and fine grained objects to divide up the problem.
It’s the standard way in Java. It’s also the opposite of how ObjC is supposed to be, which is ”a few big classes” that uses message passing as glue.
How many former ObjC programmers actually heard of ”Software IC”?
Using ObjC like Java/C++, the language quickly becomes unwieldy and verbose. If you do that, then obviously Swift feels like a huge improvement.
On the other hand, if you essentially write C and let ObjC be your reusability layer, then Swift might feel like you’re back to working inefficiently in Java / C++ with objects all over the place.
The way that I write Objective-C is to use 'id' for everything and have as few classes as possible, mostly I just add methods to the existing classes mainly NSString, NSArray, and NSDictionary.
Objects are interchangeable as long as they can respond to certain messages. For example, any object can be an array as long as it responds to objectAtIndex: and count. There was a whole discussion above about how Objective-C doesn't have generics, but this completely misses the point because Objective-C doesn't even need generics. "Modern" languages are not necessarily an improvement, software generally does not get better over time, it reaches a peak then it declines.
Objective-C is one of the best languages I have ever used, but the vast majority do not understand it, even the ones who say that they used to write Objective-C for X amount of years but now love Swift. The truth is, they never understood the beauty of Objective-C.
I consider Swift to be a language for large teams of average programmers, reading Lattner's response to Swift's criticisms tells me that he is a compiler guy, but that expertise does not carry over at all to programming languages.
I don't really like the direction they were taking Objective-C anyway, so in the end it doesn't matter. I'm against things like dot notation for accessing properties and ARC, I don't use either when I program in Objective-C. Those recent changes end up making the compiler more strict and a pain to deal with.
Consider the types of some template generated pointers, or just something like std::unique_ptr<std::vector<std::shared_ptr<Foo>>> (which isn’t a very far-fetched example).
This is ”the generics problem”, where it actually starts having an obscuring effect.
ObjC is immune to the problem since it lacks any need to do do the specialization. Unlike Java where you needed a lot of manually inserted casts without generics, ObjC doesn’t need them at all.
Like you say, dot notation, ARC, stricter resolution of dynamic messages etc were weakening the strong points of the language and would push the programmer towards a Java-like object model - which is very far away from how the language ideally should be used.
What new does kotlin or swift offer which python or ruby can not? Why reinvent the damned wheel for syntax sake when they could have worked for their device centric compiler for creating binaries out of python or ruby?
Compared to Ruby and Python they doubtless seem a little verbose. Type system features like genetics, which help to make Kotlin and Swift “expressive” in their family of languages, seem pointless from the standpoint of Ruby and Python.
So there are two aspects to this:
* What makes Swift or Kotlin compelling relative to other languages in that family? * Why use that family instead of languages outside it like Ruby and Python?
People have been promoting dynamic languages as an alternative to static languages for many decades but it doesn’t seem like performance has ever truly caught up enough.
It is not true of LuaJIT, which is as dynamic as languages get. Error detection and correctness, sure; raw performance is not the issue you've made it out to be.
Ruby and Python were fair choices, together they must have 10-50x the mindshare Lua does.
Lua (like plain JavaScript) is a more spartan development experience than Ruby or Python. I'm not sure what it is; but languages with rich OO seem to be what get picked up by people who need to build "applications" (windows where people click around in them).
What does "higher-level application demands" mean?
Rust has dynamic polymorphism like Swift, but Swift you opt-out with final (correct me please if I’m wrong here), whereas in Rust you need to promote to a trait object.
This is a small difference, but means you’re starting with different principles available to you out of the box. Personally I prefer Rust’s opt-in to complexity model, but I can see why people see that as a hinderence, even if it’s technically just as possible to do in Rust.
Then there are Swift Playgrounds and REPL for quick prototyping and those still aren't a thing in Rust.
I think it’s time for Apple (and Google) to embrace JavaScript as the app development language.
I don’t think that’s a particularly great choice.
https://blog.meteor.com/an-interesting-kind-of-javascript-me...
Plex was ported to the 3rd Gen AppleTV as an unofficial app just by running a server on your computer and redirecting DNS to it.