Wednesday, December 21, 2022

Rust Evolve

Two decades ago, I wrote the book Advanced Java Game Programming which taught readers how to make animated 2D games that would run in a webpage.  Now I am learning how to do that using Rust and WebAssemblyEvolve is an animated interactive evolutionary algorithm simulation that you can play with that I recently converted from Java to Rust.  The code is available from my open source repository.

Thursday, November 24, 2022

Using the rust-webpack-template

Using the rust-webpack-template is a checklist that I made for setting up projects that use Rust and WebAssembly instead of JavaScript to dynamically create webpage content.  Since rust-webpack-template has not been updated for a few years, the checklist includes steps for dealing with outdated dependencies.  It also includes starter code and an extensive list of related links.

Monday, October 03, 2022

Into ZAMs

Previously I wrote about using Zero Arguments Methods (ZAMs) as a work-around for the Rust programming language not yet supporting named arguments.  Here I show how an Into trait implementation can be used as a ZAM.  I start from a conventional unnamed arguments function that I gradually convert into an Into ZAM.

Start with an output structure for your calculation:

pub struct RotationMatrix {
  pub rows: [[f64; 3]; 3],

Make an associated function that takes in a number of unnamed arguments, performs the calculations, and then returns the result as the output structure.

let rotation_matrix: RotationMatrix
  = RotationMatrix::from_degrees(-45.0, 90.0, 135.0);

Next, to support named arguments, modify your associated function to accept an input structure as the sole argument:

pub struct RotationDegrees {
  pub x: f64,
  pub y: f64,
  pub z: f64,

let rotation_matrix: RotationMatrix
  = RotationMatrix::from_degrees(
    RotationDegrees {
      x: -45.0,
      y: 90.0,
      z: 135.0,

To make a ZAM, you could move the calculation code from an associated function on the output structure to a method on the input structure:

let rotation_degrees = RotationDegrees {
  x: -45.0,
  y: 90.0,
  z: 135.0,

let rotation_matrix: RotationMatrix
  = rotation_degrees.to_rotation_matrix();

Instead, however, move the calculation code to a From trait implementation:

impl From<RotationDegrees> for RotationMatrix {
  fn from(rotation_degrees: RotationDegrees) -> Self {
    // [...]

let rotation_matrix: RotationMatrix
  = RotationMatrix::from(rotation_degrees);

Implementing the From trait automatically implements the Into trait which now serves as your ZAM:

let rotation_matrix: RotationMatrix
  = rotation_degrees.into();

Saturday, September 17, 2022

Rust Podcast List

Previously I wrote about how I have been enjoying listening to Rust programming language podcasts.  Since then, I have discovered three more Rust podcasts for a total of six.  Today I updated my list of all Rust podcasts on the CroftSoft Links webpage.

Saturday, August 13, 2022

Sycamore Prototype

Today I launched a new open source project, the CroftSoft Sycamore Prototype.  This is a conversion of one of my old Angular-based CSS Grid Layout demonstrations to the Rust-based front-end framework Sycamore.  My portfolio page has a link to a demonstration of the in-progress prototype.

Previously I was focusing on the far more popular Yew framework but according to this comparisons webpage on the Perseus website, Yew does not support static site generation (SSG) and server side rendering (SSR).  Perseus appears to be a framework layered on top of Sycamore which does support SSG and SSR.  Besides Sycamore / Perseus, another framework that I am considering is Dioxus.

Rust Project Setup

I started a new tutorial webpage providing a Rust Project Setup checklist. In addition to project directory creation and customization, it includes preliminary development steps such as tool installation. I am going to be adding to this over time as I use it.

Friday, August 12, 2022

Rust Podcasts

I have enjoyed listening to the Rust programming language podcast Rustacean Station. I like this podcast because it is not always the same host speaking. Now that I am all caught up with all eighty-eight episodes published to date, I searched for a different Rust podcast to listen to while I wait for the next episode to come out.

Fortunately one of the more recent episodes of Rustacean Station is an interview with the former host of the now defunct podcast New Rustacean with one hundred and three episodes available. I listened to the first episode tonight and it sounds like I am in for a high quality experience. I have also sampled the start of the first of nine episodes of the podcast Rust Game Dev.

Friday, August 05, 2022

Zero Arguments Methods

In my book Advanced Java Game Programming, I have a sidebar recommending named notation as a work-around for the Java programming language not supporting named arguments.  Here is the example from the book as converted to the Rust programming language:

let game_data = SerializableGameData::new(
  10,  // health
  99,  // wealth
  18); // wisdom

There is a proposal to bring named arguments to Rust but until this proposal is adopted I have started using a new work-around which I am calling "zero arguments methods".  Here is a static function to be converted:

pub fn periodic_savings_needed(
  f: f64,
  r: f64,
  t: f64,
) -> f64 {
  f * r / ((1.0 + r).powf(t) - 1.0)

Here is the equivalent using a zero arguments method:

#[derive(Clone, Copy, Debug)]
pub struct PeriodicSavingsNeeded {
  pub future_value: f64,
  pub interest_rate: f64,
  pub time_periods: f64,

impl PeriodicSavingsNeeded {
  pub fn calculate(&self) -> f64 {
    let f = self.future_value;
    let r = self.interest_rate;
    let t = self.time_periods;
    f * r / ((1.0 + r).powf(t) - 1.0)

Here is how the zero arguments method can be called:

let calculated_value = PeriodicSavingsNeeded {
  future_value:  1_000_000.0,

  interest_rate: 0.12,
  time_periods:  10.0,


Saturday, July 30, 2022

First Published Crate

Today I published my first Rust crate to  Crate com-croftsoft-core is an adaption to Rust of the Java-based CroftSoft Core Library.  After publishing this crate, I was able to use it as a dependency in my Yew-based retirement calculator.

The crate only has a single financial calculation function and a few constants right now.  I hope to eventually expand it to include most of the code from the CroftSoft Core Library.  Converting my old Java code library is another way for me to learn the Rust programming language.

Sunday, July 24, 2022

Rust, WebSockets, and Yew

Almost two decades ago when I wrote my book Advanced Java Game Programming, I ended it with three chapters on the subject of multiplayer network communications over Hypertext Transfer Protocol (HTTP).  The final chapter demonstrated a browser-based chat applet in which 2D characters would move about in response to player clicks on the screen.  I described how to use what I called "HTTP Pulling", now known as HTTP Long Polling, to receive messages from the server through the firewall.

The modern replacement for HTTP Long Polling is WebSockets which is now supported in all major browsersLast weekend I was able to write my first browser-based application in the Rust programming language by using the Rust-based front-end framework Yew.  Today I was pleased to be able to successfully implement a browser-based chat application using WebSockets and Yew by following the instructions in the online tutorial Let’s Build a WebSockets Project With Rust and Yew 0.19 by Johnny Tordgeman.


Sunday, July 17, 2022

The Rust Book

Tonight I finished reading The Rust Programming Language, informally known as "The Rust Book", by Steve Klabnik and Carol Nichols with contributions from the Rust Community.  The print copy published by No Starch Press covers the 2018 Edition of Rust.  There is also a free online version which is updated continuously.

I had started reading the Rust book last year and made it three-quarters of the way through.  This year I restarted from the beginning so I could refresh on the fundamentals.  It helped me understand a couple of Rust game programming books that I was reading simultaneously.

The book is well written with many code examples which are described in detail.  The authors ease the readers into the subject but then rapidly advance to more complicated topics in later chapters.  I assume that this is because they wanted to cover the entire programming language in just over five hundred pages.

I searched the Web to see if there is a second edition of the book coming out that covers the 2021 Edition of the Rust programming language.  Apparently there is not so I might start reading the online version for the updates and to review the material.  To help take me to the next level, I ordered from the same publisher Rust for Rustaceans: Idiomatic Programming for Experienced Developers by Jon Gjengset.

Saturday, July 16, 2022

Retirement Calculator

Back in 1999 when the stock market was doing well, I wrote a browser-based retirement calculator application using the Java Servlet framework.  Since a Java Servlet renders the Hypertext Markup Language (HTML) server-side, the application stopped working when I stopped using the Java application server.  Since the application does not fetch or store data using a back-end server, I could have re-written the calculator as a JavaScript-based application and simply hosted it on a website fronted by a Content Delivery Network (CDN).

Now in 2022 when the stock market is not doing so well, I converted the application to my new favorite programming language Rust using the front-end framework Yew.  Yew compiles the Rust code to WebAssembly (Wasm) which then runs in the browser just like JavaScript.  You can view the converted source code and play with an online demonstration hosted on one of my websites deployed using Amazon Web Services (AWS) Amplify Hosting.


Sunday, July 10, 2022

Rust and WebAssembly

My New Year's resolution this year was to learn the new Rust programming language.  I wrote a Hello, World! program in Rust many years ago and started reading the Rust book last year but now I am really getting into it.  You can follow my efforts on my new GitHub account.

My older open source Java code is hosted on  Many of my applications are Java game applets.  Now that Web browsers no longer support applets, I am exploring WebAssembly which can run both in browsers and in servers.

Today I was able to deploy a game that runs in the browser by following the instructions in the book Game Development with Rust & WebAssembly by Eric Smith.  I wrote the code in Rust, compiled it to WebAssembly, and then wrapped it in a thin layer of JavaScript so that it can run in a webpage.  You can play the game online at my GameSpawn website.

Sunday, June 26, 2022

Specialist Pools

If a software development team gets to be too large, you might be able to refactor a monolithic application into microservices.  You can then split the team into smaller teams, each dedicated to its own microservice.  Within the smaller team, you can have specialists, each focused on a different technology such as front-end, back-end, automated testing, or DevSecOps.

If you instead decide to keep the larger team dedicated to a single codebase, you might be able to split the team into Specialist Pools.  Each pool of specialists is focused on a single technology and each has its own Specialist Lead.  Since not all feature development stories require work in all technologies, members of the specialist pool can be assigned as needed where needed.

At regular increments of some number of months, one member of each pool can be rotated to another pool.  This permits the developer to get breadth across the technologies while at the same time conserving the depth of knowledge within the remaining members of the pool.  If more than one developer from a pool is volunteering to rotate, the one who has been in the pool the longest might be given preference.