So yes, I am back with learning how to code, after more than 2 years of complete stop during which I have probably launched Xcode twice. Most of those of you who follow me on Twitter do so because of those more than 100 articles I wrote back then when I was walking the challenging path of the 100 Days of Swift by Paul Hudson. After “graduating” with Merit from that program I attended the Pragma Conference in Bologna, Italy, and, there, something clicked. I didn’t like that kind of life, I didn’t like what I saw a professional programmer, hired and working for a company, became. I want to avoid generalising but, at least, that was the absolute majority. After coming home, I started the 100 Days of SwiftUI challenge path and, after the first 20 days, I dropped off, I couldn’t stand it anymore. I was feeling that this was not the way I wanted it to be, that I was missing my music too much, that I did not have the proper base to do this after a certain level.
Two years passed and, while I do not miss the stress of having each day to follow the challenge and to write about it like a machine, I still miss the act of sitting in front of a computer, writing a few lines of code and having it do what I told it to! We can say that, yes, I miss the power! I therefore decided I would get back, but on my terms!
First, I would start programming for the Mac and not for mobile devices, at least to begin with. While I love what my only available app on the App Store has become after numerous efforts, what I learned didn’t teach me how to port it successfully to the iPad (sure it runs, but not with an iPad-like interface), nor to the Mac. I wanted to expand it, to add a quiz feature people could play with, all things I needed to research, forgetting about my current job (which I still love and do) and not getting any sure money to keep supporting my family. Finally, it came down to practicality, and I couldn’t do it that way.
My first approach to programming had been the CS50 course held by David J. Malan at Harvard University: such an incredible teacher, such an inspiring course, and it was all using the C programming language. I have to confess, I did not finish the course, I did not get to the end. Once more, it required too much preceding knowledge, or so much time filling in the gaps that it was just impossible to follow. I decided that I would go back to where everything started, not following the CS50 course once more, but studying the C programming language. But why? C is basically unused in most apps, so why on Earth would I do that? Simple: because C is the starting point of everything else that truly matters in Apple development. Objective-C stemmed from C, Swift sits above it with so many dependencies still in there, most Apple frameworks are still written in either C or Objective-C, even the SwiftUI framework still have some hidden and obscure connections to it. Most professional desktop applications, even just considering the two I use the most, Dorico and Sibelius, are both written in C++, another of C’s offsprings!
There are hundreds, if not thousands, of courses out there on the C programming language, but I chose to follow Lucas Derraugh and his YouTube videos on his Apple Programming channel, integrating what I didn’t understand with personal researches. Lucas’ teachings are clear and easy to follow and, besides that, they are well-structured.
This series will be titled ”Learning the C Programming Language as a Classical Musician”, and I count on using what my nature, my training, my whole self is to make this unique. Every episode, every code sample I will use, will be tied to something musical so that you will be able to possibly learn something new alongside me.
As I am a Mac user, I will be using Xcode 13.x on macOS 12.x to write this series and all its samples. I will possibly create some repository on GitHub as well for you to follow and download the code samples. The C compiler in Xcode 13 has only one big downside: it is very slow to start. That means that the first time you will press Cmd-R to build and run you will have to wait quite a long time for it to start, make the console appear and compile your code. Actually, there is another downside: Xcode has no C-language documentation in it, meaning that we will have to look for our explanations and clarifications elsewhere. To get started, I downloaded Dash from its website and will purchase the license once the 30-days trial expires, assuming this proves better than just searching online (about which I am 99% sure).
If you launch Xcode on your Mac and you expect it to offer you a “C App” then you will be sorely disappointed. This gives you a glimpse of some of the beauties of this language: in short, a C app runs in the Command Line (which you can see by launching the Terminal app) and has no graphical interface by itself. You will just see lines of code running in Terminal or, in our case in the beginning, in the Console panel in Xcode.
Assuming you have already launched Xcode (if not, just head over to the App Store and download it, wait for an eternity to unxip and install and then come back here!), you should see something like this:
Ignore what you see on the right for the moment being, as they are my recent projects, and they will for sure differ from yours. To the left you are given three options: Create a new Xcode project, which allows you to create a new app from scratch for any Apple device; Clone an existing project, which allows you to clone a Git repository1 to start working from there; and, finally, Open a project or file, which does exactly what it says.
For now, just click on the first one, Create a new Xcode project, which should bring you here:
Xcode will remember your last choice, so do not worry if you do not see the same options as I do. This dialog asks you to choose a template to start from. Please select macOS from the top bar and then, under the “Application” category, select Command Line Tool and either hit Return on your keyboard or press Next. The next page will show you this:
In the first line just write the name of your project, for example “C Tutorials Ep1” or “Learning C Ep1” (do not use dashes or special symbols as they will cause issues in the file path and filename). In the Team dropdown menu you should either see “None” or your name or your organisation name, even if I am pretty confident you will not be reading this if you are part of a company already. The Organization Identifier asks you to write something like a URL (Uniform Resource Locator) backwards, something like “mywebsite.com” starting with the “.com” part. I always leave it alone and Xcode usually performs this flawlessly so, go ahead and, from the Language dropdown menu, choose C, then click Next. Decide a place where to save your project (I suggest creating a master folder to contain all the project of this series) and click Create. Xcode will think for a little while, and then you will be ready to go.
In the next episode, we will look at the structure of a C program on the Mac in Xcode 13 and look at some basics concepts of the C programming language.
Thank you for reading today’s article.
If you have any question or suggestion, please leave a comment below or contact me using the dedicated contact form. Assuming you do not already do so, please subscribe to my newsletter on Gumroad, to receive exclusive discounts and free products.
I hope you found this article helpful, if you did, please like it and share it with your friends and peers. Don’t forget to follow me on this blog and to let me know what you think.
If you are interested in my music engraving services and publications don’t forget to visit my Facebook page and the pages where I publish my scores (Gumroad, SheetMusicPlus, ScoreExchange and on Apple Books).
You can also support me by buying Paul Hudson’s Swift programming books from this Affiliate Link or BigMountainStudio’s books from this Affiliate Link.
Thank you so much for reading!
Until the next one, this is Michele, the Music Designer.
- A Git repository is, in very simple terms, a place where some code is stored, alongside all its previous versions. This allows you to start in some place, make some edits, check that everything works and then commit to the original code. It is all much more complex and deep than this but, in short, it allows to collaborate, to share, to backup, to save and, especially, to revert back to a previous state of your code. For more info, visit here. ↩
One thought on “Learning the C Programming Language as a Classical Musician”