LLVM IR: The Esperanto of Computer Languages
Pat Shaughnessy
by Pat Shaughnessy
2y ago
Esperanto grammar is logical and self consistent, designed to be easy to learn. via Wikimedia Commons I empathize for people who have to learn English as a foreign language. English grammar is inconsistent, arbitrary and hard to master. English spelling is even worse. I sometimes find myself apologizing for my language’s shortcomings. But learning any foreign language as an adult is very difficult. Esperanto, an “artificial language,” is different. Invented by Ludwik Zamenhof in 1873, Esperanto has a vocabulary and grammar that are logical and consistent, designed to be easier to learn. Zamen ..read more
Visit website
Visiting an Abstract Syntax Tree
Pat Shaughnessy
by Pat Shaughnessy
2y ago
Joshua Tree National Park (via: Wikimedia Commons) In my last post, I explored how Crystal parsed a simple program and produced a data structure called an abstract syntax tree (AST). But what does Crystal do with the AST? Why bother going to such lengths to create it? After Crystal parses my code, it repeatedly steps through all the entries or nodes in the AST and builds up a description of the intended meaning and behavior of my code. This process is known as semantic analysis. Later, Crystal will use this description to convert my program into a machine language executable. But what does th ..read more
Visit website
Reading Code Like a Compiler
Pat Shaughnessy
by Pat Shaughnessy
2y ago
Imagine trying to read an entire book while focusing on only one or two words at a time We use compilers every day to parse our code, find our programming mistakes and then help us fix them. But how do compilers read and understand our code? What does our code look like to them? We tend to read code like we would read a human language like English. We don’t see letters; we see words and phrases. And in a very natural way we use what we just read, the proceeding sentence or paragraph, to give us the context we need to understand the following text. And sometimes we just skim over text quickly ..read more
Visit website
Find Your Language’s Primitives
Pat Shaughnessy
by Pat Shaughnessy
2y ago
If you dig into your programming language's syntax, you might discover that it is capable of much more than you thought it was. Wikipedia defines “Language Primitive” this way: In computing, language primitives are the simplest elements available in a programming language. A primitive is the smallest 'unit of processing' available to a programmer of a given machine, or can be an atomic element of an expression in a language. By looking at a language’s primitives, we can learn what kind of code will be easy to write or impossible to express, and what types of problems the language was intended ..read more
Visit website
Generic Types: Adding Math Puzzles To Your Code
Pat Shaughnessy
by Pat Shaughnessy
2y ago
In this formula, x is the bound variable, a is the free variable and e is constant. Most modern, statically typed languages allow us to use generic types. We write a function once with generic type syntax, and then the compiler can apply the same code over and over again to different actual, concrete types. Hence the name generic. This is a powerful language feature, but generic code is often confusing and hard to read. For me, generic code resembles something from my high school algebra textbook. I see small math puzzles sprinkled around my computer program. Why do this? Why add math problem ..read more
Visit website
To Learn a New Language, Read Its Standard Library
Pat Shaughnessy
by Pat Shaughnessy
2y ago
If I was learning to read English as a foreign language, I would need something simple to get started. (from The Remarkable Story of Chicken Little, 1840) The best way to learn a new programming language, just like a human language, is from example. To learn how to write code you first need to read someone else’s code. But who is the best person to learn from? Which code should we read? Where should we look to find it? This year in my spare time I was learning about Crystal. I had played around with some simple scripts, but I wanted to learn more. Then I stumbled on to Crystal’s standard libr ..read more
Visit website
Downloading 100,000 Files Using Async Rust
Pat Shaughnessy
by Pat Shaughnessy
2y ago
Rust's new async/await feature makes it easy to stop and start asynchronous tasks (from: Wikimedia Commons) Imagine if you had a text file containing thousands of URLs: $ cat urls.txt https://example.com/1.html https://example.com/2.html https://example.com/3.html etc... https://example.com/99999.html https://example.com/100000.html …and you needed to download all of those HTML pages efficiently. How would you do it? Maybe a shell script using xargs and curl? Maybe a simple Golang program? Go’s powerful concurrency features would work well for this. Instead, I decided to try to use Rust ..read more
Visit website
Using Result Combinator Functions in Rust
Pat Shaughnessy
by Pat Shaughnessy
2y ago
Rust’s Result type can help you control your program’s flow by checking for errors in a succinct, elegant way Using Rust for the first time, error handling was my biggest stumbling block. Was this value a Result<T, E> or just a T? And the right T? The right E? I couldn’t just write the code I wanted to write. It felt confusing and overly elaborate. But after a while, I started to get a feel for the basics of using Result. I discovered that the combinator methods Result provides, like map, or_else and ok, made error handling fun. Well, maybe that's a bit of an overstatement. They made us ..read more
Visit website
How Rust Makes Error Handling Part of the Language
Pat Shaughnessy
by Pat Shaughnessy
2y ago
In Spanish these are all “dedos,” while in English we can distinguish between fingers and toes. Learning a foreign language can be an incredible experience, not only because you can talk to new people, visit new countries, read new books, etc. When you learn the words someone from a different culture uses, you start to see things from their perspective. You understand the way they think a bit more. The same is true for programming languages. Learning the syntax, keywords and patterns of a new programming language enables you to think about problems from a different perspective. You learn to s ..read more
Visit website
Using Rust to Build a Blog Site
Pat Shaughnessy
by Pat Shaughnessy
2y ago
Rust comes with batteries included (source: Wikimedia Commons) After “Hello World,” blog sites are the world’s second most unneeded application. If you want to write a blog, use Medium, Wordpress or just Twitter. The world doesn’t need another blog app. However, like Hello World, building a static site generator is a great way to get your feet wet in a new programming language. Recently I rewrote the script I use to generate this web site using Rust: I needed to update and fix my script, but really I was looking for an excuse to write Rust. Despite its reputation as a difficult to learn, expe ..read more
Visit website

Follow Pat Shaughnessy on FeedSpot

Continue with Google
Continue with Apple
OR