<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sam Lazarus on Medium]]></title>
        <description><![CDATA[Stories by Sam Lazarus on Medium]]></description>
        <link>https://medium.com/@samlazarus?source=rss-71872d5042f9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*npiE_TaNB85Ej-DQ.</url>
            <title>Stories by Sam Lazarus on Medium</title>
            <link>https://medium.com/@samlazarus?source=rss-71872d5042f9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 03:25:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@samlazarus/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using VS Code as an Editor for the Swift Compiler]]></title>
            <link>https://medium.com/@samlazarus/using-vs-code-as-an-editor-for-the-swift-compiler-57f7ed01113?source=rss-71872d5042f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/57f7ed01113</guid>
            <category><![CDATA[compilers]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Sam Lazarus]]></dc:creator>
            <pubDate>Sun, 28 Apr 2019 03:20:28 GMT</pubDate>
            <atom:updated>2019-04-28T03:20:28.017Z</atom:updated>
            <content:encoded><![CDATA[<p>Visual Studio Code is a fantastic tool that can be used as anything from lightweight text editor to a IDE suited for even heavy development tasks. When I started working on the Swift compiler, I needed to determine what tooling I wanted to use. When selecting the tooling I would use to contribute, I knew that I needed an editor which could provide type information and intelligent code completion, use lldb for debugging, and have modern text editing and refactoring capabilities. VS Code seemed like a good tool for the job, however it needs a good deal of configuration out of the box before it’s ready to work on such a heavy weight task. Here’s a quick walkthrough of setting up VS Code to work on the Swift compiler.</p><p><strong>Aside:</strong> This guide is angled towards macOS, however the majority of the steps here are cross platform with slight modification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*22qniTEN0fsBESVuR8l0Yw.png" /><figcaption>The finished product</figcaption></figure><h3><strong>Environment Setup</strong></h3><p>Before we can set up VS Code, we need to have a successful version of the Swift compiler. To get this set up, I would recommend forking the swift repository, then following <a href="https://github.com/apple/swift#getting-started">these instructions</a> but with the initial clone pointed at your fork of the repository.</p><p><strong>When you get to the build step, make sure to build with a debug configuration for the part of the compiler you plan to work on. Without doing so, you won’t be able to easily use the debugger we’ll set up.</strong></p><p>The documentation here mentions that it may be helpful to save your build directory as an environment variable. I would <em>highly</em> recommend you do so as it will make VS Code configuration significantly easier.</p><h3>Setting up VS Code Workspace</h3><p>Once your environment is set up, you can create your VS Code workspace. Open up VS Code, select add workspace folder, then navigate to the directory you cloned Swift into.</p><p>This will open up a VS Code workspace. Start out by saving the workspace File &gt; Save Workspace As... I placed mine in the folder containing swift-sources but where you save this doesn’t matter much as long as it’s not in the project folder itself.</p><p>Once your workspace is set up, install the following extensions (we’ll set them up in a bit):</p><ul><li><strong>C/C++</strong> by Microsoft (Language server integration)</li><li><strong>Cmake</strong> by twxs (Language support for CMake files)</li><li><strong>CodeLLDB </strong>by Vadim Chugunov (Debugging with LLDB)</li></ul><h3>Ignore VS Code Configuration in Git</h3><p>We need to add VS Code configuration files to the list of locally ignored files in git. To do this, from the main project directory, open .git/info/exclude and add a line containing:</p><pre>.vscode/</pre><h3>Add file associations</h3><p>Open your VS Code settings (This can be easily found by opening Code &gt; Preferences &gt; Settings and clicking the { } icon in the top right) and add the following to your configuration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/624c7859f4cd99068ce84f811ca7273a/href">https://medium.com/media/624c7859f4cd99068ce84f811ca7273a/href</a></iframe><p>This will allow C++ and swift gyb and swift test result files to get syntax highlighting from their associated language. For gyb files, the highlighting won’t be perfect, but it’s better than nothing.</p><h3>Configuring IntelliSense</h3><p>In order to get useful code completion, signature popovers, symbol searching, go to definition, error highlighting, and more useful code navigation features, you’ll need to give the Microsoft C/C++ plugin the information it needs to run clangd on the project.</p><p>If you’re on macOS, you’ll need to make sure that you install the macOS SDK headers for your OS version. If you’re on macOS 10.14, you would run the following:</p><pre>sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /</pre><p>This will install header files for the macOS SDK into usr/include .</p><p>If you’re on another operating system, ensure you have the headers for the standard library accessible in a folder somewhere.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a3c47db1e188ee66909cb10da3a1255/href">https://medium.com/media/3a3c47db1e188ee66909cb10da3a1255/href</a></iframe><p>Additionally, make sure you also have the following set. These will tell Intellisense to use clang:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d4e3245da2111da3c263d8213b2e769/href">https://medium.com/media/5d4e3245da2111da3c263d8213b2e769/href</a></iframe><h3>Setting up the Debugger</h3><p>At this point, I would create a directory where I put swift example code that I would like to run the compiler on for debugging. I would recommend saving that folder in an environment variable called ${SWIFT_EXAMPLES_DIR} .</p><p>Once you’ve done this, go to the debug panel in VS Code, and click the gear icon in the top left. If prompted, select the option to make a new launch.json file. Copy and paste the following into that file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c99a459fe2e029e3c1c92925d8b281a/href">https://medium.com/media/9c99a459fe2e029e3c1c92925d8b281a/href</a></iframe><p>Now when you click the green play button in the debug panel, you will be prompted for a file to run the compiler on, and then the debugger will start.</p><h3>Useful Tasks</h3><p>VS Code allows you to specify tasks that it can run for you. The rest of the setup is all optional, but having these tasks in your editor will make your life a lot easier as they’ll automate some common tasks.</p><p>To add one of the tasks seen below, perform any setup specified, and then add the shown JSON to the list titled &quot;tasks&quot; in tasks.json .</p><p>If you want to assign keyboard shortcuts to any of these, go to Code &gt; Preferences &gt; Keyboard Shortcuts then click the { } symbol in the top right, then add the following to the JSON File with &lt;keyboard shortcut&gt; replaced with the desired shortcut, and &lt;task name&gt; replaced with the desired task’s name:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d41a6513af9ab69f022d6bc5050f374/href">https://medium.com/media/2d41a6513af9ab69f022d6bc5050f374/href</a></iframe><h3>Format Your Changes</h3><p>The Swift codebase uses clang-format with the LLDB style to format C++. Using the built in C/C++ formatter would work, however you’ll also fix formatting in parts of the file you didn’t touch which is likely outside of the scope of any changes you’ll be making. To solve this, we’re going to use git-clang-format .</p><p>First, you’ll have to add git-clang-format to your path. A copy of the git-clang-format binary can be found in swift-source/clang/tools/clang-format . Add that folder to your path.</p><p>Finally, add the following task to your list of tasks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4140ddeb7a7065205c0b8a6fcae72fb/href">https://medium.com/media/c4140ddeb7a7065205c0b8a6fcae72fb/href</a></iframe><h3>Build The Project</h3><p>Once you’ve performed an initial build, you can use the build system ninja to perform much faster incremental builds. The following task adds build tasks for two of the most common targets, and sets the default build task (which can easily be run with Command + Shift + B to build the compiler itself.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea66546b523ca774a174afd88d9450c8/href">https://medium.com/media/ea66546b523ca774a174afd88d9450c8/href</a></iframe><h3>Run Tests</h3><p>Swift tests can be easily run using LLVM lit. In order to set up the following tasks, first, you’ll need to save the directory containing lit as an environment variable. Lit can be found in swift-source/llvm/utils/lit . Save that directory as the environment variable LLVM_LIT_DIR . Then, add the following to your tasks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd336172815a604003a70f1378632fe5/href">https://medium.com/media/bd336172815a604003a70f1378632fe5/href</a></iframe><p>You’ll also need to add the following to the list called &quot;inputs” in the same file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53fb89ac9391cf7c74570db2da5ba0d8/href">https://medium.com/media/53fb89ac9391cf7c74570db2da5ba0d8/href</a></iframe><h3>Full tasks.json File</h3><p>For reference, my full tasks.json file looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83e920f2e1c34d1ddbf3288768440613/href">https://medium.com/media/83e920f2e1c34d1ddbf3288768440613/href</a></iframe><h3>Conclusion</h3><p>Thank you for reading! I hope you found this guide helpful. If you have any questions or notice anything in this post that needs correcting, feel free to leave a comment and I’d be happy to respond.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57f7ed01113" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why an Answer Became a Blog]]></title>
            <link>https://medium.com/@samlazarus/why-an-answer-became-a-blog-2d2a70dc5aa5?source=rss-71872d5042f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d2a70dc5aa5</guid>
            <category><![CDATA[quora]]></category>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Sam Lazarus]]></dc:creator>
            <pubDate>Mon, 02 Apr 2018 22:33:59 GMT</pubDate>
            <atom:updated>2018-04-02T22:33:59.893Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y_LA4YVAdZEVJ6ZiseCCmw.png" /><figcaption>As is tradition, we begin with a “Hello World!” Who says beginnings can’t be interesting?</figcaption></figure><p>The other day, I made <a href="https://www.quora.com/In-a-game-program-do-bullets-check-if-they-hit-an-enemy-or-do-enemies-check-if-they-are-hit-by-a-bullet/answer/Sam-Lazarus-10?__filter__&amp;__nsrc__=2&amp;__snid3__=2150902487">a post on Quora</a> answering a seemingly simple question. That post blew up, and somehow, as of today, a quarter million people have read my response. I almost can’t fathom the number of people that my words reached. Clearly, this is an indicator that I did something right. I was mentioning this bizarre success to a friend, and he somewhat jokingly recommended that I jump at the opportunity and start <a href="https://xkcd.com/741/">blogging</a>. My first thought was: “that’s an interesting idea, but I’m sure no one wants to read <em>my</em> musings about my personal hobby.” After some more thought though, I realized that while no one wants to hear what I specifically have to say, the things that I say may be able to fill some kind of void. It’s because of this that I decided to give it a go, so here we are. I’m itching to jump into my own ramblings just about as much as I hope you are to hear them, but first, I wanted to figure out what it is that I intend to accomplish by putting my thoughts out there on the internet.</p><p>To figure this out, I decided to take a look at what it was that made my Quora post successful in the first place. If such a post could capture the imagination of so many people, hopefully, a similar series of articles could as well. After hours of pouring over the comments on that post, I’ve come to the conclusion that my response was successful not because of the answer I gave, but because of how I gave it. I realized there were very few bloggers that attempt explain what makes Computer Science so special in a way that those without a technical background can understand.</p><blockquote>My post appealed to those with a technical background because it touched on a fundamental quandary of Computer Science, and it appealed to those without one because it did so in an approachable manner. My goal is to appeal to both those new to, and those knowledgeable about the field in a similar manner.</blockquote><p>Often, when I talk to high schoolers, children, or those outside of the field of Computer Science, they assume learning to program is similar to learning a language. I completely understand why this misconception is so common. “Programming language” contains the word “language”! How could they not be similar<a href="https://xkcd.com/1209/">‽</a> To me though, this shows a fundamental misunderstanding amongst the general public regarding what Computer Scientists <em>actually do. </em>If learning a programming language is like learning a linguistic language, then programming itself is more akin to writing poetry than to speaking in prose. A language is a tool, and Computer Scientists learn to use those tools so we can do our real job: <strong>solving problems</strong>. In fact, some of the greatest minds in the world of computing did their work <em>before computers existed</em>.</p><p>I realize that this goal that I’ve set out to accomplish is no easy task, and I’m in no way a qualified enough writer to tackle it alone. I’m not even as qualified as most in my own field. My hope is that I’ll start the blog off headed in close to the right direction, and I’ll perfect my course based on feedback from the community. Eventually, maybe I’ll be able to hit the sweet spot between technical, and relatable, filling the void I set out to explore.</p><p>Thanks for reading this introduction, and I hope to have my first real article up as soon as possible.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d2a70dc5aa5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>