13 ms·
Chris Lattner writes: ”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 pra
by pavlov 8y ago
Chris Lattner writes:
”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.
- lmm 8y agoThose 16MHz processors were two or more orders of magnitude slower than anything anyone's running Objective-C on these days. Is there really a need for C any more?
- ziotom78 8y agoThis is true, but consider that today we are using computers fo to run tasks much more complex than 30 years ago. Rendering a complex HTML page with CSS and Javascript is an herculean and time-consuming task, which is why Firefox and Chrome are written in C++; and don't forget deep learning! Plus, low-level languages like C are sometimes the only way to go if you are writing for embedded systems with slow CPUs.
- pjmlp 8y agoOnly if one doesn't look into the right place. Mikroelektronika has Basic and Pascal compilers, in addition to C, for all those slow CPUs that are market relevant. https://www.mikroe.com/compilers https://www.mikroe.com/compilers And they aren't the only ones still alive.
- bluejekyll 8y ago> Firefox and Chrome are written in C++; 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.
- otabdeveloper2 8y ago'On a course' implies that there's some sort of definite plan and resources delegated to the task. Which isn't true of Firefox and Rust, as far as I know.
- bluejekyll 8y agoWhile it may not be an explicit goal, everything I’ve read implies that, for example the heading in this wiki on oxidization: https://wiki.mozilla.org/Oxidation https://wiki.mozilla.org/Oxidation > Moving forward, the goal of Oxidation is to make it easier and more pleasant to use Rust in Firefox, and correspondingly to increase the amount of Rust code in Firefox. And then there is the Rust page on Mozilla’s site: > Mozilla also utilizes Rust in many of its core initiatives including Servo and key parts of Firefox. https://research.mozilla.org/rust/ https://research.mozilla.org/rust/ Where “key parts” is a link to the project quantum announcement: https://medium.com/mozilla-tech/a-quantum-leap-for-the-web-a3b7174b3c12 https://medium.com/mozilla-tech/a-quantum-leap-for-the-web-a... > Initially, Quantum will share a couple of components with Servo, but as the projects evolve we will experiment with adopting even more.
- gsnedders 8y agoThere is, however, no expectation or any real plan that C++ will be gone from Firefox. There's a huge amount of code, and there's a cost to rewriting it.
- bluejekyll 8y agoI only claimed “safety critical areas”... the other millions of lines and OS interop for UI, etc., will most likely not change for a long time.
- acdha 8y agoYou don’t even need higher level tasks like that: take something as seemingly simple as processing text. That used to be 8 byte operations, display was looking up a bitmap and copying it into a buffer, but once programmers accepted that humans use more than ASCII and want nice displays that started to involve context sensitive decoding and display, processing vectors, subpixel rendering, etc. All great improvements but most of them require more CPU/RAM than a 30 year old computer had, too.
- willvarfar 8y agoI recall discussing the spec of an upcoming phone platform in about 2007 or so. It claimed to be 4x faster than the previous generation and there was much rejoicing. And at the same time the screen went from QVGA to a widescreen that had 5x as many pixels... And the camera from 2MP to 8 or was it 12MP. In practice, from a usability perspective, the new platform was slightly slower than the previous platform :(
- NeedMoreTea 8y agoWhen compiling or video encoding I'll take a current processor. For everything else, not so much. 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.
- pjmlp 8y agoYeah, but you forgot to copy the other relevant part. > 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.
- pavlov 8y agoThat’s a good reason to create a new language. But all the C code in the world isn’t suddenly going to go away, and so the need for an improved C still remains.
- josephg 8y agoThat’s why LLVM is such a great idea - any llvm language can interoperate with any other, within the same binary, with no overhead. Apple isn’t throwing away their C code any time soon either. LLVM provides a smooth upgrade path via mixed language binaries. 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.
- pjmlp 8y agoIt is a great idea, but not an innovative one, already PL/8 for IBM RISC research used a similar approach.
- coldcode 8y agoI have used Objective-C since 1997 when I worked with WebObjects back then and I don't miss it for a second. When I have to touch our one codebase with Objective-C I have to groan. It was amazing for its day and I did enjoy it despite its shortcomings. But I can write way more highly functional code faster in Swift than I ever could in Objective-C due to real type safety and other modern features. I also spent years doing regular C and C++ and Java (not at the same time) and all 3 languages seem clunky to me now. Preferring Objective-C over Swift is wishing for the golden oldie days kind of thinking and I'm one with almost 4 decades of programming experience. Swift is still young and growing and sometimes thats a bit challenging to adapt, but its the one language I truly enjoy now.
- 0x0 8y agoObjective-C in 1997 and in 2017 are almost two different languages. Between ARC and generics, auto-synthesized ivars, and blocks, there's not much missing from being a modern C#/Java-like language.
- zoul 8y agoI love Objective-C, but calling it (close to) a modern language is a long stretch. The “generics” are a joke, for example. The whole type system is miles from what can be expressed (and guaranteed!) by a modern language. We got an immense amount of fun out of it considering its age, but it’s time to move on.
- tsycho 8y agoTotally agree that generics in objective c are very bare. And that's what frustrates me the most. Apple/Lattner could have improved them, but chose not to, by focusing all their energy on Swift. "Simple" things I want from generics: 1. Carry over generic information from header files to .m files, and not force us to drop all type information by having to use "id". 2. A compiler flag to enforce that the generic type must be specified at usage. 3. Where clauses in generics: Foo <T where T : NSCopying, MyProtocol>> 4. Generics on protocols, ideally with all the other features. I know some of these are not trivial to implement, but they are mostly new syntax and hence don't have backward compatibility issues (except #2 which is why I asked for a compiler flag).
- flipgimble 8y agoWhen people criticize C as a language they are usually referring to the fact that it easily and frequently allows for many classes of bugs that riddle C code. For decades, as an industry we've been apologizing and fixing critical exploits and bugs (ex HeartBleed), that can be traced to the fact that C allows for mistakes. If a bug is allowed, someone will perpetrate it sooner or later. Sacrificing correctness and safety for the speed and complicity of C is not a valid tradeoff for the industry in my opinion. 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.
- jmpt 8y agoIf Swift lets you override dealing with errors (think force unwrapping) then such security is pointless because "someone will perpetrate it sooner or later." In practice, what we get is an overly pedantic language that gets in the way of the developer.
- zoul 8y agoThere is a world of difference between letting bugs easily happen a letting the programmer override error handling.
- flipgimble 8y agoThe critical difference is that in swift your have to override safe behavior by using special syntax. This means you can search for it to fix it, you can have compiler/linters enforce certain rules, you can catch it easily in code reviews. No professional team I've worked on would allow forced unwrapped code except in special well documented cases. 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.
- patrickg_zill 8y agoFunnily enough, NeXT never ran on 16MHz cpus! The original machine was a 25 MHz 68030,followed by 68040 running at 25 and 33 MHz.
- masklinn 8y agoNeXT did not, but Objective-C was not designed by or for NeXT, it was licensed for it years later.
- cheez 8y agoThat's because a lot of the people involved in C++ are now involved in Swift.
- b3b0p 8y agoI have some similar thoughts. I like Objective-C and C and always thought of Objective-C as an improved upon iteration of C. The C/C++ integration is one of my favorite parts. 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
- rimliu 8y agoNot sure what apps you are talking about, but not many core apps have been rewritten in Swift.
- Volt 8y agoThat's just plain software bloat, which continues to plague everything ever.
- saagarjha 8y agoThis is entirely unrelated to Swift. But to address our concern: your iPhone 6 Plus is the slowest iPhone still getting updates today. Sure, it should perform better, and the iOS 12 update later this year will help fix this issue, but Swift has nothing to do with making your phone slow.
- MR4D 8y agoI upgraded to the iOS 12 beta a week or so ago on my 6S+. I can say without any doubt that it is so much faster that I feel like I have a new phone in my hand. I honestly never thought an upgrade could make this much difference.
- gok 8y agoI actually find Swift's C interop pretty extraordinary. Miles better than cgo, JNI, cffi/Cython/ctypes, etc. Parsing C headers, complete with comments and stuff, is super cool, and just about as slick as you can get without bringing in serious C cruft (like having its preprocessor). My biggest disappointment with Swift is that C++ doesn’t get the same treatment.
- saagarjha 8y agoC++ really is hard for any language to interop with. You basically have to add all of C++ to the language before it can work with C++.
- gok 8y agoYeah I agree it wouldn’t be easy but damn would it be great. And like... given that much of the Swift Core team implemented C++ in clang, they’d be the ones to do it.
- tinus_hn 8y agoIf you need C in your Swift program you can just put it in a separate library. I think the idea is to make common things easy and uncommon things possible.