<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Collin Donnell</title>
    <description>The latest articles on DEV Community by Collin Donnell (@collindonnell).</description>
    <link>https://dev.to/collindonnell</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F846460%2Fe71688fc-861d-43e1-b35c-15692a81f11c.jpeg</url>
      <title>DEV Community: Collin Donnell</title>
      <link>https://dev.to/collindonnell</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/collindonnell"/>
    <language>en</language>
    <item>
      <title>Debugging Rails in Visual Studio Code When Using Puma-dev</title>
      <dc:creator>Collin Donnell</dc:creator>
      <pubDate>Sat, 21 May 2022 02:19:10 +0000</pubDate>
      <link>https://dev.to/collindonnell/debugging-rails-in-visual-studio-code-when-using-puma-dev-mp2</link>
      <guid>https://dev.to/collindonnell/debugging-rails-in-visual-studio-code-when-using-puma-dev-mp2</guid>
      <description>&lt;p&gt;Coming from languages like Swift and Objective-C, using a proper debugger where I don’t have to edit my code to log something or pause execution is pretty critical for tracking down issues quickly. So — I thought — we’re using &lt;code&gt;puma-dev&lt;/code&gt; to run our Rails app during development, that’s a common setup, and so there must be easy instructions for how to attach Visual Studio Code’s debugger to a running app. Well, not that I could find. I did manage to patch it together through a combination of reading Stack Overflow posts and experimentation.&lt;/p&gt;

&lt;p&gt;So, here it is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set up debug port environment variable
&lt;/h2&gt;

&lt;p&gt;First, we need to add an environment variable in a place that puma-dev will load from. I put mine in &lt;code&gt;~/.powconfig&lt;/code&gt;, because that’s the first thing that gets loaded and it’s in my home directory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Edit &lt;code&gt;~/.powconfig&lt;/code&gt; to include this:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;export RUBY_DEBUG_PORT=1234&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Update Gemfile
&lt;/h2&gt;

&lt;p&gt;Make sure you’ve got these under &lt;code&gt;:development&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s2"&gt;"ruby-debug-ide"&lt;/span&gt;
&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s2"&gt;"debase"&lt;/span&gt; &lt;span class="c1"&gt;# or byebug&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I’m sure there’s a way to make this work with the new debugger that comes packaged with Ruby 3.1+ (&lt;code&gt;rdbg&lt;/code&gt;), but that’s going to be an exercise for another time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add Rails initializer to start &lt;code&gt;rdebug-ide&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Create a file in &lt;code&gt;/config/initializers/&lt;/code&gt; called &lt;code&gt;start_debugger.rb&lt;/code&gt; (or whatever you want), and add this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;development?&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'RUBY_DEBUG_PORT'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s2"&gt;"ruby-debug-ide"&lt;/span&gt;
  &lt;span class="no"&gt;Debugger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start_server&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'RUBY_DEBUG_PORT'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;to_i&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Add Launch Target to project in Visual Studio Code
&lt;/h2&gt;

&lt;p&gt;Add this configuration to &lt;code&gt;&amp;lt;app root&amp;gt;/.vscode/launch.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"configurations"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Remote Debug"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Ruby"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"request"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"attach"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"remoteHost"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"127.0.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"remotePort"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1234"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"remoteWorkspaceRoot"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"${workspaceRoot}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"cwd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"${workspaceRoot}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Finally
&lt;/h2&gt;

&lt;p&gt;Restart your app with &lt;code&gt;touch tmp/restart.txt&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Test it out by running “Remote Debug”, setting a breakpoint in one of your controllers, and refreshing the page that will trigger the code. If everything is setup correctly, your app should pause at the breakpoint. &lt;/p&gt;

&lt;p&gt;Congratulations! 🎉 &lt;/p&gt;

</description>
      <category>rails</category>
      <category>vscode</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>The Brilliance of `nil` in Objective-C</title>
      <dc:creator>Collin Donnell</dc:creator>
      <pubDate>Fri, 29 Apr 2022 20:10:03 +0000</pubDate>
      <link>https://dev.to/collindonnell/the-brilliance-of-nil-in-objective-c-23be</link>
      <guid>https://dev.to/collindonnell/the-brilliance-of-nil-in-objective-c-23be</guid>
      <description>&lt;p&gt;I don’t code much in &lt;a href="https://en.wikipedia.org/wiki/Objective-C"&gt;Objective-C&lt;/a&gt; these days&lt;sup id="fnref1"&gt;1&lt;/sup&gt; but one thing I miss about it compared to Swift is how &lt;code&gt;nil&lt;/code&gt; works.&lt;/p&gt;

