logo dotConferences
Menu

Wh@t is th@t?

Mark Dalrymple at dotSwift 2019

Swift Attributes - you use them in your day-to-day coding. The @decorations that @you put on your @code to more clearly express your intent for the code. Mark tours a number of attributes, and ends up by showing you how to search the compiler source code to find all of the attributes, providing a gateway to your own personal exploration of the compiler and the language.

Slides

To see the slides, you can click here

More details

The interesting command from the talk is find:

$ cd ~/Projects/swift
$ find . -type f -exec grep SomeInterestingText {} \; -print

Breaking down the command:

  • find - walk the file system, visiting files and directories recursively
  • . - where do we start? The current directory (the dot)
  • -type f - only visit actual files. Only do more clauses if the file being visited is a file.
  • -exec - for the file being visited, run a command. What command?
  • grep SomeInterestingText - run grep to search for the string SomeInterestingText in the file being visited.
  • {} - What file should grepsearch? The matching braces is a placeholder for the path to the file being visited
  • \; - backslash-semicolon. The exec clause needs to be terminated by a semicolon. But the shell wants to eat that semicolon. So escape the semicolon from the shell with the backslash
  • -print - if the grep successfully found something, print out the file name.

The output then will be found text, followed by the path to the file, for each file that contains the text. All other files won't result in any output.

There are other bulk searches, such as ack, ag (the Silver Searcher), and rg (RipGrep) that are much faster than find being used like this. You can get these tools via HomeBrew.