214 points · by pjmlp · 2y ago · 241 comments
If you're want to have access to everything, Objective-C++ is easier.
Where C++ reigns in Metal is being the shading language.
If the audience at Goose Con thinks your talk about Hedgehogs is great, that's not the wrong talk for Goose Con. Maybe it means "Wildlife Con" is a better name, but, maybe that talk, on that subject, at that time, was perfect and there's no wider lesson.
From Apple's point of view C++17 is good enough for their purposes.
Metal uses a C++14 dialect, and LLVM requires C++17 currently.
C++ is not used for the majority of platform APIs because of all the problems, difficulties, and costs of ensuring ABI stability. C++ ABIs are notoriously fragile, which is a problem objc does not have, and swift was designed specifically to reduce ABI issues (that’s part of the reason generics are implemented as they are)
That is how you end with COM stuff, C++ only SDKs, and .NET dev community having to implementing bindings ourselves.
https://github.com/apple/swift-evolution/blob/main/proposals...
At runtime, it’s functionally close(ish) to malloc/free and doesn’t carry much overhead.
ARC certainly helps ARC be more performant than ARC without ARC due to the elided traffic on the count. (lol)
Citation needed on the performance loss. So far only a handful of SIL optimizer passes have been rewritten in Swift.
Also, internally the stdlib uses objc arc types nsarray nsstring etc only on Darwin platforms for zero overhead objc interop. This isn't the case on Linux and windows. For some embedded or Micro-swift variant for low level os work there could be a similar stdlib toggle for Darwin I think.
FWIW there’s been plenty of C++ in macOS since the start, eg. Security.framework.
I never understood why the "Champagne" issue was so obviously silly to Americans.
Champagne is an actual place, that's where the name of the wine made there comes from.
Could you name something "Napa Valley wine" if it's not from Napa Valley?
A randomly selected hamburger, frankfurter, or wiener, probably isn't made in Hamburg, Frankfurt, or Vienna.
And sometimes it can get even weirder: Stilton cheese is named after where it was historically sold, but it's made elsewhere and you're not allowed to call a cheese "stilton" if you actually make it in Stilton. (Edit: I originally got Stilton and Cheddar mixed up).
As I'm a British national, I don't know if this is the full reason, or if this is in combination with the natural human tendency to care more about nearby things and that the Atlantic is so big that all of the USA is closer to one of the places called "Champagne" within the USA than to the original in France.
There is a kind of onion called a "Vidalia onion," grown in the town of Vidalia, Georgia. They're a sweeter onion, which is unusual, which is why it grew into a brand.
However, because of this, a lot of people's first exposure with a sweet onion is a Vidalia. But not all sweet onions are Vidalia onions. Yet sometimes people still use "Vidalia" to mean "sweet onion" in a generic sense.
I suspect it's very similar, honestly: I don't think your average American knows that Champagne is a place. Their only exposure to the word is via that style of wine. And so they associate it with the style rather than the brand/region.
(Vidalia onions are also protected legally in the same way that Champagne is; a lot of people in this thread saying that that's just some silly French thing don't realize how common this is. In the onions' case, this has been true since 1989.)
The simple explanation is that nobody in the US really cares about the point of origin — even wine labels are considered more a brand than a location. There is no sense that « terroir » might have any consequence.
Sometimes you encounter food labeled with the state where it was grown or produced — that’s mainly a “buy local” claim, nothing more.
So really, congrats to Champagne for making a brand so well known that Wayne’s World can make fun of it and be sure that basically the whole audience will get the joke. I mean that sincerely.
You have to know a little bit about wine to know about Napa Valley. I think “it’s from NaPa Valllleeyyy” in a sort of silly voice is something that somebody might say. It just doesn’t have the reach.
I would think of this as not really making fun of Champagne. We’re making fun of being the kind of person that cares about Champagne.
It's like saying you can't call them brazil nuts unless they were grown in Brazil.
Which showcases the real issue - it's ok when americans approriate non-american names for things, but not when others do it.
“No one’s gonna tell me that the 1.5 litre bottle of Baby Duck that I drink with my Pizza Hut delivery while watching infomercials isn’t shampane!”
And this where your ununderstanding starts. It is a place name for you. For literally billions of people it's some word describing a type alc. drink first.
While you are indeed free not to work for Apple (that is what I do!), policies in FAANG companies have significant influence on smaller companies who tend to cargo cult them without much thinking. That is how we end up with leetcode-style interviews, now I'm afraid we all might end up back in office, only even worse one than before where you don't even have assigned table in the open-space.
"If you don't like it, leave!"
Following this advice bolsters bad policies & practices by removing opposition from institutions.
It's noble to stay aboard to fight the good fight. I'm envious of engineers able to take on the risk.
One thing that has always puzzled me is the low quality of a lot of Apple software. Here are some things that tend to happen over and over:
- Desktop applications that block the UI thread and present spinning ball of fail
- OS daemons that consume far more CPU than they should and often get stuck in a state where they consume lots of CPU
- Slow downloads and ultra slow "checking for update" type scenarios
It wouldn't hurt Apple to focus on quality for a couple of years. Both to rewrite a lot of software that doesn't quite perform as it should, as well as laying down some plan for long term quality enhancement.
The stuff that is written in C/C++ and possibly Objective-C today should perhaps be written in Rust. Rust is a pain in the ass to program in, but I do think it is worth it for system software just because it affects so many people when stuff fails. And I suspect a lot of Objective-C code could also be replaced with Swift.
What are you referring to, for specific example? I haven’t had any of the symptoms you list.
https://mjtsai.com/blog/2015/05/27/mac-os-x-10-10-4-replaces...
If someone found a rust binary somewhere on a macOS install I’d be super interested.
I found that ObjC made it easy to write spaghetti code if you don't understand the motivations behind ObjC and its SmallTalk-like OO approach, and if you didn't have good rules to follow, and really think hard about the best way to do things.
I feel like too many people came into ObjC trying to just use it like Java or Python.
The dynamic-ness of it can quickly get out of control, event handling was verbose and tangled.
I feel like ObjC was missing a proper SmallTalk environment to tame it.
I think ObjC caused a lot of this bad software. Race conditions, state management bugs, logic bugs, etc.
But on the flip-side the compiled nature of it allowed things to be fast when they needed to be.
Swift Playground was a good sign of Apple drawing on its SmallTalk roots, but at the same time entirely abandoning the SmallTalk OO approach.
I find Swift a bit of a boring language. It's just a new compiled language with some fun and quirky syntax choices. There doesn't seem to be any brave new philosophy or new ideas behind it.
Apple software quality has declined significantly from the Objective-C era to the Swift era; but that actually has nothing to do with the programming language and everything to do with the forced march yearly release schedule and the lack of caring about quality by current Apple leadership.
The first IDE vendors for Java, were doing Smalltalk.
So the Java critic is kind of ironic.
And Java interfaces were taken from ObjC protocols.
I think its sad though that this entire lineage while being inspired by SmallTalk, seemed to miss the whole point of SmallTalk. The always-running virtual machine was an essential part of it. And a good IDE and tooling is needed to help deal with such a dynamic language. But I think a lot of people just ended up treating it like C with a quirky syntax.
I'm pretty sure if Jetbrains somehow gets acquired by Google, Kotlin will reach greater heights than Swift.
I personally think Jetbrains getting acquired would be a nightmare. JB is very responsive and accessible when you have an issue with their libraries (Of which I've found many). Google is an impenetrable super-corp and they already endorse Kotlin heavily for Android development.
What's more in typical Google fashion, this would inevitably spell the death of Compose Multiplatform UI or Flutter when a higher-up learned they were paying for two competing solutions. Flutter has more users, so Compose would join the graveyard.
Best I can tell no one really uses Swift for anything other than desktop/ios apps. Kotlin is only gaining traction in industry on the backend. I don't really know how relevant Tiobe indices are, but I would expect Kotlin to overtake Swift in a year or two.
I would love if more folks would ship Swift backends, but JVM folks moving from Java to Kotlin is a natural progression and I don't see Swift closing that gap
1. Google has multiple in house languages already. They somehow haven’t made them work well together.
2. Google already tried their hand at Swift when Lattner was there. It was really cool, but died on the vine.
3. Google is very easily distracted and will kill off things that aren’t critical or bringing in enough new customers.
I like my Jetbrains IDEs to want a company as poorly managed as Google take it over. Their offerings would quickly be killed off in the name of “unifying them” and then suddenly that one solution will die as well for anything except for Android Java.
The fact that you can log an issue on their public tracker for any product, and some human is triaging this instantly.
That said, I don't disagree that if Google backed it properly (seems unlikely now, considering they just fired the guy who led Guava/Guice, for example), it would do really well.
But can’t swing Cupertino :(
Another problem is C++ template. Oh boy that thing is semi-decidable on its own.
Besides that, you have small things like ADL [1] and SFINAE plus the new C++ concepts...
That's why after learning C++17, I decided to give up and switch to Rust.
I'm not sure why is everybody so after C++. I don't care about sunk cost, and I just want the best of the best. Easy to implement the parser, easily make a compiler for it. I like those languages.
[1]: https://en.wikipedia.org/wiki/Argument-dependent_name_lookup
That is somebody else's headache, namely compiler developers. As a user I am totally happy with C++. It lets me do what I want to do without much fuzz and has enough features to be ergonomic. Sure I would never know it completely but who says I need it? It absolutely does not preclude me from being productive.
Not everybody; those who have tons and tons of existing C/C++ code, want to move away from it, and realize the only way to do that is gradually.
Swift’s C++ interop makes it possible to add a Swift class to an existing C++ code base and have code from either language call into the other, mostly without having to copy or convert function arguments.
You can write Swift functions that work with C++ std::string today, for example, gradually replace all code using it by Swift code, and then change the type of the value to Swift’s string. Easy? No, but easier than a ‘big bang’ rewrite.
Then you should get a copy of Modern Compiler implementation in ML. I love the Crafting Interpreters book, and also the Writing A Compiler In Go book; but they will not satisfy any person with undergraduate CS education.
All of the front-end parsing stuff is good, but heavily biased toward LALR parsing, which is rarely used in production compilers these days because it’s really hard to get good error messaging. There’s also a lot of tooling that can help these days.
But where it really falls down is the backend part. Parsing is just not where you’ll spend most of your time. Once you parse you usually need to translate the parse tree (often an AST but not always) into some other representation.
I found the Appel books (Modern Compiler Implementation in <language>) to be much better at that part. I still own a Dragon book (an older one), but tend to refer to my Appel book a lot more when working on compiler-y things.
From memory (because I left my copy of the Dragon book in another country) the book describes very well the first stages of compiler construction, describing the fundamentals of what Lex/Flex and Yacc/Bison do.
Right now for a compiler I'm writing I have used the Crafting Interpreters book and find it very useful. It's basic but can carry you through a project, and a decent reference for someone who took a Compiler Construction course about 20 years ago.
A somewhat more playful approach might be to complete the 2019 edition of Advent of Code [2], where you'll learn some preliminaries while implementing the Intcode interpreter.
[1] https://online.stanford.edu/courses/soe-ycscs1-compilers
# Learning Resources
## Theory
Take a look at these two books:
- Crafting Interpreters[2]. Compilers and interpreters have a lot in common and the book is exceptionally beginner-friendly. Basically, this is the perfect one to get started with.
- Introduction to Compilers and Language Design[3]. Doesn’t assume any preexisting compilers knowledge, and teaches all the basics necessary to build a compiler using a hands-down approach. The examples are in C.
Ignore the classics textbooks like the Dragon Book or "Modern Compiler Implementation" for the time. You can always come back to them later if you want to.
## Source code
Explore the sources of
- 8cc[4]. A compiler for the C programming language. It's intended to support all C11 language features while keeping the code as small and simple as possible.
- chibicc[5]. The successor of 8cc from the same author.
If you want a bit of background on these two compilers, check out the author's blog post "How I wrote a self-hosting C compiler in 40 days"[6]. Personally, I find it to be quite a fascinating read.
# Input language
Don’t try to come up with your own language just yet. Go with an existing educational language instead, and focus on learning about compilers. ChocoPy[7] is specifically designed for classroom use in compiler courses and by extension is great for a hobby compiler project.
# Target language
Many educational compilers emit MIPS assembly. Although it's possible to run it using an emulator, running a native executable produced by your own compiler feels much more rewarding. So I'd suggest your compiler emits x86-64 assembly.
For educational purposes, I'd avoid targeting languages such as LLVM IR or C. Emitting assembly helps understand many important concepts better:
- Managing a function's stack frame
- Calling conventions
- Finding the memory address of an identifier
- Converting expressions into assembly
- And so on and so forth.
[1]: https://mykolam.net/posts/toy-compiler-of-scala-subset/2-loo...
[2]: https://craftinginterpreters.com/contents.html
[3]: https://www3.nd.edu/~dthain/compilerbook/
[4]: https://github.com/rui314/8cc
[5]: https://github.com/rui314/chibicc
[6]: https://www.sigbus.info/how-i-wrote-a-self-hosting-c-compile...
[7]: https://chocopy.org/
The base does have a quite wide range, I assume that's the range for a few different levels. Still, you are roughly looking at a TC starting from $230k all the way up to $400k and more.
"Niche space and serious talent" doesn't necessarily translate to higher levels or salary in a company. It all comes down to how much resource an organization has. (I wish my employer actually understood how "valuable" I am and that I achieved things very few in my company could do, but I am not betting on that or the company.)
All other comments here are useless and a waste of your time.
(EDIT: Removed a lot of extra verbiage explaining TC vs. base pay, which — thanks to the comment below — I'm realizing everyone probably already knows.)
I was asking about TC in this particular instance given the following:
1. I have never worked for Apple (but I interviewed at big US companies for remote roles, and got to the TC negotiating round with a couple of big techs).
2. THis is a very niche role and requires very niche expertise and lots of experience.
3. The current state of the industry and how it has impacted comp at big tech like Apple.
I was hoping for a better insigh given all the above, not how TC works at big tech.
I think Apple’s always cared about ease of development over the possibility of bare metal optimization - after all, Objective-C was built on dynamic dispatch, and libraries as important Cocoa/AppKit and Apple’s compositors aren’t going to ditch that soon.
And, because of C++’s scars and warts, I don’t see Apple ever valuing stable codebases over Apple’s ruthless deprecation habits when it comes to change and development.
Instead, I’m convinced it’s really to help people trying to port games to macOS; it’s unusual for Apple to ever invest in an ecosystem of porting from different platforms, but here we are.
I would disagree.
Apple avoided managed runtimes this whole time and made people think about memory safety a lot compared with Java/C#. Programming was not as easy as it could have been.
It has also always been trivial to fallback to C/C++, and the interop story with ObjC code is a lot cleaner.
I think the driver for this was because they highly valued a buttery smooth UI, and this requires a lot of bare metal optimization.
It’s binary compatibility that Apple doesn’t care about.
If you ever watch talks from folks like Dave A. Who wrote the stdlib, he says he only ever uses arc types as a mechanism to enforce COW for the stdlib types and containers.
This is not relevant to system programming. It's actually anti-relevant, as your #1 job is to be small and stay out of the way of the app code. And your #0 job is to not crash or have security holes.
what's the point :o
> The average Cupertino home value is $2,663,389
I'm sorry wtf?
Now you know how us European devs feel like in ragrds to wage/housing prices.
With Swift language bindings it would be quite smooth to work towards.
Key Qualifications: Ability to write safe and high performing code with C/C++
The entire reason swift exists? Because safe and fast code code in C or C++ is not a thing.
I'm curious whether their swift compiler is written in swift yet. It seems like that would be a good idea but in direct tension with C++ interop which would be very tempting to do by hacking on clang (which is not written in swift).
I wouldn't generally mention that (it's in the "sky is blue" class of interest). That a swift compiler role had this in the prereq struck me as hilarious.