<?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>Forem: Si Dunn</title>
    <description>The latest articles on Forem by Si Dunn (@sidunn).</description>
    <link>https://forem.com/sidunn</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%2F999932%2F0a8acb1e-ea60-4051-bab6-f730de5823a2.jpeg</url>
      <title>Forem: Si Dunn</title>
      <link>https://forem.com/sidunn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sidunn"/>
    <language>en</language>
    <item>
      <title>Hello, Rust. This is C. Play Nice!</title>
      <dc:creator>Si Dunn</dc:creator>
      <pubDate>Wed, 15 Feb 2023 01:20:47 +0000</pubDate>
      <link>https://forem.com/sidunn/hello-rust-this-is-c-play-nice-28id</link>
      <guid>https://forem.com/sidunn/hello-rust-this-is-c-play-nice-28id</guid>
      <description>&lt;h3&gt;
  
  
  How to compile and run a 'Hello World' C script using a Rust build file with the cc crate.
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;In a&lt;/strong&gt; &lt;a href="https://dev.to/sidunn/macro-roni-ai-yi-yi-3fce"&gt;previous post&lt;/a&gt; here on Dev, I grumbled about being impatient while learning Rust. And, after floundering miserably at Rust procedural macros, I promised to go back to the Rust Playground and get more experience.&lt;/p&gt;

&lt;p&gt;On my way back there, however, I stopped off long enough to look through some of &lt;a href="https://doc.rust-lang.org/cargo/reference/build-script-examples.html?highlight=hello.c#building-a-native-library" rel="noopener noreferrer"&gt;The Cargo Book&lt;/a&gt; and found a simple way to compile and display a "Hello, World" C file by adding it to a Rust build script.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check out&lt;/strong&gt; the "Build a Native Library" section of &lt;em&gt;The Cargo Book&lt;/em&gt; and look at its examples. I chose to focus on the Rust build script using a build-dependencies entry from &lt;a href="https://crates.io" rel="noopener noreferrer"&gt;Crates.io&lt;/a&gt;. &lt;strong&gt;cc-rs&lt;/strong&gt; is "[a] library to compile C/C++/assembly into a Rust library/application."&lt;/p&gt;

&lt;p&gt;In &lt;em&gt;The Cargo Book&lt;/em&gt;, find the text that begins: &lt;em&gt;"Not to fear, though, this is where a build-dependencies entry would help!"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enter and save&lt;/strong&gt; the simple code examples that are shown. And be sure to place each file in the correct subdirectory. For example, the &lt;em&gt;build.rs&lt;/em&gt; file should not be placed into the &lt;em&gt;src&lt;/em&gt; folder. Put it in the folder with the &lt;em&gt;Cargo.toml&lt;/em&gt; file. Meanwhile, be sure the &lt;em&gt;hello.c&lt;/em&gt; file is placed in the &lt;em&gt;src&lt;/em&gt; folder, along with the main.rs file.&lt;/p&gt;

