<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ WebAssembly - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ WebAssembly - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sun, 24 May 2026 22:25:20 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/webassembly/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to use Rust + WebAssembly to Perform Serverless Machine Learning and Data Visualization in the Cloud ]]>
                </title>
                <description>
                    <![CDATA[ The Tencent Serverless Cloud Function Custom Runtime allows developers to write serverless functions in any programming language. In this article, we make the case for serverless functions in Rust and WebAssembly, and demonstrate their use in machine... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/rust-webassembly-serverless-tencent-cloud/</link>
                <guid isPermaLink="false">66d46050264384a65d5a95b0</guid>
                
                    <category>
                        <![CDATA[ Machine Learning ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Rust ]]>
                    </category>
                
                    <category>
                        <![CDATA[ WebAssembly ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 31 Aug 2020 16:26:16 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/08/origin_img_6f483a12-6885-4499-b35b-2e23c949ef8g.PNG" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>The Tencent Serverless Cloud Function Custom Runtime allows developers to write serverless functions in any programming language.</p>
<p>In this article, we make the case for serverless functions in Rust and WebAssembly, and demonstrate their use in machine learning and visualization.</p>
<p>You will learn how to create a simple function for machine learning and deploy a serverless web site around it, for free (unless a million people use it!).</p>
<h2 id="heading-first-what-is-tencent">First, what is Tencent?</h2>
<p>Tencent is the biggest Internet company outside of the USA with over a billion active daily users. Its cloud computing arm, <a target="_blank" href="https://cloud.tencent.com/?lang=en">Tencent Cloud</a>, is ranked among the top 5 cloud providers in the world by market share.</p>
<p>If you want to reach the world-wide market with your cloud services, Tencent Cloud should be near the top of your list.</p>
<p>Tencent Cloud is also a leading innovator in serverless computing with strong offerings ranging from Function as a Service (FaaS) runtimes, triggers, connectors, and developer tools.</p>
<p>The <a target="_blank" href="https://intl.cloud.tencent.com/document/product/583">Tencent Serverless Cloud Functions (SCF)</a> already support 10+ programming languages and runtime frameworks. But the recently released SCF Custom Runtime took another step forward. The SCF can now support functions written in any programming language.</p>
<p>In this article, I will cover how to run WebAssembly functions, written in Rust, in the SCF.</p>
<h3 id="heading-what-well-cover-in-this-article">What we'll cover in this article</h3>
<p>We will first go over the basic concepts. Then, we will review a complete but simple hello world example to deploy your first WebAssembly serverless function.</p>
<p>Finally, we will do something useful with a machine earning as a service (MLaaS) example that takes data and returns the fitted model and visualization in the SVG format.</p>
<p><a target="_blank" href="https://www.secondstate.io/demo/2020-tencentcloud.html">Here is the final application</a> you will create by the end of this tutorial. It is completely “serverless” and incurs cost when people use it.</p>
<p>The HTML and JavaScript UI can be hosted on any computer including your laptop, and the <a target="_blank" href="https://github.com/second-state/wasm-learning/tree/master/tencentcloud/ssvm/pca">backend function</a> to perform machine learning and SVG drawing is on Tencent Cloud Serverless.</p>
<h2 id="heading-why-webassembly-and-rust">Why WebAssembly and Rust</h2>
<p>Traditional serverless functions are based on heavy-weight frameworks. Developers must write functions in specific application frameworks, such as JavaScript in Node.js or Python Boto and so on.</p>
<p>The Tencent Cloud SCF Custom Runtime breaks this mold, and allows developers to write serverless functions in any language.</p>
<p>To demonstrate this point, it provides examples for a <a target="_blank" href="https://github.com/tencentyun/scf-demo-repo/tree/master/CustomRuntime-shellDemo">Bash script-based function</a>, a <a target="_blank" href="https://github.com/tencentyun/scf-demo-repo/tree/master/CustomRuntime-denoDemo">Deno-based TypeScript function</a>, and a <a target="_blank" href="https://github.com/tencentyun/scf-demo-repo/tree/master/CustomRuntime-rustDemo">Rust-based native binary function</a>. That allows us to create and deploy WebAssembly-based serverless functions on Tencent Cloud.</p>
<p>Why do we want to do that? Here are <a target="_blank" href="https://www.secondstate.io/articles/why-webassembly-server/">some reasons</a>.</p>
<ul>
<li><p>WebAssembly is designed for performance. <a target="_blank" href="https://www.secondstate.io/articles/performance-rust-wasm/">WebAssembly functions could be 10x faster</a> than comparable programs written in JavaScript or Python.</p>
</li>
<li><p>WebAssembly functions are portable. While it is possible to run native binaries on SCF Custom Runtime, those binaries must be compiled to the exact operating system environment for Custom Runtime. It is currently CentOS 7.6 on X86 CPUs, and could change later. WebAssembly functions are portable and very easy to deploy and manage as we will see.</p>
</li>
<li><p>WebAssembly functions are safe. It is known that even with Docker, native binary applications could breach the container. Since your application probably depends on many 3rd-party libraries, the risk for rogue code in your dependencies is real. WebAssembly, with its <a target="_blank" href="https://www.secondstate.io/articles/wasi-access-system-resources/">capability-based security model</a>, provides better runtime protection for your code.</p>
</li>
<li><p>While WebAssembly is agnostic to programming languages, Rust, AssemblyScript (a subset of TypeScript), C/C++, and Go are among the best languages to write WebAssembly functions. In particular, Rust is a popular and fast rising programming language with a passionate community. It allows us to write highly efficient, yet memory safe, functions.</p>
</li>
</ul>
<p>Finally, programming and deploy WebAssembly functions on Tencent Cloud is actually quite easy. You can do in it an hour. Let’s get started.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>First, sign up for a <a target="_blank" href="https://cloud.tencent.com/?lang=en">Tencent Cloud account</a>. For most development and personal projects, you can probably staying within its <a target="_blank" href="https://intl.cloud.tencent.com/document/product/583/12282">free tier</a> of service.</p>
<p>Then, on your local development computer or Docker container, make sure that you have Rust and <a target="_blank" href="https://www.secondstate.io/articles/ssvmup/">ssvmup</a> toolchain installed. The ssvmup toolchain compiles and optimizes Rust programs into WebAssembly bytecode.</p>
<p>Just use the following simple commands to install both. Or you can refer to <a target="_blank" href="https://www.secondstate.io/articles/ssvmup/">this guide</a>.</p>
<pre><code class="lang-bash">$ curl --proto <span class="hljs-string">'=https'</span> --tlsv1.2 -sSf https://sh.rustup.rs | sh
$ <span class="hljs-built_in">source</span> <span class="hljs-variable">$HOME</span>/.cargo/env
... ...
$ curl https://raw.githubusercontent.com/second-state/ssvmup/master/installer/init.sh -sSf | sh
</code></pre>
<p>The WebAssembly function is executed in the <a target="_blank" href="https://www.secondstate.io/ssvm/">Second State VM</a> — a <a target="_blank" href="https://www.secondstate.io/articles/ssvm-performance/">high-performance WebAssembly VM</a> optimized for server-side use cases and applications.</p>
<h2 id="heading-hello-world">Hello, world</h2>
<p>To get started with your first Rust and WebAssembly function on Tencent Cloud, we encourage your to clone or <a target="_blank" href="https://github.com/second-state/ssvm-tencent-starter">fork this template repository</a> on Github and use it as the basis for your own application.</p>
<p>The Rust function in <a target="_blank" href="https://github.com/second-state/ssvm-tencent-starter/blob/master/src/main.rs">main.rs</a> is the serverless function we will deploy to SCF. As you can see from its source code, it reads the function’s input from <code>STDIN</code>, and then use the <code>println!</code> macro to send results to the <code>STDOUT</code>.</p>
<pre><code class="lang-rust"><span class="hljs-keyword">use</span> std::io::{<span class="hljs-keyword">self</span>, Read};
<span class="hljs-keyword">use</span> serde::Deserialize;

<span class="hljs-function"><span class="hljs-keyword">fn</span> <span class="hljs-title">main</span></span>() {    
    <span class="hljs-keyword">let</span> <span class="hljs-keyword">mut</span> buffer = <span class="hljs-built_in">String</span>::new();    
    io::stdin().read_to_string(&amp;<span class="hljs-keyword">mut</span> buffer).expect(<span class="hljs-string">"Error reading from STDIN"</span>);    
    <span class="hljs-keyword">let</span> obj: FaasInput = serde_json::from_str(&amp;buffer).unwrap();    
    <span class="hljs-keyword">let</span> key1 = &amp;(obj.key1);    
    <span class="hljs-keyword">let</span> key2 = &amp;(obj.key2);    
    <span class="hljs-built_in">println!</span>(<span class="hljs-string">"Hello! {}, {}"</span>, key1, key2);
}

<span class="hljs-meta">#[derive(Deserialize, Debug)]</span>
<span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">FaasInput</span></span> {    
    key1: <span class="hljs-built_in">String</span>,    
    key2: <span class="hljs-built_in">String</span>
}
</code></pre>
<p>The Rust <code>main()</code> function uses the <code>serde</code> library to parse a JSON string from <code>STDIN</code>.</p>
<p>The JSON looks like the following. The reason we write the function this way is because this is the built-in hello world JSON template SCF uses to test deployed functions.</p>
<pre><code class="lang-json">{  
    <span class="hljs-attr">"key1"</span>: <span class="hljs-string">"test value 1"</span>,  
    <span class="hljs-attr">"key2"</span>: <span class="hljs-string">"test value 2"</span>
}
</code></pre>
<p>The function extracts the <code>key1</code> and <code>key2</code> values and outputs the following hello message to <code>STDOUT</code>.</p>
<pre><code class="lang-text">Hello! test value 1, test value 2
</code></pre>
<p>But, how does a web request to this function get translated into <code>STDIN</code>? And how does the function response in <code>STDOUT</code> get translated into a the HTTP response?</p>
<p>That is done by the SCF Custom Runtime infrastructure and the <a target="_blank" href="https://github.com/second-state/ssvm-tencent-starter/blob/master/cloud/bootstrap">bootstrap</a> program in our template.</p>
<p>As you can see, the <a target="_blank" href="https://github.com/second-state/ssvm-tencent-starter/blob/master/cloud/bootstrap">bootstrap</a> program is simply a bash shell program that continuously polls the SCF for incoming requests. It translates the incoming request to <code>STDIN</code> and calls the WebAssembly function through the SSVM. It then takes the <code>STDOUT</code> output and sends it back into SCF as the function’s response.</p>
<p>You do not need to modify the bootstrap program if you use our template.</p>
<p>Now, you can build the Rust function into WebAssembly bytecode with ssvmup, and then package a zip file for deployment on the Tencent Cloud SCF Custom Runtime.</p>
<pre><code class="lang-bash">$ ssvmup build
</code></pre>
<p><a target="_blank" href="https://github.com/second-state/ssvm-tencent-starter/blob/master/README.md">Follow the instructions and screenshots</a> to deploy and test the <code>hello.zip</code> file from above. Now you have successfully deployed a WebAssembly serverless function!</p>
<p>Next, let's create a useful web service from a Rust function.</p>
<h2 id="heading-machine-learning-as-a-service">Machine Learning as a Service</h2>
<p>For this example, we chose a computationally intensive machine learning task to demonstrate the performance of a Rust WebAssembly function.</p>
<p>The serverless function takes an input string of comma delimited numbers that represent a set of points on a 2-D plane. The input data format is <code>x1,y1,x2,y2,...</code>.</p>
<p>The function analyzes the data and computes two Eigenvectors that indicate the directions of the most variance in the data.</p>
<p>The Eigenvectors give data scientists hints on the underlying factors that drives the variance in the data. This is called Principal Component Analysis (PCA).</p>
<p>Our function creates a SVG graph with the input data points as well as the Eigenvectors plotted on it. It outputs the SVG graph in XML text.</p>
<p>To get started with this example, you should <a target="_blank" href="https://github.com/second-state/wasm-learning">clone or fork this repository</a>. The project is in the <a target="_blank" href="https://github.com/second-state/wasm-learning/tree/master/tencentcloud/ssvm/pca">tencentcloud/ssvm/pca</a> folder. You can also copy the content of the <a target="_blank" href="https://github.com/second-state/wasm-learning/blob/master/tencentcloud/ssvm/pca/Cargo.toml">Cargo.toml</a> and <a target="_blank" href="https://github.com/second-state/wasm-learning/tree/master/tencentcloud/ssvm/pca/src">src/</a><a target="_blank" href="http://main.rs">*</a>to your hello world template.</p>
<p>If you do the latter, make sure that you modify the <a target="_blank" href="https://github.com/second-state/wasm-learning/blob/master/tencentcloud/ssvm/pca/Cargo.toml">Cargo.toml</a> to point to the correct source code folder for our Rust machine learning library.</p>
<p>I will not go into the details of the Rust source code for PCA or SVG generation in this tutorial as they involve a fair amount of computational code. If you are interested, you can check out more resources at the end of this article.</p>
<p>You can <a target="_blank" href="https://github.com/second-state/ssvm-tencent-starter/blob/master/README.md">follow the same process</a> as in the hello world example. Use the ssvmup to build a <code>pca.zip</code> package and deploy it on Tencent Cloud SCF Custom Runtime.</p>
<p>Next, we want to associate the deployed function with a web API Gateway so that it can be invoked from a web HTTP or HTTPS request. Do that from the Trigger Management tab in the web console for SCF. <a target="_blank" href="https://github.com/second-state/wasm-learning/tree/master/tencentcloud/ssvm/pca#create-a-web-service">See the instructions and screenshots here</a>.</p>
<p>The API console turns an HTTP request into a JSON input to the serverless function. For example, here is an HTTP POST request to the API gateway URL. We put the comma delimited data points from the <code>iris.csv</code> file in the POST body.</p>
<pre><code class="lang-bash">$ curl -d @iris.csv -X POST https://service-m9pxktbc-1302315972.hk.apigw.tencentcs.com/release/PCASVG
</code></pre>
<p>The API Gateway passes the following JSON to the Rust function’s STDIN. The POST body is now the body attribute in the JSON.</p>
<pre><code class="lang-json">{
  <span class="hljs-attr">"body"</span>: <span class="hljs-string">"3.5,0.2,3,0.2,..."</span>,
  <span class="hljs-attr">"headerParameters"</span>: {},
  <span class="hljs-attr">"headers"</span>: {
    <span class="hljs-attr">"accept"</span>: <span class="hljs-string">"/"</span>,
    <span class="hljs-attr">"content-length"</span>: <span class="hljs-string">"11"</span>,
    <span class="hljs-attr">"content-type"</span>: <span class="hljs-string">"application/x-www-form-urlencoded"</span>,
    <span class="hljs-attr">"host"</span>: <span class="hljs-string">"service-aj0plx8u-1302315972.hk.apigw.tencentcs.com"</span>,
    <span class="hljs-attr">"user-agent"</span>: <span class="hljs-string">"curl/7.54.0"</span>,
    <span class="hljs-attr">"x-anonymous-consumer"</span>: <span class="hljs-string">"true"</span>,
    <span class="hljs-attr">"x-api-requestid"</span>: <span class="hljs-string">"e3123014742e7dd79f0652968bf1f62e"</span>,
    <span class="hljs-attr">"x-b3-traceid"</span>: <span class="hljs-string">"e3123014742e7dd79f0652968bf1f62e"</span>,
    <span class="hljs-attr">"x-qualifier"</span>: <span class="hljs-string">"$DEFAULT"</span>
  },
  <span class="hljs-attr">"httpMethod"</span>: <span class="hljs-string">"POST"</span>,
  <span class="hljs-attr">"path"</span>: <span class="hljs-string">"/my_hk"</span>,
  <span class="hljs-attr">"pathParameters"</span>: {},
  <span class="hljs-attr">"queryString"</span>: {},
  <span class="hljs-attr">"queryStringParameters"</span>: {},
  <span class="hljs-attr">"requestContext"</span>: {
    <span class="hljs-attr">"httpMethod"</span>: <span class="hljs-string">"ANY"</span>,
    <span class="hljs-attr">"identity"</span>: {},
    <span class="hljs-attr">"path"</span>: <span class="hljs-string">"/my_hk"</span>,
    <span class="hljs-attr">"serviceId"</span>: <span class="hljs-string">"service-aj0plx8u"</span>,
    <span class="hljs-attr">"sourceIp"</span>: <span class="hljs-string">"136.49.211.114"</span>,
    <span class="hljs-attr">"stage"</span>: <span class="hljs-string">"release"</span>
  }
}
</code></pre>
<p>The Rust function parses the data in the body, performs PCA, and generates the SVG graph. It prints the SVG content to STDOUT, which is picked up by the API Gateway and sent back as the HTTP response.</p>
<blockquote>
<p>To use this API Gateway URL in AJAX requests, you must also configure the Tencent Cloud gateway to accept CORS web requests. <a target="_blank" href="https://www.secondstate.io/articles/tencentcloud-api-gateway-cors/">Check out this guide</a> on how to do it.</p>
</blockquote>
<p>The HTML JavaScript example below shows how to use this serverless function in a web page.</p>
<p>It takes the CSV data from the <code>textarea</code> field with ID <code>csv_data</code>, makes an AJAX HTTP POST request to the serverless function, and then puts the return value, which is a SVG graph, in an HTML element with ID <code>svg_img</code>. <a target="_blank" href="https://www.secondstate.io/demo/2020-tencentcloud.html">See the live demo here</a>.</p>
<pre><code class="lang-javascript">$.ajax({
  <span class="hljs-attr">method</span>: <span class="hljs-string">"POST"</span>,
  <span class="hljs-attr">url</span>: <span class="hljs-string">"https://service-m9pxktbc-1302315972.hk.apigw.tencentcs.com/release/PCASVG"</span>,
  <span class="hljs-attr">data</span>: $(<span class="hljs-string">'#csv_data'</span>).val(),
  <span class="hljs-attr">dataType</span>: <span class="hljs-string">"text"</span>
}).done(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">data</span>) </span>{
  $(<span class="hljs-string">'#svg_img'</span>).html(data);
})
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/tencentcloud_pca_webapp.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The serverless web application in action.</em></p>
<h2 id="heading-next-steps">Next steps</h2>
<p>The Tencent SCF Custom Runtime is a very powerful serverless environment. It provides a generic Linux environment for any application function you want to write, as well as standard web interfaces to interact with the function input and output. It is definitely worth trying out.</p>
<p>As discussed in the article, we believe that Rust and WebAssembly provides a <a target="_blank" href="https://www.secondstate.io/articles/why-webassembly-server/">high performance, safe, portable, and future-proof stack</a> for serverless functions. Rust and WebAssembly with SCF Custom Runtime is the future!</p>
<h2 id="heading-resources">Resources</h2>
<ul>
<li><p>Learn more about <a target="_blank" href="https://www.secondstate.io/articles/why-webassembly-server/">why use WebAssembly on the server side</a></p>
</li>
<li><p>Learn more about <a target="_blank" href="https://intl.cloud.tencent.com/document/product/583">Tencent Serverless Cloud Functions</a></p>
</li>
<li><p><a target="_blank" href="https://www.freecodecamp.org/news/a-no-code-intro-to-the-9-most-important-machine-learning-algorithms-today/">Learn more about machine learning algorithms</a></p>
</li>
<li><p><a target="_blank" href="https://www.rust-lang.org/learn/get-started">Getting started with Rust</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/second-state/wasm-learning/tree/master/nodejs/algos">Machine learning algorithms in Rust and WebAssembly</a></p>
</li>
<li><p><a target="_blank" href="https://www.secondstate.io/articles/getting-started-with-rust-function/">Getting started with Rust functions in Node.js</a></p>
</li>
<li><p>Learn more about the <a target="_blank" href="https://www.secondstate.io/ssvm/">Second State WebAssembly VM</a></p>
</li>
</ul>
<p><a target="_blank" href="https://webassemblytoday.substack.com/">Subscribe to our newsletter</a> and stay in touch. Happy coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ GitHub Codespaces – How to Code Right in Your Browser with Your Own Cloud Dev Environment ]]>
                </title>
                <description>
                    <![CDATA[ GitHub Codespaces enable you to experiment with complex software development stacks right from the web browser. No software to install or configure. No stress. No mess. A gif showing the setup process of a GitHub Codespace In the recent GitHub Satel... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-programming-in-your-browser-the-right-way/</link>
                <guid isPermaLink="false">66d4604a264384a65d5a95ac</guid>
                
                    <category>
                        <![CDATA[ codespaces ]]>
                    </category>
                
                    <category>
                        <![CDATA[ GitHub ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ node js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Rust ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Visual Studio Code ]]>
                    </category>
                
                    <category>
                        <![CDATA[ WebAssembly ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Michael Yuan ]]>
                </dc:creator>
                <pubDate>Tue, 09 Jun 2020 21:34:29 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9a61740569d1a4ca2547.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>GitHub Codespaces enable you to experiment with complex software development stacks right from the web browser. No software to install or configure. No stress. No mess.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/SSVM-edited-without-music-1-1.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>A gif showing the setup process of a GitHub Codespace</em></p>
<p>In the recent GitHub Satellite online conference, one of the most exciting product announcements was GitHub Codespaces. The idea is to have a code button on every repository.</p>
<p>When you click on it, it launches a fully featured VSCode IDE with all the necessarily software dependencies, including operating system level libraries, to build and run the project. This VSCode IDE runs entirely in your browser, and will not install any software or change any configuration to mess up your computer.</p>
<p>Sounds too good to be true? Well, watch the Github Satellite keynote segment about Codespaces yourself!</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/fQbH3meWNQ8" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p> </p>
<p>A key benefit of Github Codespaces is how quickly you can on-board new developers to a project. A new developer can get set up in minutes, instead of days, and immediately start contributing to the project. It is a great learning tool for new languages, frameworks, and software tools.</p>
<p>Under the hood, it starts a Docker container on a remote server, installs the entire software stack required by the project, and runs tasks like compiling and debugging in the remote Docker.</p>
<p>The web browser acts as a front end UI for the Docker instance. This approach requires no software install on the developer’s machine. But the trade-off is that all software installation from the operation system all the way to the final application happens on the server.</p>
<p>GitHub must start a fresh server for each Codespaces instance. That requires a lot of data center resources. In fact, the <a target="_blank" href="https://github.com/features/codespaces/">GitHub Codespaces web page</a> has a waiting list as of today (June 2020).</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/codespaces-beta.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Personally, I cannot wait for GitHub Codespaces to become available. But a time machine does exist. You can experience all the features in GitHub Codespaces today, for free.</p>
<h2 id="heading-vs-codespaces">VS Codespaces</h2>
<p>The software behind GitHub Codespaces is actually based on a Microsoft VSCode product called <a target="_blank" href="https://online.visualstudio.com/">VS Codespaces</a>. VS Codespaces is available today to all Microsoft Azure users. And yes, it allows you to open GitHub repositories in VSCode IDE directly from a browser window.</p>
<p>In this tutorial, I will show you how to use Codespaces in your own development work today.</p>
<p>To make Codespaces available in your GitHub repositories, you just need to add the following HTML button anywhere on your web pages.</p>
<p>When an Azure user clicks on the button, it asks the user to log into VS Codespaces and walks the user through opening the repository in the online IDE. You can see how it works in the examples in the next section.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://online.visualstudio.com/environments/new?name=My%20Project&amp;repo=username/reponame"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://img.shields.io/endpoint?style=social&amp;url=https%3A%2F%2Faka.ms%2Fvso-badge"</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<blockquote>
<p>VS Codespaces runs entirely in your browser and costs around $1 per work day. It is cheaper than a cup of coffee in the office.</p>
</blockquote>
<h2 id="heading-examples">Examples</h2>
<p>Now, let's look into several examples of how you might learn new programming skills using VS Codespaces.</p>
<p>Rust is one of the fastest growing programming languages today. It is voted as the most beloved programming language by Stackoverflow users four years in a row.</p>
<p>But to experiment with Rust requires a complex toolchain of compiler, linker, package manager, tool manager and so on.</p>
<p>VS Codespaces provides an easy way to <a target="_blank" href="https://www.secondstate.io/articles/how-to-learn-rust-without-installing-any-software/">learn Rust</a>. Just click on the VS Codespaces button in <a target="_blank" href="https://github.com/second-state/learn-rust-with-github-actions">this repository</a> and you now have a working Rust project to experiment with!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/learn-rust-20-seconds.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p><a target="_blank" href="https://github.com/second-state/learn-rust-with-github-actions"><em>https://github.com/second-state/learn-rust-with-github-actions</em></a></p>
<p>As a system language, Rust is well positioned to build high performance server side applications. The most promising stack is to compile and run Rust functions in a WebAssembly container, and then access those high performance functions from an existing web application framework, such as Node.js.</p>
<p>However, as you can already see, this “best practice” setup requires a complex stack of software.</p>
<p>Clicking on the VS Codespaces button in <a target="_blank" href="https://github.com/second-state/ssvm-nodejs-starter">this repository</a> gives you a fully functional Node.js project that uses <a target="_blank" href="https://www.secondstate.io/articles/getting-started-with-rust-function/">Rust functions in WebAssembly</a> as modules. You can immediately start to modify the Rust and JavaScript code and run the Node.js application from inside the web browser IDE.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/SSVM-edited-without-music.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p><a target="_blank" href="https://github.com/second-state/ssvm-nodejs-starter"><em>https://github.com/second-state/ssvm-nodejs-starter</em></a></p>
<p><a target="_blank" href="https://www.secondstate.io/articles/why-webassembly-server/">Server-side Rust and WebAssembly</a> sound cool. But do we actually have a more complete example that demonstrate the power and performance of Rust beyond a simple hello world?</p>
<p><a target="_blank" href="https://github.com/second-state/rust-wasm-ai-demo">This repository</a> is such an example. Open it in VS Codespaces and you will have a project for a <a target="_blank" href="https://www.secondstate.io/articles/artificial-intelligence/">Rust + JavaScript app that utilizes Tensorflow to perform image recognition</a>. Since the app runs inside Node.js, it provides a template for AI-as-a-Service web applications.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/68747470733a2f2f626c6f672e7365636f6e6473746174652e696f2f696d616765732f414961617325323033307365636f6e64732e676966.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p><a target="_blank" href="https://github.com/second-state/rust-wasm-ai-demo"><em>https://github.com/second-state/rust-wasm-ai-demo</em></a></p>
<p>What if you want to stay on the bleeding edge and use Rust-based web runtime Deno instead of the C-based Node.js? Well, there is a VS Codespaces <a target="_blank" href="https://github.com/anthonychu/azure-functions-deno-worker">template for running Deno as an Azure Function</a> too!</p>
<h2 id="heading-how-it-works">How it works</h2>
<p>If you look closely, each VS Codespaces-enabled repository has a <code>.devcontainer</code> folder. Inside that folder, the <code>Dockerfile</code> specifies how to build the Docker container for the development environment.</p>
<p>For example, the Node.js Docker container is based on Ubuntu Linux with Node.js and selected NPM packages pre-installed. <a target="_blank" href="https://github.com/second-state/ssvm-nodejs-starter/tree/master/.devcontainer">Check out an example here</a>.</p>
<p>The <code>devcontainer.json</code> file specifies the configuration for the VSCode IDE on the remote Docker. For example, it configures the VSCode extensions to install, the terminal and debugger commands to use, and the host ports to forward to for testing and debugging.</p>
<p>Microsoft provides <a target="_blank" href="https://github.com/microsoft/vscode-dev-containers">quite a few <code>.devcontainer</code> templates</a> for you to modify and use. They cover most of the common software development stacks today.</p>
<p>You could further customize the user’s VSCode experience by providing launch and tasks definitions in the <code>.vscode</code> folder. <a target="_blank" href="https://github.com/second-state/ssvm-nodejs-starter/tree/master/.vscode">Check them out</a>!</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>With VS Codespaces, and GitHub Codespaces when it launches, the barriers and friction for software development are further reduced. You can get started with complex software stacks without leaving your web browser. <a target="_blank" href="https://www.secondstate.io/articles/getting-started-rust-nodejs-vscode/">Try it today</a>!</p>
<p>Finally, watch the full length GitHub Satellite presentation on GitHub Codespaces.</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/dy2eYaNxaQc" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p> </p>
<p><a target="_blank" href="https://webassemblytoday.substack.com/">Subscribe to my newsletter</a> and stay in touch.</p>
<div class="embed-wrapper"><iframe src="https://webassemblytoday.substack.com/embed" width="480" height="320" style="border:1px solid #EEE;background:white" title="Embedded content" loading="lazy"></iframe></div> ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The Top 8 Things I Learned From 4000 Rust Developers ]]>
                </title>
                <description>
                    <![CDATA[ Do you know that most Rust programmers are working on web applications? ? Rust is challenging, but also rewarding and great fun! Learn Rust by example, or ?open this GitHub repo to get started in VSCode. Rust is one of the hottest ? programming langu... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/8-things-i-learned-from-4000-rust-developers/</link>
                <guid isPermaLink="false">66d460404bc8f441cb6df811</guid>
                
                    <category>
                        <![CDATA[ codespaces ]]>
                    </category>
                
                    <category>
                        <![CDATA[ programming languages ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Rust ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Visual Studio Code ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Applications ]]>
                    </category>
                
                    <category>
                        <![CDATA[ WebAssembly ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Michael Yuan ]]>
                </dc:creator>
                <pubDate>Sun, 24 May 2020 17:57:05 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/05/learn-rust-20-seconds-1.gif" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Do you know that most Rust programmers are working on web applications? ? Rust is challenging, but also rewarding and great fun! Learn <a target="_blank" href="https://rust-by-example-ext.com/">Rust by example</a>, or ?open <a target="_blank" href="https://github.com/second-state/learn-rust-with-github-actions">this GitHub repo</a> to get started in VSCode.</p>
<p>Rust is one of the hottest ? programming languages today. It is StackOverflow's <a target="_blank" href="https://stackoverflow.blog/2020/01/20/what-is-rust-and-why-is-it-so-popular/">most beloved programming language</a> for the past 4 years. Yet, it still has a reputation as the programming language for alpha geeks.</p>
<p>By <a target="_blank" href="https://s3-eu-west-1.amazonaws.com/vm-blog/uploads/2020/04/DE18-SoN-Digital-.pdf">some estimate</a>, there are 600,000 Rust developers world-wide, which is a significant number. But it's still dwarfed when compared with tens of millions of JavaScript, Java, and Python developers.</p>
<p>Who are those Rust developers? What are they using Rust for? Why do they love Rust so much? And most important, how do you join their ranks and see for yourself why Rust is so beloved? Don't get left behind.</p>
<p>In order to answer those questions, the Rust community has conducted annual developer surveys from rust-lang.org since 2016. The site recently released its <a target="_blank" href="https://blog.rust-lang.org/2020/04/17/Rust-survey-2019.html">2019 survey results</a> based on responses from nearly 4000 Rust developers. Here are the top 8 things I learned from the survey.</p>
<h2 id="heading-rust-is-for-professional-programmers">??‍? Rust is for professional programmers</h2>
<p>The Rust programming language is not designed to be “<a target="_blank" href="https://www.secondstate.io/articles/a-rusty-hello-world/">easy to get started</a>”. Rather, it is designed to be powerful and safe at the same time. It aims to be the developer productivity language for professional programmers. It is challenging, fun, and rewarding. That shows in the survey.</p>
<p>Very few respondents call themselves as Rust experts. Most people rate their Rust expertise as 7/10 or below, despite the fact that over 68% of them write Rust code on a weekly basis. It is clearly a language that takes time to master and excel.</p>
<blockquote>
<p>About 37% of Rust users felt productive in Rust in less than a month of use - this is not too different from the percentage last year (40%). Over 70% felt productive in their first year. Unfortunately, like last year, there is still a struggle among users - 21% indicated they did not yet feel productive.</p>
</blockquote>
<p>At the same time, when asked why not using Rust on some projects, the learning curve is cited as the #2 most common reason. The #1 reason, of course, is the company’s decision whether to use a particular programming language in a project.</p>
<h2 id="heading-documentation-is-critical-for-adoption">? Documentation is critical for adoption</h2>
<p>How do developers overcome Rust's learning curve and fall in love with it? Well, not unexpectedly, most developers cited “better documentation” as the driver for adoption.</p>
<p>But true to “professional programmers”, the most sought after Rust documentation is intermediate-level content that helps developers improve their Rust skills and productivity.</p>
<p>While the survey is biased toward developers who already knew the basics of Rust, it seems that there is a thirst for knowledge and self-improvement in this crowd.</p>
<h2 id="heading-developers-do-not-want-tomes-of-text">? Developers do not want tomes of text</h2>
<p>Traditional software documentation typically consists of entire books and websites. New generations of developers want more and better documentation. As a “new” language, Rust is already leading the innovation when it comes to programming language documentation.</p>
<p>For example, the Rust compiler is a self-documenting tool. One of the most unique and beloved features of Rust is its aggressive compiler that helps you ensure correctness and safety before the program even runs. As a result, Rust developers can write highly performant yet safe programs.</p>
<p>When you encounter a compiling error in Rust, the compiler gives you an immediate explanation of the error, and suggestions on how to fix the error based on the context of your program.</p>
<p><a target="_blank" href="https://github.com/second-state/learn-rust-with-github-actions">This starter project</a> in GitHub gets you started with the Rust compiler and the Cargo system without having to install any software toolchain. You can use the VSCode online IDE directly with this project.</p>
<p>Rust documentation web sites like <a target="_blank" href="http://docs.rs">docs.rs</a> and <a target="_blank" href="https://doc.rust-lang.org/rust-by-example/">Rust by Example</a> (and its <a target="_blank" href="https://rust-by-example-ext.com/">Extended Edition</a>) use the <a target="_blank" href="https://play.rust-lang.org/">Rust Playground</a> to run Rust example code directly from the browser. Those interactive books are much better than simple text.</p>
<p>However, as the survey finds out, developers want more. Developers are thirsty for more video content, for example. We can look forward to more coding videos and live broadcasts from the community soon.</p>
<h2 id="heading-most-people-use-rust-for-web-apps-srsly">?️ Most people use Rust for web apps, srsly!</h2>
<p>As a system-level language intended to replace C and C++, most people assume that Rust would be used in infrastructure programming, such as operating systems, native libraries, and runtime platforms.</p>
<p>Yet, the survey clearly shows that by a large margin, most Rust developers today are working on web app backends. No wonder crates like <a target="_blank" href="https://docs.rs/hyper/0.13.5/hyper/">hyper</a>, <a target="_blank" href="https://github.com/actix/actix-web">actix-web</a>, and <a target="_blank" href="https://rocket.rs/">Rocket</a> are among the most popular with Rust developers.</p>
<p>To be sure, most software developers are working on web applications. It is not surprising that, as Rust gains mainstream adoption, Rust projects will mirror the bigger software industry.</p>
<p>However, that does present opportunities for projects and tools that integrates Rust into popular web application runtimes. For example, the <a target="_blank" href="https://www.secondstate.io/articles/getting-started-with-rust-function/">Rust + JavaScript hybrid application</a> approach is gaining momentum.</p>
<h2 id="heading-blockchain-is-a-rusty-hotbed">? Blockchain is a Rusty hotbed</h2>
<p>When it comes to infrastructure software, Rust really shines as a programming language for blockchain systems.</p>
<p>For all software related industry sectors, the survey shows that blockchain only ranks the 35th for all software developers, but 11th for Rust developers. That is in no small part due to aggressive Rust adoption by large blockchain projects such as <a target="_blank" href="https://www.parity.io/">Polkadot / Substrate</a>, <a target="_blank" href="https://www.oasislabs.com/">Oasis</a>, <a target="_blank" href="https://solana.com/">Solana</a>, and <a target="_blank" href="https://www.secondstate.io/">Second State</a> etc.</p>
<p>In many ways, blockchains are perfect fit for Rust. Blockchains represent the community effort to re-build the internet infrastructure in a decentralized manner. They require high performance software that is also very safe. If you are interested in a career as a blockchain engineer, Rust is a must-have skill today.</p>
<h2 id="heading-rust-webassembly">Rust ❤️ WebAssembly</h2>
<p>The survey reveals that WebAssembly is a popular runtime environment for Rust programs. Rust and WebAssembly were both invented at Mozilla.</p>
<p>Rust is focused on performance and memory safety, while WebAssembly is focused on performance and runtime safety. As a runtime container, WebAssembly also makes Rust programs cross-platform and more manageable. There are indeed a lot of synergy between the two technologies.</p>
<p>WebAssembly was originally invented as a client side virtual machine to run in-browser applications. But as Java and JavaScript before it, WebAssembly is now making the migration from the client side <a target="_blank" href="https://www.secondstate.io/articles/why-webassembly-server/">to the server side</a>.</p>
<p>Rust-in-WebAssembly bodes well with the trend of accelerating Rust adoption on backend web applications. You can get started with Rust and WebAssembly application development from a starter project in <a target="_blank" href="https://github.com/second-state/ssvm-nodejs-starter">this GitHub repository</a>.</p>
<h2 id="heading-asynchronous-programming-is-taking-off">? Asynchronous programming is taking off</h2>
<p>In recent years, two new programming languages have gained significant traction among developers. One is Rust, and the other is Go. A big part of their success is their superior support for concurrency programming models.</p>
<p>In fact, an early tagline of Rust is "fearless concurrency". It promises developer productivity in writing asynchronous multi-threaded programs optimized for today’s multi-core CPU architectures. As Node.js demonstrated, easy asynchronous programming is crucial for a language or framework’s success on the server side.</p>
<p>The survey shows that 4 of the 10 most important Rust crates (ie third party libraries), <a target="_blank" href="https://tokio.rs/">tokio</a>, <a target="_blank" href="https://docs.rs/crate/async-std/1.4.0">async</a>, <a target="_blank" href="https://docs.rs/futures/0.3.4/futures/">futures</a>, and <a target="_blank" href="https://hyper.rs/">hyper</a>, are frameworks for asynchronous multi-thread applications.</p>
<h2 id="heading-r-python-and-javascript">? R, Python, and JavaScript</h2>
<p>As the adoption of Rust grows, developers increasingly need to integrate Rust programs with programs written in other languages. In the past, C and C++ were the most common languages to “talk” to Rust as they are all used in infrastructure software projects.</p>
<p>As Rust grows into application software projects, more language level interfaces and bridges are needed now. A good example is the <a target="_blank" href="https://www.secondstate.io/articles/rust-functions-in-nodejs/">Rust JavaScript bridge</a> that supports <a target="_blank" href="https://www.secondstate.io/articles/getting-started-with-rust-function/">Rust functions in Node.js</a> applications.</p>
<p>The survey found that, besides C/C++ and JavaScript, Rust developers are interested in integrating with R and Python. That indicates developer interests in machine learning, big data, and artificial intelligence (AI) applications. In fact, many Python and R machine learning and statistical packages are implemented in native binary modules.</p>
<p>Rust is one of the best programming languages to write native modules. <a target="_blank" href="https://github.com/second-state/rust-wasm-ai-demo">This example</a> shows how to use <a target="_blank" href="https://www.secondstate.io/articles/artificial-intelligence/">Rust to execute Tensorflow models in a Node.js</a> application. In the future, we envision such Rust modules to run in high performance managed containers such as WebAssembly.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>2019 was a year of growth and incremental improvements for Rust. As Rust becomes a mainstream programming language, we look forward to more documentation, more tools, more ecosystem support, more interoperability with other languages, and a gentler learning curve.</p>
<p>And most important of all, we are eager to make more friends and have fun with the most beloved programming language in the world!</p>
<h2 id="heading-about-the-author">About the author</h2>
<p>Dr. Michael Yuan is the <a target="_blank" href="http://www.michaelyuan.com/">author of 5 books</a> on software engineering. His latest book <a target="_blank" href="https://www.buildingblockchainapps.com/">Building Blockchain Apps</a> was published by Addison-Wesley in Dec 2019. Dr. Yuan is the co-founder of <a target="_blank" href="https://www.secondstate.io/">Second State</a>, a VC-funded startup that brings WebAssembly and Rust technologies to <a target="_blank" href="https://www.secondstate.io/articles/why-webassembly-server/">cloud</a>, <a target="_blank" href="https://docs.secondstate.io/">blockchain</a>, and <a target="_blank" href="https://github.com/second-state/rust-wasm-ai-demo/blob/master/README.md">AI</a> applications. It enables developers to deploy fast, safe, portable, and serverless <a target="_blank" href="https://www.secondstate.io/articles/getting-started-with-rust-function/">Rust functions on Node.js</a>.</p>
<div class="embed-wrapper"><iframe src="https://webassemblytoday.substack.com/embed" width="480" height="320" style="border:1px solid #EEE;background:white" title="Embedded content" loading="lazy"></iframe></div>

<p>Prior to Second State, Dr. Yuan was a long time open source contributor at Red Hat, JBoss, and Mozilla. Outside of software, Dr. Yuan is a Principal Investigator at the National Institutes of Health, with multiple research awards on cancer and public health research. He holds a PhD in astrophysics from the University of Texas at Austin.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The Design of WebAssembly ]]>
                </title>
                <description>
                    <![CDATA[ By Patrick Ferris I love the web. It is a modern-day superpower for the dissemination of information and empowerment of the individual. Of course, it has its downsides like trolling (largely possible through anonymity) and privacy issues, not to ment... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/the-design-of-webassembly-81f1dcabaddd/</link>
                <guid isPermaLink="false">66c3612ba33cff0dc251d5ef</guid>
                
                    <category>
                        <![CDATA[ internet ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ WebAssembly ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 28 Jan 2019 18:14:11 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*xAFAiAxqZVrOVLBTo9tf6w.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Patrick Ferris</p>
<p>I love the web. It is a modern-day superpower for the dissemination of information and empowerment of the individual. Of course, it has its downsides like trolling (largely possible through anonymity) and privacy issues, not to mention the problems of ownership and copyright infringement about to come into effect with the highly divisive <a target="_blank" href="https://www.wired.co.uk/article/what-is-article-13-article-11-european-directive-on-copyright-explained-meme-ban">article 13</a>. But, let’s forget about that for just a moment and marvel at the technological innovation of the internet and the browsers which support it.</p>
<p>I first learnt to code in Javascript and have since been ridiculed by many for liking it. Yes, I know there are <a target="_blank" href="https://github.com/denysdovhan/wtfjs">weird</a> bits like this gem: <code>[] == ![] // true</code> but it has become one of the most ubiquitous languages on the planet thanks to the internet, browsers and the interpreters that run the code (<a target="_blank" href="https://v8.dev/">Google’s V8</a> and <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey">Firefox’s SpiderMonkey</a> to name a few).</p>
<p>As I got more into web development, I noticed a new name on the block: WebAssembly. As a computer science student and a developer, I believe one of the best ways to learn something is to try and understand why the engineers who built it made those design choices. So here is a brief look at some of the interesting design principles in WebAssembly and also why I think everyone should be excited.</p>
<h4 id="heading-why-do-we-need-webassembly">Why do we need WebAssembly?</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*lNZl5UEb8T84byWotDdV3w.jpeg" alt="Image" width="800" height="701" loading="lazy"></p>
<p>Okay, so first of all, to all my Javascript fans out there — no you shouldn’t be worried. When Javascript first came about, it was designed to be used in a lightweight way but has since gone on to do a lot of heavy lifting. Maybe it was used for manipulating some DOM elements, some client-side verification in forms but not everything that is trying to be done on the web now. Certainly not running fully-fledged games.</p>
<p>Why is Javascript not so fast or great? One of the main reasons is because it is an interpreted language. Scanning the code line by line and executing, luckily with Just-in-Time compilers, the efficiency improved massively but still there is only so much room to improve. But even then there’s the issue of Javascript’s dynamic typing causing another ceiling on performance</p>
<p>Alex Danilo discussed the improvements WebAssembly could make in his <a target="_blank" href="https://www.youtube.com/watch?v=6v4E6oksar0">Google I/O talk</a> in 2017. What really brought home the inefficiencies was his example <code>add(a, b)</code> function and the complexity that the Javascript interpreters have to go through in order to make sense of it.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*oaXj5mrSX8ho6XCnWx8dig.jpeg" alt="Image" width="800" height="258" loading="lazy">
_A simple Javascript function — [ECMAScript Rabbit Hole p.263](https://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf" rel="noopener" target="<em>blank" title=") (be sure to follow the links of the other function calls)</em></p>
<p>WebAssembly opens the door to compilation, which opens another door to optimisation. It’s ability to take C/C++ source language allows it to do some static type checking which helps improve speed. This is what the developers of the <a target="_blank" href="https://medium.com/mozilla-tech/why-webassembly-is-a-game-changer-for-the-web-and-a-source-of-pride-for-mozilla-and-firefox-dda80e4c43cb">Mozilla Foundation</a> realised and wanted to fix. To summarise this <a target="_blank" href="https://www.youtube.com/watch?time_continue=3&amp;v=o52_5qAJhNg">great video</a>, Javascript was designed for humans and browsers were left to try and make it fast; WebAssembly was designed as a target language for compilers that browsers could already run quickly.</p>
<p>The realisation that we could have two choices of code run in the engines was an exciting prospect — and the four major browsers (Chrome, Safari, Firefox and IE) all began plans to let their engines run Javascript and WebAssembly. Again, let me reiterate… WebAssembly is <strong>not</strong> replacing Javascript.</p>
<h4 id="heading-why-compile-code">Why compile code?</h4>
<p>Compiling code really means taking it from one (source) language and translating it into another (target) language. This is an incredibly simplified understanding of compilation. Most modern day compilation pipelines involve many more stages that allow us to really fine-tune and optimise our code making it faster and more energy-efficient.</p>
<p>The first steps usually include lexical, syntactic and semantic analysers to get the code into some kind of intermediate language that is perfect for optimisation. Then we optimise independently, generate the target code and then maybe optimise dependently on the hardware or environment.</p>
<p>All projects need to start small first, and the engineers at Mozilla decided to begin with their source language being C/C++ and using an existing toolchain called <a target="_blank" href="https://llvm.org/">LLVM</a> (not an acronym) they would compile using that.</p>
<p>Initially, the search for a better performing web started with <code>[asm.js](http://asmjs.org/spec/latest/)</code> (at least in WebAssembly narrative. See <a target="_blank" href="https://developer.chrome.com/native-client">PNaCL</a> — Google’s earlier attempts) a small subset of Javascript that could be the compile target for C/C++ programs that used annotations and other clever tricks to improve the Javascript performance.</p>
<p>Unfortunately, it lacked one crucial design principle underlying what was wanted: Portability. Different Javascript engines gave different performance reviews, but it was a clear indication that this may be a good approach.</p>
<p>The developers of WebAssembly decided their target representation would be a binary format that provided a “<a target="_blank" href="https://webassembly.github.io/spec/core/binary/conventions.html">dense, linear encoding of the abstract syntax</a>”… Which is a lot of words, so let’s unpack that.</p>
<p>The “dense” part refers to the <a target="_blank" href="https://webassembly.org/docs/high-level-goals/">high-level goal</a> of achieving a size and load time efficient format. The internet is all about sending data along wires, and whilst there are lots of projects to improve the latency of this, one foolproof way of achieving this is to send less data. Another important aspect is the increased decoding speed thanks to array indexing over dictionary lookup (if they used compressed text format). Read more about this design choice <a target="_blank" href="https://webassembly.org/docs/rationale/#why-a-binary-encoding">here</a>.</p>
<h4 id="heading-what-is-wat">What is wat?</h4>
<p>The binary format that the C and C++ programs compile to are <code>.wasm</code> files, these have a 1:1 mapping straight to a (somewhat) human readable text format. These files are labelled <code>.wat</code> , this <a target="_blank" href="https://mbebenita.github.io/WasmExplorer/">WasmExplorer</a> is great for getting your head around text representation and how it relates to the original code. Let’s take a simple example.</p>
<p>There’s a lot going on here so let’s take it slowly and explain the concepts as they come.</p>
<p>First, there is this weird <code>module</code> word, where did that come from? <a target="_blank" href="https://www.youtube.com/watch?v=Th-Z6le3bHA">Mejin Leechor</a> gave a great talk on modules in Javascript and describes them as giving code “structure and boundaries”. This is very similar to the idea of WebAssembly modules (and there are plans in the future to try and integrate with es6 modules).</p>
<p>Straight from the docs, we have that the module is the “<a target="_blank" href="https://webassembly.org/docs/modules/">distributable, loadable, and executable unit of code in WebAssembly</a>”. Modules can have the following sections each with their own unique responsibility: import, export, start, global, memory, data, table, elements, function and code. For now, let’s just look at what we have in our module.</p>
<p>The first declaration is <code>(type $type0 (func (param i32) (result i32)))</code> . This is intimately linked to the table call on the next line. We are declaring a new type with the <code>func</code> signature that takes a 32 bit integer parameter and returns a 32 bit integer. If we were to make use of the function we wrote again, we would have to make a <code>call_indirect</code> into our <code>table</code> and then we could do some type-checking to make sure everything was correct. As part of the minimal viable product only one table is allowed, but there are future plans to allow multiple tables and for these to be indexed.</p>
<p>The next declaration is <code>(table 0 anyfunc)</code> . The table section is reserved for defining zero or more tables. A table is similar to a linear memory in the sense that they are resizable arrays which contain references. The <code>0</code> makes reference to the fact that we have nothing in our table, but we still need to provide the MVP’s only possible value of <code>anyfunc</code> (a function).</p>
<p>The problem that the developers had was linked to security. If a function wanted to call another function, giving it direct access to a function stored in linear memory was unsafe. Instead functions are stored in the table ready to be indexed if needed. <a target="_blank" href="https://twitter.com/linclark">Lin Clark</a> wrote a great <a target="_blank" href="https://hacks.mozilla.org/2017/07/webassembly-table-imports-what-are-they/">article</a> describing tables (as used in imports) in more detail and how they provide better security.</p>
<p>We then have a declaration of <code>(memory 1)</code> , this is the linear memory used by the module and we declare that we need <code>1</code> page of <a target="_blank" href="https://webassembly.org/docs/semantics/#linear-memory">memory (64KiB)</a>.</p>
<p>The next declaration is <code>(export "memory" memory)</code> . An export is something that is returned to the host at instantiation time. Basically, the cool bits we want from the WebAssembly code.</p>
<p>The structure is quite simple <code>(export &lt;name-of-export&gt; (&lt;type&gt; &amp;l</code>t;name/index&gt;)) so here we are just exporting the memory we declared in the previous line. This allows for direct memory access within our Javas<code>cript code,</code> as an ArrayBuffer which drastically improves the efficiency as there are no backwards and forwards calls across the WASM/JS border. Similarly we then export <code>our function with (exp</code>ort "main" $func0) .</p>
<p>Now to the slightly more interesting bit, our code and its representation.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*ywt3H0EvyqqZwTC_SkvyqQ.jpeg" alt="Image" width="800" height="197" loading="lazy">
<em>The different parts of the function declaration in WebAssembly Text Format</em></p>
<p>Before moving on, this is the perfect opportunity to introduce yet another design component: the stack machine.</p>
<h4 id="heading-register-versus-stack-machines">Register versus Stack Machines</h4>
<p>Computers, at their simplest, consume inputs and produce outputs. As a ‘machine’ executes a program it can do so in multiple different ways. Two of the main approaches are register and stack machines. In a register machine, parameters to functions are kept in memory locations and are then manipulated depending on the program in execution.</p>
<p>A simple, but somewhat flawed, analogy could be a kitchen and making a recipe. The ingredients are stored in different locations, you get them and make something which you might put somewhere for another day or immediately consume (yum). It’s far from perfect but hopefully you get the idea.</p>
<p>Stack machines, on the other hand, employ a different model. Imagine you are a journalist or secretary, your job is to read and respond to letters. You ‘pop’ the top letter from your pile and begin writing a response whilst someone else comes along with more work and ‘pushes’ to the top of the pile. These are the ones you are going to have to do next. Again, grossly oversimplified but it should help visualise the mechanics.</p>
<p>WebAssembly uses a stack machine model for code execution. If you’re short of some great reading, and are into programming semantics, the paper “<a target="_blank" href="https://people.mpi-sws.org/~rossberg/papers/Haas,%20Rossberg,%20Schuff,%20Titzer,%20Gohman,%20Wagner,%20Zakai,%20Bastien,%20Holman%20-%20Bringing%20the%20Web%20up%20to%20Speed%20with%20WebAssembly.pdf">Bringing the Web up to Speed with WebAssembly</a>” is really good. It also indicates why they choose the stack machine representation: “The stack organization is merely a way to achieve a compact program representation, as it has been shown to be smaller than a register machine” with reference to <a target="_blank" href="http://delivery.acm.org/10.1145/1330000/1328197/a21-shi.pdf?ip=131.111.184.4&amp;id=1328197&amp;acc=OPEN&amp;key=BF07A2EE685417C5%2E6CDC43D2A5950A53%2E4D4702B0C3E38B35%2E6D218144511F3437&amp;__acm__=1547647308_6631c4fb74b2b8d18427168494ccc927">this paper</a> which found “… the bytecode size of the register machine being only 26% larger than that of the corresponding stack one”.</p>
<p>Even though the stack machine approach isn’t necessarily faster, it offered smaller bytecode; an incredibly important design goal for internet-based transactions.</p>
<p>So how can we understand the text-format as a stack machine. As we read the code line by line we end up pushing arguments to the stack, then popping them off, doing some computation and pushing the result back. And repeat.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*01B21CM64DHEkL6nzv7WPw.jpeg" alt="Image" width="800" height="165" loading="lazy">
<em>A small example of WebAssembly and the implicit stack machine approach</em></p>
<p>At first it might seem a little odd to have a text format, if in the end it will be compiled to the binary format for compression. But, the internet has always had the policy of viewing the source and that’s why the developers behind WebAssembly produced the text format. To go one step further and avoid conflicts of syntax they used the Lisp-like <a target="_blank" href="https://en.wikipedia.org/wiki/S-expression">s-expression style</a>.</p>
<h4 id="heading-safety-and-sandboxing">Safety and Sandboxing</h4>
<p>One of the greatest sources of bugs (and exploits) in unsafe languages is buffer overflows. C and C++ are almost interchangeable with this idea and it is one of the first aspects you are taught when learning these languages. In exchange for a little overhead costs, WebAssembly adds this safety net by enforcing fixed-sized, indexed memory (although certain memory can be grown).</p>
<p>The local variables to our function, for example<code>$var0</code> , are not referenced by address but instead are indexed providing a layer of security. Access is granted via the <code>get_local</code> and <code>set_local</code> commands which all happens within the index space of the local variables.</p>
<p>Memory security was a top priority when designing WebAssembly. Straight from the documentation: “<a target="_blank" href="https://github.com/WebAssembly/design/blob/master/Semantics.md#linear-memory">Linear memory is sandboxed</a>; it does not alias other linear memories, the execution engine’s internal data structures, the execution stack, local variables, or other process memory.” Lin Clark, again, wrote a great article <a target="_blank" href="https://hacks.mozilla.org/2017/07/memory-in-webassembly-and-why-its-safer-than-you-think/">describing this</a>.</p>
<p>The basic idea is comparable to the Javascript ArrayBuffer object — resizable and bound-checked. What we’re trying to achieve is program isolation to prevent errors and malicious code from spreading and corrupting data it shouldn’t even have access to.</p>
<h4 id="heading-what-can-webassembly-do">What can WebAssembly do?</h4>
<p>One of the major end-goals for WebAssembly was revolutionising what was possible in terms of graphics on the web. The classic examples are <a target="_blank" href="https://s3.amazonaws.com/mozilla-games/ZenGarden/EpicZenGarden.html">ZenGarden</a> by EpicGames and <a target="_blank" href="https://webassembly.org/demo/Tanks/">Tanks!</a>.</p>
<p>Thanks to its design, WebAssembly marks a pivotal moment in web development. The internet has a new tool in its arsenal to create amazing experiences and share information. WebAssembly provides smaller code-sizes, faster execution, greater security and a lot of room for extensibility. With ideas like <a target="_blank" href="https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md">threads</a>, single-instruction multiple-data (<a target="_blank" href="https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md">SIMD</a>) primitives and zero-cost execution on the horizon, WebAssembly’s abilities look only set to expand.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ All you need to know about Go version 1.11 ]]>
                </title>
                <description>
                    <![CDATA[ By Ridham Tarpara Go 1.11 hit the ground on 24 August 2018. It introduces a few really needed tools and components such as versioned modules, WebAssembly support, and debugging improvements. It also brings some changes to core packages and performanc... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/all-you-need-to-know-about-go-1-11-webassembly-modules-and-major-changes-df6a02108373/</link>
                <guid isPermaLink="false">66c343ba52e2abc555bfcbf9</guid>
                
                    <category>
                        <![CDATA[ Go Language ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ WebAssembly ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 27 Aug 2018 09:48:15 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*ZhP-Sh-b9W-Y4IeI84prkw.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Ridham Tarpara</p>
<p>Go 1.11 hit the ground on 24 August 2018. It introduces a few really needed tools and components such as versioned modules, WebAssembly support, and debugging improvements. It also brings some changes to core packages and performance/run-time.</p>
<p>As always, the release maintains the Go 1 <a target="_blank" href="https://golang.org/doc/go1compat.html">promise of compatibility</a>. So almost all Go programs continue to compile and run as before with this update. There are no changes to the language specification.</p>
<p>Let’s take a look at what’s new.</p>
<h3 id="heading-modules"><strong>Modules</strong></h3>
<p>Go 1.11 includes experimental support for Go modules, including a new module-aware <code>go get</code> command.</p>
<p>The quickest way to take advantage of the new module support is to check out your repository into a directory <strong>outside,</strong> create a go.mod file and run Go commands from within that file tree.</p>
<p>Let’s demo this. I am using the <a target="_blank" href="https://github.com/stretchr/testify">testify-powerful and standard Go testing libraries</a>.</p>
<p>Let’s clone the testify repo in my favorite folder <code>~/proj/github</code> .</p>
<pre><code>$ git clone https:<span class="hljs-comment">//github.com/stretchr/testify ~/proj/github/testify$ cd ~/proj/github/testify</span>
</code></pre><p>Now, to use Go commands from here, you need to initialize this repo as a module with the following command:</p>
<pre><code>go mod init github.com/stretchr/testify
</code></pre><p>Where <code>github.com/stretchr/testify</code> is the location you would generally put this repo, under the Go src folder.</p>
<p>This command will create a go.mod file in the root of the folder. In a project already using an existing dependency management tool like godep, glide, or dep, <code>go mod init</code> will also add require statements matching the existing configuration.</p>
<p>Now if you open the <code>go.mod</code> file, you can see the list of dependencies with the module name.</p>
<pre><code>$ vi go.mod
</code></pre><pre><code><span class="hljs-built_in">module</span> github.com/stretchr/testify
</code></pre><pre><code><span class="hljs-built_in">require</span> (    github.com/davecgh/go-spew v1<span class="hljs-number">.1</span><span class="hljs-number">.0</span>    github.com/pmezard/go-difflib v1<span class="hljs-number">.0</span><span class="hljs-number">.0</span>    github.com/stretchr/objx v0<span class="hljs-number">.1</span><span class="hljs-number">.0</span>)
</code></pre><p>As you’ll notice, these three are the dependencies of the testify. This is testify’s <code>Gopkg.toml</code> file:</p>
<pre><code>[prune] unused-packages = <span class="hljs-literal">true</span> non-go = <span class="hljs-literal">true</span> go-tests = <span class="hljs-literal">true</span>
</code></pre><pre><code>[[constraint]] name = “github.com/davecgh/go-spew” version = “~<span class="hljs-number">1.1</span><span class="hljs-number">.0</span>”
</code></pre><pre><code>[[constraint]] name = “github.com/pmezard/go-difflib” version = “~<span class="hljs-number">1.0</span><span class="hljs-number">.0</span>”
</code></pre><pre><code>[[constraint]] name = “github.com/stretchr/objx” version = “~<span class="hljs-number">0.1</span><span class="hljs-number">.0</span>”
</code></pre><p>Now that the module has been initialized, you can use any Go command from this folder.</p>
<pre><code>╭─ ~<span class="hljs-regexp">/proj/gi</span>thub/testify  ‹master*› ╰─$ go build                               go: finding github.com/davecgh/go-spew v1<span class="hljs-number">.1</span><span class="hljs-number">.0</span>go: finding github.com/pmezard/go-difflib v1<span class="hljs-number">.0</span><span class="hljs-number">.0</span>go: finding github.com/stretchr/objx v0<span class="hljs-number">.1</span><span class="hljs-number">.0</span>go: downloading github.com/davecgh/go-spew v1<span class="hljs-number">.1</span><span class="hljs-number">.0</span>go: downloading github.com/pmezard/go-difflib v1<span class="hljs-number">.0</span><span class="hljs-number">.0</span>go: downloading github.com/stretchr/objx v0<span class="hljs-number">.1</span><span class="hljs-number">.0</span>
</code></pre><pre><code>╭─ ~<span class="hljs-regexp">/proj/gi</span>thub/testify  ‹master*› ╰─$ go test PASSok   github.com/stretchr/testify <span class="hljs-number">0.001</span>s
</code></pre><p>So with Go 1.11 and modules, you can write your Go modules <em>anywhere you like and you don’t need to maintain a copy</em> in a specific sub directory of your <code>$GOPATH</code>.</p>
<h3 id="heading-webassembly">WebAssembly</h3>
<p>Go 1.11 adds an experimental port to WebAssembly.</p>
<blockquote>
<p>WebAssembly (abbreviated <em>Wasm</em>) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable target for compilation of high-level languages like C/C++/Rust, enabling deployment on the web for client and server applications.</p>
</blockquote>
<p>Now we can run Go in the browser, and vice versa — we can run JavaScript in Go easily. Although this feature is in the experimental state, it’s still pretty useful.</p>
<p>This small example calls Go from the Web:</p>
<p><strong>wasm-exec.html</strong></p>
<pre><code>&lt;!doctype html&gt;&lt;!--Copyright <span class="hljs-number">2018</span> The Go Authors. All rights reserved.Use <span class="hljs-keyword">of</span> <span class="hljs-built_in">this</span> source code is governed by a BSD-stylelicense that can be found <span class="hljs-keyword">in</span> the LICENSE file.--&gt;<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span></span>
</code></pre><pre><code>&lt;head&gt;    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"utf-8"</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Go wasm<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span></span>
</code></pre><pre><code>&lt;body&gt;    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"wasm_exec.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">        <span class="hljs-keyword">if</span> (!WebAssembly.instantiateStreaming) { <span class="hljs-comment">// polyfill            WebAssembly.instantiateStreaming = async (resp, importObject) =&gt; {                const source = await (await resp).arrayBuffer();                return await WebAssembly.instantiate(source, importObject);            };        }        const go = new Go();        let mod, inst;        WebAssembly.instantiateStreaming(fetch("test.wasm"), go.importObject).then((result) =&gt; {            mod = result.module;            inst = result.instance;            document.getElementById("runButton").disabled = false;        });        let printMessage // Our reference to the Go callback        let printMessageReceived // Our promise        let resolvePrintMessageReceived // Our promise resolver        function setPrintMessage(callback) {          printMessage = callback          resolvePrintMessageReceived()        }        async function run() {          console.clear()          // Create the Promise and store its resolve function          printMessageReceived = new Promise(resolve =&gt; {            resolvePrintMessageReceived = resolve          })          const run = go.run(inst) // Start the wasm binary          await printMessageReceived // Wait for the callback reception          printMessage('Hello Wasm!') // Invoke the callback          await run // Wait for the binary to terminate          inst = await WebAssembly.instantiate(mod, go.importObject) // reset instance        }    </span></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>
</code></pre><pre><code>&lt;button onClick=<span class="hljs-string">"run();"</span> id=<span class="hljs-string">"runButton"</span> disabled&gt;Run&lt;<span class="hljs-regexp">/button&gt;&lt;/</span>body&gt;
</code></pre><pre><code>&lt;/html&gt;
</code></pre><p><strong>go-call.go</strong></p>
<pre><code>package main
</code></pre><pre><code><span class="hljs-keyword">import</span> (  <span class="hljs-string">"fmt"</span>  <span class="hljs-string">"syscall/js"</span>)
</code></pre><pre><code><span class="hljs-keyword">var</span> done = make(chan struct{})
</code></pre><pre><code>func main() {  <span class="hljs-attr">callback</span> := js.NewCallback(printMessage)  defer callback.Release() <span class="hljs-comment">// To defer the callback releasing is a good practice  setPrintMessage := js.Global().Get("setPrintMessage")  setPrintMessage.Invoke(callback)  &lt;-done}</span>
</code></pre><pre><code>func printMessage(args []js.Value) {  <span class="hljs-attr">message</span> := args[<span class="hljs-number">0</span>].String()  fmt.Println(message)  done &lt;- struct{}{} <span class="hljs-comment">// Notify printMessage has been called}</span>
</code></pre><p>You can find more examples <a target="_blank" href="https://github.com/nlepage/golang-wasm/blob/master/examples">here</a>. And here is a video on <a target="_blank" href="https://www.youtube.com/watch?v=4kBvvk2Bzis&amp;feature=youtu.be">building a calculator with WebAssembly</a>.</p>
<h3 id="heading-other-changes-to-consider"><strong>Other changes to consider</strong></h3>
<ul>
<li>Because Go module support assigns special meaning to the <code>@</code> symbol in command line operations, the <code>go</code>command now disallows the use of import paths containing <code>@</code> symbols.</li>
<li>With the new <code>runtime/trace</code> package's <a target="_blank" href="https://golang.org/pkg/runtime/trace/#hdr-User_annotation">user annotation API</a>, users can record application-level information in execution traces and create groups of related goroutines. The <code>go</code> <code>tool</code> <code>trace</code> command visualizes this information in the trace view and the new user task/region analysis page.</li>
<li>The runtime now uses a sparse heap layout so there is no longer a limit to the size of the Go heap (previously, the limit was 512GiB). This also fixes rare “address space conflict” failures in mixed Go/C binaries or binaries compiled with <code>-race</code>.</li>
<li><a target="_blank" href="https://golang.org/pkg/time/">time</a>: Parsing of timezones denoted by sign and offset is now supported. In previous versions, numeric timezone names (such as <code>+03</code>) were not considered valid, and only three-letter abbreviations (such as <code>MST</code>) were accepted when expecting a timezone name.</li>
<li><a target="_blank" href="https://golang.org/pkg/text/scanner/">text/scanner</a>: The <code>[Scanner.Scan](https://golang.org/pkg/text/scanner/#Scanner.Scan)</code> method now returns the <code>[RawString](https://golang.org/pkg/text/scanner/#RawString)</code> token instead of <code>[String](https://golang.org/pkg/text/scanner/#String)</code> for raw string literals.</li>
<li>There are changes in <a target="_blank" href="https://golang.org/pkg/crypto/">crypto</a>, <a target="_blank" href="https://golang.org/pkg/encoding/">encoding</a>, <a target="_blank" href="https://golang.org/pkg/net/http/">net/http</a>, <a target="_blank" href="https://golang.org/pkg/os/">os</a>, <a target="_blank" href="https://golang.org/pkg/runtime/">runtime</a>, <a target="_blank" href="https://golang.org/pkg/sync/">sync</a>, <a target="_blank" href="https://golang.org/pkg/mime/">mime</a> and few others which you can read about <a target="_blank" href="https://golang.org/doc/go1.11#library">here</a>.</li>
</ul>
<p>If you enjoyed this article, spare me some claps — it means the world to the writer. Follow me if you want to read more articles about Go, JavaScript, Technology, and Startups.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to use WebGL shaders in WebAssembly ]]>
                </title>
                <description>
                    <![CDATA[ By Dan Ruta WebAssembly is blazing fast for number crunching, game engines, and many other things, but nothing can quite compare to the extreme parallelization of shaders, running on the GPU. This is especially so if you’re looking to do some image p... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-webgl-shaders-in-webassembly-1e6c5effc813/</link>
                <guid isPermaLink="false">66c355f2e9895571912a0c99</guid>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Shaders ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Tutorial ]]>
                    </category>
                
                    <category>
                        <![CDATA[ WebAssembly ]]>
                    </category>
                
                    <category>
                        <![CDATA[ WebGL ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 28 Dec 2017 18:26:48 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*wJXxr-2-89FQ2O1wVXBD8w.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Dan Ruta</p>
<p>WebAssembly is blazing fast for <a target="_blank" href="https://ai.danruta.co.uk/webassembly">number crunching</a>, <a target="_blank" href="http://webassembly.org/demo/">game engines</a>, and many other things, but nothing can quite compare to the extreme parallelization of shaders, running on the GPU.</p>
<p>This is especially so if you’re looking to do some image processing. Usually, on the web, this is done through WebGL, but how would you access its APIs when using WebAssembly?</p>
<h3 id="heading-setting-up">Setting up</h3>
<p>We’ll very briefly go through setting up an example project, then we’ll look at how an image can be loaded as a texture. Then, in a separate context, we’ll apply an edge detection GLSL shader to the image.</p>
<p>All the code is in a repo <a target="_blank" href="https://github.com/DanRuta/webassembly-webgl-shaders">here</a>, if you’d prefer to jump straight to that. Note that you have to serve your files via a server for WebAssembly to work.</p>
<p>As a prerequisite, I’m going to assume you already have your WebAssembly project set up. If not, you can check out the article <a target="_blank" href="https://medium.com/statuscode/setting-up-the-ultimate-webassembly-c-workflow-6484efa3e162">here</a> on how to do it, or just fork the repo linked above.</p>
<p>For demoing the below code, I’m using a basic html file which serves only to load an image, get its imageData, and pass it to the WebAssembly code using <a target="_blank" href="https://becominghuman.ai/passing-and-returning-webassembly-array-parameters-a0f572c65d97">the <em>ccallArrays</em> function</a>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*zJIvrPP5Q_-JqJSSAH738g.png" alt="Image" width="342" height="464" loading="lazy">
<em>The HTML file with the preview input image</em></p>
<p>As for the C++ code, there is an emscripten.cpp file which manages and routes method calls to context instances created in the Context.cpp file. The Context.cpp file is structured as follows:</p>
<h3 id="heading-compilation">Compilation</h3>
<p>WebGL is based on and follows the OpenGL ES (Embedded Systems) spec, which is a subset of OpenGL. When compiling, emscripten will map our code to the WebGL API.</p>
<p>There are a couple of different versions we can target. OpenGL ES 2 maps to WebGL 1, whereas OpenGL ES 3 maps to WebGL 2. By default you should target WebGL 2, as it comes with <a target="_blank" href="https://github.com/kripken/emscripten/blob/incoming/site/source/docs/optimizing/Optimizing-WebGL.rst#which-gl-mode-to-target">some free optimizations and improvements</a>.</p>
<p>To do this, we must add <a target="_blank" href="https://kripken.github.io/emscripten-site/docs/porting/multimedia_and_graphics/OpenGL-support.html#webgl-friendly-subset-of-opengl-es-2-0-3-0">the <code>USE_WEBGL2=1</code> flag</a> to the compilation.</p>
<p>If you are planning to use some OpenGL ES features not present in the WebGL spec, you can use t<a target="_blank" href="https://kripken.github.io/emscripten-site/docs/porting/multimedia_and_graphics/OpenGL-support.html#opengl-es-2-0-3-0-emulation">he <code>FULL_ES2=1</code> and/or <code>FULL_ES3=1</code> flags</a>.</p>
<p>To be able to handle large textures/images, we can also add <a target="_blank" href="https://kripken.github.io/emscripten-site/docs/optimizing/Optimizing-Code.html#memory-growth">the <code>ALLLOW_MEMORY_GROWTH=1</code> flag</a>. This removes the memory limit of the WebAssembly program, at the cost of some optimizations.</p>
<p>If you know ahead of time how much memory you’ll need, you can instead use the <code>TOTAL_MEMORY=X</code> flag, where X is the memory size.</p>
<p>So we’re going to end up with something like this:</p>
<p><code>emcc -o ./dist/appWASM.js ./dev/cpp/emscripten.cpp -O3 -s ALLOW_MEMORY_GROWTH=1 -s USE_WEBGL2=1 -s FULL_ES3=1 -s WASM=1 -s NO_EXIT_RUNTIME=1 -std=c++1z</code></p>
<p>Finally, we need the following imports, in our code:</p>
<pre><code>#include &lt;emscripten.h&gt;#include &lt;string&gt;#include &lt;GLES2/gl2.h&gt;#include &lt;EGL/egl.h&gt;extern <span class="hljs-string">"C"</span> {       #include <span class="hljs-string">"html5.h"</span> <span class="hljs-comment">// emscripten module}</span>
</code></pre><h3 id="heading-implementation">Implementation</h3>
<p>If you have previous experience with WebGL or OpenGL, then this bit may seem familiar.</p>
<p>When writing OpenGL, the API will not work until you create a context. This is normally done using platform specific APIs. However, the web is not platform bound, and we can instead use an API integrated into OpenGL ES.</p>
<p>The majority of the legwork, however, can be more easily implemented using emscripten’s APIs in <a target="_blank" href="http://kripken.github.io/emscripten-site/docs/api_reference/html5.h">the html5.h file</a>. The functions we’re interested in are:</p>
<ul>
<li>_emscripten_webgl_create<em>context</em> — This will instantiate a context for the given canvas and attributes</li>
<li>_emscripten_webgl_destroy<em>context</em> — This is needed for cleaning up memory when destructing context instances</li>
<li>_emscripten_webgl_make_context<em>current</em> — This will assign and switch which context WebGL will render to</li>
</ul>
<h4 id="heading-create-the-context">Create the context</h4>
<p>To start implementing, you have to first create the canvas elements in your JavaScript code. Then, when using the <code>emscripten_webgl_create_context</code> function, you pass the id of the canvas as the first parameter, with any configurations as the second. The <code>emscripten_webgl_make_context_current</code> function is used to set the new context as the one currently in use.</p>
<p>Next, the vertex shader (to specify coordinates) and the fragment shader (to calculate the colour at each pixel) are both compiled, and the program is built.</p>
<p>Finally, the shaders are attached to the program, which is then linked, and validated.</p>
<p>Though that sounds like a lot, the code for this is as follows:</p>
<p>The shader compilation is done within the <code>CompileShader</code> helper function which performs the compilation, printing out any errors:</p>
<h4 id="heading-create-the-shader">Create the shader</h4>
<p>The shader code for this example is minimal, and it just maps each pixel to itself, to display the image as a texture:</p>
<p>You can access the canvas’ context in JavaScript in addition to the context in the C++ code, but it must be of the same type, ‘webgl2’. While defining multiple context types does nothing when just using JavaScript, if you do it before creating the webgl2 context in WebAssembly, it will throw an error when the code execution gets there.</p>
<h4 id="heading-loading-the-texture">Loading the texture</h4>
<p>The first thing to do when applying the shader is to call the <code>emscripten_webgl_make_context_current</code>function to make sure that we are still using the correct context, and <code>glUseProgram</code>to make sure we are using the correct program.</p>
<p>Next, we get the indices of the GLSL variables (similar to getting a pointer) via the<code>glGetAttribLocation</code>and <code>glGetUniformLocation</code> functions, so we can assign our own values to those locations. The function used to do that depends on the value type.</p>
<p>For example, an integer, such as the texture location needs <code>glUniform1i</code>, whereas a float would need <code>glUniform1f</code>. <a target="_blank" href="https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glUniform.xhtml">This is a good resource</a> for seeing which function you need to use.</p>
<p>Next, we get the texture object via <code>glGenTextures</code>, assign it as the active texture, and load the imageData buffer. The vertex and indices buffers are then bound, to set the boundaries of the texture to fill the canvas.</p>
<p>Finally, we clear the existing content, define our remaining variables with data, and draw to the canvas.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*lICDL2HxpbsJ2RjvjfzCbg.png" alt="Image" width="479" height="455" loading="lazy">
<em>The texture being loaded</em></p>
<h4 id="heading-detect-edges-using-a-shader">Detect edges using a shader</h4>
<p>To add another context, where the edge detection is done, we load a different fragment shader (which applies the <a target="_blank" href="https://en.wikipedia.org/wiki/Sobel_operator">Sobel</a> filter), and we bind the width and height as extra variables, in the code.</p>
<p>To pick between different fragment shaders, for the different contexts, we just add an if-else statement in the constructor, like so:</p>
<p>And to load the width and height variables, we add the following to the run function:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*kfvsG8s4vRLbxPxZot8isg.png" alt="Image" width="700" height="455" loading="lazy"></p>
<p>If you run into an error similar to<code>ERROR: GL_INVALID_OPERATION : glUniform1i: wrong uniform function for type</code>, then there’s a mismatched assignment function for the given variable.</p>
<p>One thing to look out for when sending the imageData, is to use the correct heap, unsigned integer (the Uint8Array typed array). You can learn more about those <a target="_blank" href="https://becominghuman.ai/passing-and-returning-webassembly-array-parameters-a0f572c65d97">here</a>, but if you’re using the ccallArray function, set the ‘<em>heapIn</em>’ config to “<em>HEAPU8</em>”, as seen above.</p>
<p>If the type is not correct, the texture will still load, but you’re going to be seeing strange renderings, like these:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*0_EmLybuEaLJnnd_JfobFg.png" alt="Image" width="706" height="466" loading="lazy"></p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>We’ve gone through a mini “Hello World!”-style project to show how to load textures and apply GLSL shaders to them in WebAssembly. The complete code is hosted on GitHub <a target="_blank" href="https://github.com/DanRuta/webassembly-webgl-shaders">here</a>, for further reference.</p>
<p>For a real project, you may want to add some additional error handling. I omitted it here, for clarity.</p>
<p>It may also be more efficient (in the above example) to share data such as the imageData texture between contexts. You can read more about this and more <a target="_blank" href="https://blog.gvnott.com/some-usefull-facts-about-multipul-opengl-contexts/">here</a>.</p>
<p>For some further reading, you can check out <a target="_blank" href="https://www.khronos.org/opengl/wiki/Common_Mistakes">this link</a> for common mistakes, or you can look through some demo projects in emscripten’s <a target="_blank" href="https://github.com/kripken/emscripten/tree/incoming/tests/glbook">glbook</a> folder, on GitHub.</p>
<p>To see WebGL being used in a WebAssembly project, you can check out the <a target="_blank" href="https://github.com/DanRuta/jsNet/tree/dev">dev branch on jsNet</a>, a web based deep learning framework, where I’ll be working on moving heavier computations onto shaders, over the next few weeks (support for WebGL compute shaders via OpenGL ES 3.1 <a target="_blank" href="https://www.khronos.org/webgl/public-mailing-list/public_webgl/1706/msg00034.php">can’t come soon enough</a> ? ).</p>
<p><strong>Update</strong></p>
<p>To see what GPU compute using shaders would look like in WebAssembly, you can check out <a target="_blank" href="https://github.com/DanRuta/GPGPU">the repo for GPGPU</a>, a small library I’m working on, with both JavaScript and WebAssembly versions.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
