Thursday, November 10, 2016

How to Read the Swift Standard Library Source

Ole Begemann:

The bulk of the standard library’s code is in the stdlib/public/core directory in the Swift repository on GitHub. You’ll find the interfaces and implementations for all public types, protocols, and free functions there. You can of course just read the code directly in your browser or clone the repository and go through it on your local machine, but there’s one complication: you’ll notice that about a third of the files have the file extension .swift.gyb. If you open one of these files, e.g. FixedPoint.swift.gyb (this is where the integer types are defined), you’ll see a mixture of Swift and a templating language called GYB.

Erik Dietrich (via Reddit):

When it comes to getting up to speed in short order, there’s really little besides practice that will give you the needed skill set. As such, going into a bunch of codebases in your spare time and poking around is really the best way to become skilled at going into foreign codebases and figuring them out.


It’s not just the weighty architectural decisions that you’ll pick up, either. You’d be amazed at how many quick, little wins you snag with this practice. One day you’ll see a unit test naming scheme that you fall in love with. The next day you’ll notice a new language feature that will save you twenty lines of code in a lot of your classes. Or, maybe you’ll observe someone using semantics that make mistakes a lot harder.

Whatever the case may be, looking at a lot of code means taking advantage of a lot of others’ experience. It’s not quite the same as having tons of people review your code, but you can realize some of the same benefits.

Update (2016-11-16): Erica Sadun has more information about gyb.

Comments RSS · Twitter

Leave a Comment