&lt;p&gt;I chose to add two more "message" lines to the &lt;em&gt;printf();&lt;/em&gt; portion of the boring &lt;em&gt;hello.c&lt;/em&gt; file. This C file is compiled and displays text on the screen right after you enter &lt;code&gt;cargo build&lt;/code&gt; at the prompt and then  &lt;code&gt;cargo run&lt;/code&gt;. Here is my &lt;em&gt;hello.c&lt;/em&gt; example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// hello.c - Simple C program to display "Hello World"  
// Header file for input output functions
#include &amp;lt;stdio.h&amp;gt;
// main function - where program execution begins
void hello(){
// prints hello world
printf("Hello, Rust World! This is a message from C World!\n");
printf("And another message to Rust World from C World!\n");
printf("But now, that's all, folks!\n");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\sidun\Documents\Rust_code\projects\hello-world-from-c&amp;gt;cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `target\debug\hello-world-from-c.exe`
Hello, Rust World! This is a message from C World!
And another message to Rust World from C World!
But now, that's all, folks!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;After getting ahead&lt;/strong&gt; of my Rust-beginner skills and floundering at procedural macros, it has been nice little confidence boost to see that I can get some Rust and C to work together. If you are a Rust beginner, be sure to spend some quality study time with &lt;a href="https://doc.rust-lang.org/cargo/guide/" rel="noopener noreferrer"&gt;The Cargo Book&lt;/a&gt;, as well as &lt;a href="https://doc.rust-lang.org/book/" rel="noopener noreferrer"&gt;The Rust Programming Language&lt;/a&gt; book.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv1m28ahxazkzwr44cs3m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv1m28ahxazkzwr44cs3m.png" alt="Cargo run...for the win!" width="598" height="189"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  Cover image credit: &lt;em&gt;Photo by Si Dunn&lt;/em&gt;
&lt;/h6&gt;

</description>
    </item>
    <item>
      <title>Macro-Roni? AI-yi-yi!</title>
      <dc:creator>Si Dunn</dc:creator>
      <pubDate>Wed, 08 Feb 2023 21:16:11 +0000</pubDate>
      <link>https://forem.com/sidunn/macro-roni-ai-yi-yi-3fce</link>
      <guid>https://forem.com/sidunn/macro-roni-ai-yi-yi-3fce</guid>
      <description>&lt;h3&gt;Old Tutorials, ChatGPT, and No Mentor: How I Failed to Build a Rust Procedural Macro That Worked. (Until One Finally Did.)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Have you&lt;/em&gt;&lt;/strong&gt; heard the old saying "Never get ahead of your skis"? Or your skates? Or your common sense?&lt;/p&gt;

&lt;p&gt;Recently, I got tired of being a post-"Hello, world" Rust newbie, especially one who has been plodding forward at a turtle-like, spare-time pace. I've been trying to become competent at Rust by using books, online tutorials, and no in-person guidance, one code example at a time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rust is&lt;/strong&gt; not an easy language to learn, especially &lt;em&gt;that&lt;/em&gt; way. And, unfortunately, I still work remotely and must--for survival's sake--minimize my exposure to a wide range of illnesses. That sums up my basic path forward.&lt;/p&gt;

&lt;p&gt;In a burst of impatience, however, I decided to vault ahead and tackle something more substantial than, say, shadowing or immutability, in (another old saying) one fell swoop. After all, I had successfully done some remote work not long ago that required a few basic Rust skills. Whatever I jumped into next involving Rust, I could figure out on the fly, I reasoned. &lt;em&gt;Nope!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Out of the digital blue&lt;/strong&gt;, and without fully comprehending what the term meant, I decided I would teach myself how to create a Rust procedural macro. &lt;em&gt;Easy, peasy&lt;/em&gt;, I reasoned. What could be hard about making some macro-&lt;em&gt;roni&lt;/em&gt;? &lt;/p&gt;

&lt;p&gt;Speaking of fell swoops and getting ahead of one's skis, let's note my photograph (above) of the failing, falling pole vaulter and move on to some other sports imagery. When I swooped off the end of Rust's macro ski jump on my first attempt and briefly stood on thin air like the cartoon character Wile E. Coyote...I realized I had left both skis behind, neatly parked at the top of the run. The hard landing that followed completely broke my common sense. Indeed, I ran back up the macro mountain to try again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I re-consulted&lt;/strong&gt; a Rust how-to book for more information. The book described the alleged wonders of procedural macros but gave no complete code examples. I found some aging procedural macro tutorials online and carefully copied their code. Cargo test? Fail. Cargo build? Fail. Some of them tried to compile, then flashed some error messages. Cargo run? Exactly none.&lt;/p&gt;

&lt;p&gt;Over the next two days, I tried to run and rework the code from several tutorial examples. Always, there were frustrating holes in the how-to descriptions. And clear assumptions had been made that those attempting the tutorials would be smarter and more experienced at Rust than I was. My code "fixes" only made matters worse.     &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Finally, completely&lt;/strong&gt; flummoxed by failing to compile even a "Hello, world" procedural macro, I decided to cheat and get help from AI. I asked ChatGPT to show me the code and describe all steps necessary to build a simple, working example.&lt;/p&gt;

&lt;p&gt;It took a few minutes to get a response from the wildly popular, overloaded site. But I eagerly copied the arriving code and followed each calm, confident step in the AI-generated tutorial. The secrets of procedural macros were about to be revealed at last, I believed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cargo build?&lt;/strong&gt; Nope. Fail. And this time, I spotted a startling code typo. The "all knowing" AI had told me to use proc-macro in a place where proc_macro clearly was correct. Fixing that, of course, still did nothing to solve my dilemma. Cryptic new error messages appeared.&lt;/p&gt;

&lt;p&gt;Defeated at last, I deleted the entire procedural macro saga from my hard drive and vowed to quit Rust. Perhaps I could go home to Python, I reasoned. Or take up C# again and maybe build some model airplanes on the side. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Breaking news!&lt;/strong&gt; After completely giving up Rust &lt;em&gt;forever&lt;/em&gt; for a few hours, I came back for one more round of macro boxing. This time, I ducked and weaved--and noodled around on the web a bit more. And I came across something I should have paid much closer attention to many days ago: &lt;a href="https://doc.rust-lang.org/book/" rel="noopener noreferrer"&gt;The Rust Programming Language&lt;/a&gt; book. Very close to the end of its huge piles of pages, it offers some &lt;a href="https://doc.rust-lang.org/book/ch19-06-macros.html" rel="noopener noreferrer"&gt;procedural macro examples&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I chose "How to Write a Custom derive Macro." And once again, I ran into descriptions that seemed short on a few essential details. I kept doing the code &lt;em&gt;as shown&lt;/em&gt;, and Cargo build kept failing. Finally, almost by accident, I clicked on a screen prompt I had not noticed before: The hidden-lines link in Listing 19-33. The hidden lines now popped into view, and I quickly saw where and why my coding was going off the rails. Copy, paste, Cargo build, Cargo run...for the &lt;em&gt;win&lt;/em&gt;! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1idji6qg2e0tfpfz6et0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1idji6qg2e0tfpfz6et0.png" alt="All of this...just for Pancakes???"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What's the moral&lt;/strong&gt; of this story? For me, it's this: I need to reach out more often from my pandemic-walled-off, remote-work castle and humbly ask for help from people who don't mind showing a newbie how to do something that's over his or her head. Trying to learn Rust in a vacuum is a sure-fire way to quickly run out of air. Other newbies should remember this, too, I believe.&lt;/p&gt;

&lt;p&gt;Also, I need to go straight back to the Rust playground, stay in line, keep learning patiently, and get much better at the basics first. I've been to the procedural macro mountaintop, yes, and discovered I was almost completely clueless about what I could do once that I was there.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When I do&lt;/strong&gt; return, please do me one small favor in honor of the procedural macro that I finally got to work. &lt;em&gt;Don't&lt;/em&gt; call me "Pancakes."&lt;/p&gt;

&lt;h6&gt;
  
  
  Cover image credit: &lt;em&gt;Photo by Si Dunn&lt;/em&gt;
&lt;/h6&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>rust</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Rust(y) Cargo!</title>
      <dc:creator>Si Dunn</dc:creator>
      <pubDate>Thu, 19 Jan 2023 21:24:01 +0000</pubDate>
      <link>https://forem.com/sidunn/rusty-cargo-1g5i</link>
      <guid>https://forem.com/sidunn/rusty-cargo-1g5i</guid>
      <description>&lt;h3&gt;
  
  
  Installing Rust &amp;amp; Cargo on a Windows 10 PC
&lt;/h3&gt;

&lt;p&gt;The &lt;a href="https://www.rust-lang.org/" rel="noopener noreferrer"&gt;Rust website&lt;/a&gt; offers easy ways to install Rust and its build tool and package manager, Cargo, for several different operating systems.&lt;/p&gt;

&lt;p&gt;However, if you use a Windows 10 PC, the simplest path is to just click on the Rust site's "Install" link and choose &lt;em&gt;rustup&lt;/em&gt; as recommended. Depending on whether you are using a 32-bit or 64-bit Windows PC, click on the appropriate link to download the &lt;em&gt;rustup-init.exe&lt;/em&gt; file. (&lt;em&gt;Note:&lt;/em&gt; There is also a Rust download link for those who use a Windows subsystem for Linux.)     &lt;/p&gt;

&lt;p&gt;Pay close attention to the "Notes about Rust installation" section of the "Install Rust" page. Rust will try to configure the PATH environment variable during installation. But you may need to reboot your computer, or edit the PATH, or even reinstall Rust if there is a problem.&lt;/p&gt;

&lt;p&gt;Once installation is complete, go to a command prompt and enter the following commands in any order:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rustc --version&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rustdoc --version&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cargo --version&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You should get responses similar to these:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;c:\&amp;gt;rustc --version&lt;/code&gt;&lt;br&gt;
&lt;code&gt;rustc 1.66.1 (90743e729 2023-01-10)&lt;/code&gt;&lt;br&gt;
&lt;code&gt;c:\&amp;gt;rustdoc --version&lt;/code&gt;&lt;br&gt;
&lt;code&gt;rustdoc 1.66.1 (90743e729 2023-01-10)&lt;/code&gt;&lt;br&gt;
&lt;code&gt;c:\&amp;gt;cargo --version&lt;/code&gt;&lt;br&gt;
&lt;code&gt;cargo 1.66.1 (ad779e08b 2023-01-10)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Rust is working, so now take some time to look at &lt;a href="https://doc.rust-lang.org/cargo/index.html" rel="noopener noreferrer"&gt;The Cargo Book&lt;/a&gt;. According to that publication:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"Cargo is the Rust package manager. Cargo downloads your Rust package's dependencies, compiles your packages, makes distributable packages, and uploads them to crates.io, the Rust community’s package registry. You can contribute to this book on GitHub."&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;If you happen to have an older version of Rust already installed on your Windows PC, just run the command &lt;em&gt;rustup update&lt;/em&gt; to get the most-recent release. After Rust is updated, test the installation using the &lt;code&gt;--version&lt;/code&gt; commands listed above.&lt;/p&gt;

&lt;p&gt;Thanks for reading. Feedback welcome. (And yes, this is my first big try at writing something with Markdown, so I do have more to learn).&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>programming</category>
      <category>learning</category>
    </item>
    <item>
      <title>Learning from Out-of-date Online Tutorials &amp; Courses?</title>
      <dc:creator>Si Dunn</dc:creator>
      <pubDate>Sat, 07 Jan 2023 18:39:57 +0000</pubDate>
      <link>https://forem.com/sidunn/learning-from-out-of-date-online-tutorials-courses-1lhk</link>
      <guid>https://forem.com/sidunn/learning-from-out-of-date-online-tutorials-courses-1lhk</guid>
      <description>&lt;p&gt;&lt;strong&gt;To keep&lt;/strong&gt; expanding my software knowledge and coding skills, I search frequently for online tutorials and courses. But many that I find are in need of software updates and clearly are being neglected by the authors and/or companies that posted them. It's not helpful to me when I find an online project that looks intriguing yet requires considerably earlier versions of the software I have loaded and am now trying to learn.&lt;/p&gt;

&lt;p&gt;I'm guessing the tutorial or course authors did not get paid much, if anything, for their efforts or got very little feedback from those who used the materials. And now they have moved on to other opportunities and challenges in their software careers and have simply left their once-helpful materials marooned in cyberspace.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What can be&lt;/strong&gt; done about this, realistically? Try to contact the authors and ask them to update what they posted (or at least give you some guidance)? Attempt the tutorial project using the much-newer software releases and force yourself to try to debug and rewrite your way to completion? Use the bones of an outdated tutorial and try to create a new and somewhat different project? Or--???&lt;/p&gt;

&lt;p&gt;What approach(es) do you favor?      &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Hello, World(s)!</title>
      <dc:creator>Si Dunn</dc:creator>
      <pubDate>Fri, 06 Jan 2023 16:43:01 +0000</pubDate>
      <link>https://forem.com/sidunn/hello-worlds-cc2</link>
      <guid>https://forem.com/sidunn/hello-worlds-cc2</guid>
      <description>&lt;p&gt;&lt;strong&gt;Indeed&lt;/strong&gt;, hello, &lt;em&gt;multiple&lt;/em&gt; worlds! (As I mentioned in one of my posts on the Welcome thread, I have now moved past "Hello, World!" in several programming languages.)&lt;/p&gt;

&lt;p&gt;At age 78, soon to turn 79, I don't consider myself much of a software "developer." I'm more of a software hobbyist. Anyway, who's hiring developers born during World War II?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I retired&lt;/strong&gt; from software technical writing 14 years ago after working for several large telecommunications companies. I used to write hardware and software manuals and training courses and even tested some hardware and software. But that was long ago, in a younger universe...far, far away behind me.&lt;/p&gt;

&lt;p&gt;Over the past few years, however, I have been using software "development"--at the hobbyist level--as a way to help keep my aging brain alert, alive, and open to learning. In my own mind, at least, that daily tinkering seems to be working.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I'm now&lt;/strong&gt; in the process of learning how to get better at working with several software languages and frameworks. I also occasionally write online reviews of beginner-level software books. One other part of my learning process is to find relatively easy software projects, try them out, and attempt to make minor modifications that work (or blow up). I jump from one thing to another as my interests change, so skill-wise I tend to remain just a few steps above "Hello, World!" while I keep collecting more languages and packages to play with. Yes, I know. Definitely NOT the best way to develop any depth in my abilities.&lt;/p&gt;

&lt;p&gt;I'm trying to change some of that now, if only to pare down the number of "how to" binders and books currently stacked on my shelves. In short, I'm narrowing my focus a bit. For the near future, I intend to just center my attention on...Java, JavaScript, Rust, Python, C#, .Net, Angular, PostgreSQL, Go, Spring Boot, Haskell, and one or two others I can't seem to remember at the moment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Anyway&lt;/strong&gt;, as Buzz Lightyear &lt;em&gt;never&lt;/em&gt; said: "To infinite loops...and beyond!"  &lt;/p&gt;

&lt;p&gt;(&lt;em&gt;Cover photo by Si Dunn&lt;/em&gt;) &lt;/p&gt;

</description>
      <category>opensource</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