&lt;p&gt;To be fair to Swift, the concept of “nothing” in Objective-C is kind of a mess, since there’s four different versions of it compared to two in Swift.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;tr&gt;
    &lt;td&gt;
&lt;code&gt;nil&lt;/code&gt;
    &lt;/td&gt;
&lt;td&gt;An empty Objective-C object.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td&gt;&lt;code&gt;Nil&lt;/code&gt;&lt;/td&gt;
    &lt;td&gt;An empty Objective-C class.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td&gt;&lt;code&gt;NULL&lt;/code&gt;&lt;/td&gt;
    &lt;td&gt;Nothing in C.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td&gt;&lt;code&gt;NSNull&lt;/code&gt;&lt;/td&gt;
    &lt;td&gt;Mostly used to represent null in Objective-C collections.&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The reason &lt;code&gt;NSNull&lt;/code&gt; exists is that Objective-C collections (&lt;code&gt;NSArray&lt;/code&gt;, &lt;code&gt;NSDictionary&lt;/code&gt;) use &lt;code&gt;nil&lt;/code&gt; in other ways. &lt;code&gt;NSArray&lt;/code&gt; is &lt;code&gt;nil&lt;/code&gt; terminated, so if you did this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight objective_c"&gt;&lt;code&gt;&lt;span class="n"&gt;NSArray&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;@[&lt;/span&gt;&lt;span class="s"&gt;@"a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;@"b"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;@"c"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="c1"&gt;// array = [@"a", @"b"] &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'd only have the first two elements available. In &lt;code&gt;NSDictionary&lt;/code&gt;, setting a key to &lt;code&gt;nil&lt;/code&gt; removes it from the dictionary, so &lt;code&gt;NSNull&lt;/code&gt; is used to say “this exists in the dictionary, and it is nothing.”&lt;/p&gt;

&lt;p&gt;The main thing to remember is that if you have a pointer assigned to &lt;code&gt;NSNull&lt;/code&gt; or &lt;code&gt;NULL&lt;/code&gt; and you try to do something with them, your app will crash. &lt;code&gt;nil&lt;/code&gt; on the other hand is kind of magic. &lt;code&gt;nil&lt;/code&gt; evaluates to &lt;code&gt;NO&lt;/code&gt; (&lt;code&gt;false&lt;/code&gt;), and &lt;code&gt;nil&lt;/code&gt; as an object always returns &lt;code&gt;nil&lt;/code&gt;. That means that because whatever you sent to &lt;code&gt;nil&lt;/code&gt; will return &lt;code&gt;nil&lt;/code&gt; and that will evaluate to false instead of crashing your app that this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight objective_c"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dict&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nb"&gt;nil&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;amp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;amp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;containsObjectForKey&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;@"a"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Can become this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight objective_c"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;containsObjectForKey&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;@"a"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is probably the least-Swift thing ever, but, if you're used to coding in this style, it's fantastic. In a lot (most?) cases where there's a possibility that &lt;code&gt;dict&lt;/code&gt; could be &lt;code&gt;nil&lt;/code&gt;, the thing you want is for nothing to happen. Way back when Swift was first released, and &lt;a href="https://inessential.com/2014/08/12/carlfish"&gt;Brent said&lt;/a&gt; switching to Swift “feels like a Jedi who’s trying to switch from a lightsaber to a blaster,” this is what I thought of.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://collindonnell.com/2022/04/28/the-brilliance-of-nil-in-objective-c/"&gt;&lt;em&gt;Originally posted on collindonnell.com&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;




&lt;ol&gt;

&lt;li id="fn1"&gt;
&lt;p&gt;Although a lot more than &lt;em&gt;none&lt;/em&gt;, and I still think it’s important to know if you’re writing software for Apple Platforms. ↩&lt;/p&gt;
&lt;/li&gt;

&lt;/ol&gt;

</description>
      <category>programming</category>
      <category>languages</category>
      <category>mobile</category>
    </item>
  </channel>
</rss>
