A short overview on how to setup a development environment for and make some first steps with the Ada programming language.
Rust Hello World Web Service
I always wanted to learn about writing web services in Rust. I know a bit about Java servlets and the Spring framework for Java. But how to start in Rust?
As Rust is strong in systems programming, it has good support for networking and some frameworks to help you with writing applications and services for the web. I prefer to start at the HTTP level so I do not need to fumble with TCP/IP protocol things. Something similar to Java servlets would be nice to get started.
While reading an article about asynchronous programming in Rust (in German), I stumbled across Tokio, an asynchronous runtime. At first, it looked as if it would be a good starting point. But after trying the hello world example, I realized that it is a bit too low level for me. My knowledge of Rust is not yet good enough for this. However, there are other, more high-level libraries to choose from. Next, I had a look at Warp and Rocket.
The following is the hello world example for Warp right from their documentation.
use warp::Filter;
#[tokio::main]
async fn main() {
// GET /hello/warp => 200 OK with body "Hello, warp!"
let hello = warp::path!("hello" / String)
.map(|name| format!("Hello, {}!", name));
warp::serve(hello)
.run(([127, 0, 0, 1], 3030))
.await;
}
This looks simple enough for me to understand. 😀 I could setup this example and run it in my local Rust development environment without problems. After I got that working, I had a look at the hello world example for Rocket. Again, this is straight from their website, just to get an impression.
#[macro_use] extern crate rocket;
#[get("/hello/<name>/<age>")]
fn hello(name: &str, age: u8) -> String {
format!("Hello, {} year old named {}!", age, name)
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![hello])
}
This as well looks good to me. What I like about Rocket is that they have first-class support for JSON and a testing library as well.
I haven’t decided yet, whether to start with Warp or Rocket. I’ll go, study their documentation and try some example code to get a better feeling for them.
Scheme Development Environment
I’m currently evaluating Scheme development environments. More specifically, I have a look at Racket and GNU Guile. I want to have something that works on my Linux machine, but as well on my Windows machine using WSL. I do not need a fancy IDE yet. To get started, I think it is enough to have an editor with syntax highlighting and some REPL. I intend to use Vim and Emacs for now to write my Scheme code. Both offer some default syntax highlighting as well as several plugins to get some more advanced language support, if needed.
Racket has a graphical environment called DrRacket. However, I do not want to get used to it, because I do not want to depend on it. Installation of Racket is pretty simple. To get the latest version, I downloaded Racket from their website and installed it to /opt
. Installation can be done without administrator rights. Then I created a symbolic link to the racket executable in my ~/.local/bin
directory. That’s enough to have the REPL in my executable search path. When run interactively, Racket will load a initialization file from ~/.racketrc
. For now, I’m not using it though.
Because I could not find pre-build releases on their website, I installed Guile with apt-get
. Unfortunately I got a version that is more than one year old. As I prefer not to build Guile from scratch using the provided tarballs, I have to live with this old version for now. When installing with apt-get
, you have to choose the major version you want to use. So you have to do apt-get install guile-3.0
, for example. Apt added Guile to my /usr/bin
directory. So it is in my executable search path as well.
When run interactively, Guile will load a initialization file from ~/.guile
. As Guile does not enable readline support by default, at least Guile 3.0 does not, it is a good idea to add the following lines to your .guile
file.
(use-modules (ice-9 readline))
(activate-readline)
Now I have a (somewhat minimalist) development environment with Vim and Emacs for writing Scheme code and Racket and Guile REPL to execute the code. I like the very easy installation of Racket. Let’s see how far I can get with this setup.
Iterators in Rust
I found an interesting article about iterators in Rust (in German). It has been a while since I found some time to try some Rust and I decided to try some of the examples in the article.
The following code block show a very simple example of how to use iterators.
pub fn run_iterator() {
let numbers = &vec![1, 1, 2, 3, 5, 8, 13];
println!("The min is {}", numbers.into_iter().min().unwrap());
for number in numbers {
println!("The next value is {}", number);
}
}
By the way, I which that WordPress had syntax highlighting for Rust code blocks. 🙁
Anyway, I have learned that memory ownership is important here and that the above code would not work, if I had written let numbers = vec![1, 1, 2, 3, 5, 8, 13]
instead of let numbers = &vec![1, 1, 2, 3, 5, 8, 13]
. Note the added ampersand sign (&), which denotes a borrowed reference.
It looks like I have to learn more about memory ownership in Rust before working with iterators. 🙂
Source code for this blog post can be found on SourceForge.
Referenced article: Ferris Talk #1: Iteratoren in Rust (in German). Copyright © 2021 Heise Medien.
On microservices and APIs
Here are some resources about microservices and APIs that I came across recently. In no particular order.
- Stack Overflow – Best practices for REST API design
- MartinFowler.com – Microservices – a definition of this new architectural term
- InfoQ – GraphQL Reference Guide: Building Flexible and Understandable APIs
- School of Haskell – Web app/Microservice example in Haskell
- The blog of wjwh – Building a small microservice in Haskell
Ressourcen zu Microservices und APIs in deutscher Sprache.
- heise Developer – Micro Frontends – die Microservices im Frontend
- Eberhard Wolff YoutTube – APIs mit Erik Wilde
Summary Statistics in R and Python
I wonder how easy it is, to do simple statistics with Python and R. For example, to calculate mean, median and other summary statistics. Let’s start with the following very simple data set.
height weight 1.85 85.0 1.80 79.1 1.91 80.5 1.75 80.3 1.77 90.8 1.79 60.9 1.81 81.1 1.69 70.2 1.80 70.9 1.89 90.9
Having stored this data in a file called “data.csv” (comma-separated), you can read this file in R using the following single line of code.
hw <- read.csv("data.csv")
The file will be read into variable “hw” of class (type) “data.frame”.
> class(hw) [1] "data.frame"
Do a quick check that the data was read correctly by evaluating the variable or access single columns of the data frame.
> hw height weight 1 1.85 85.0 2 1.80 79.1 3 1.91 80.5 4 1.75 80.3 5 1.77 90.8 6 1.79 60.9 7 1.81 81.1 8 1.69 70.2 9 1.80 70.9 10 1.89 90.9 > hw[,1] [1] 1.85 1.80 1.91 1.75 1.77 1.79 1.81 1.69 1.80 1.89 > hw[,2] [1] 85.0 79.1 80.5 80.3 90.8 60.9 81.1 70.2 70.9 90.9
Now how can we read the data using Python? This is best handled with the help of a library like pandas. The data will be read into a variable of type DataFrame.
>>> import pandas as pd >>> hw = pd.read_csv("data.csv") >>> hw height weight 0 1.85 85.0 1 1.80 79.1 2 1.91 80.5 3 1.75 80.3 4 1.77 90.8 5 1.79 60.9 6 1.81 81.1 7 1.69 70.2 8 1.80 70.9 9 1.89 90.9 >>> hw["height"] 0 1.85 1 1.80 2 1.91 3 1.75 4 1.77 5 1.79 6 1.81 7 1.69 8 1.80 9 1.89 Name: height, dtype: float64 >>> hw["weight"] 0 85.0 1 79.1 2 80.5 3 80.3 4 90.8 5 60.9 6 81.1 7 70.2 8 70.9 9 90.9 Name: weight, dtype: float64
Now that the we have read the data into our programming environment, we can calculate some summary statistics like mean and median. Let’s start with R, which has build-in functions for this.
> mean(hw[,1]) [1] 1.806 > mean(hw[,2]) [1] 78.97
For Python, the pandas library provides functions to calculate summary statistics.
>>> hw["height"].mean() 1.8060000000000003 >>> hw["weight"].mean() 78.97
As you can see, it is very straightforward to calculate summary statistics with R and Python. Next time, I will evaluate, how to do a linear regression and plot the results.
Basic stdin/stdout programs in Haskell
It is not very complicated to write basic stdin/stdout Unix-style programs in Haskell. For example, the following one-line program copies stdin to stdout.
main = interact id
This might not look very useful, but this code is a good starting point to implement, for example, Unix-style filter programs. When you look at the definition of interact, you get ideas about adding additional logic.
interact f = do s <- getContents putStr (f s)
For example, a filter that does a line-based transformation for each line in stdin and writes the transformed lines to stdout, might look as follows.
main = do contents <- getContents let ls = lines contents lst = map transformLine ls str = unlines lst putStr str
As you can see, Haskell already comes with some nice functions to handle lines in text-files. See Tutorials/Programming Haskell/String IO in the Haskell wiki for some more inspiration.
Ageism anyone?
Shame on you, HP! You copied IBM!
Lawsuit klaxon: HP, HPE accused of coordinated plan to oust older staff in favor of cheaper, compliant youngsters
IBM isn’t the only IT giant said to be unfairly binning elders
https://www.theregister.co.uk/2020/05/22/hp_hpe_accused_of_coordinated/
© 2020 The Register
Hhm, cheaper, compliant youngsters? What happened to the highly-educated, tech-savvy, environmental-friendly, world-changing youngsters?
Happy birthday Hubble!
The Hubble Space Telescope launched 30 years ago—then the problems began
What stands out most vividly in my mind is all things that didn’t go right.
https://arstechnica.com/science/2020/04/the-hubble-space-telescope-launched-30-years-ago-then-the-problems-began/
© 2020 Condé Nast. All rights reserved.
Sternexplosionen, Exoplaneten, Schwarze Löcher: Weltraumteleskop Hubble wird 30
Hubble ist längst ein Popstar. Weil der Nachfolger auf sich warten lässt, steht das Weltraumteleskop zum 30. Geburtstag weiter im Rampenlicht.
https://heise.de/-4707642
Copyright © 2020 Heise Medien
Herzlichen Glückwunsch! 🙂
Bayes and null hypothesis significance testing
I found these interesting articles about Bayes and null hypothesis significance testing by Andrew Gelman.
What’s wrong with Bayes
My problem is not just with the methods – although I do have problems with the method – but also with the ideology.
https://statmodeling.stat.columbia.edu/2019/12/03/whats-wrong-with-bayes/
Copyright 2020 Columbia University.
What’s wrong with null hypothesis significance testing
Following up on yesterday’s post, “What’s wrong with Bayes”.
https://statmodeling.stat.columbia.edu/2019/12/04/whats-wrong-with-null-hypothesis-significance-testing/
Copyright 2020 Columbia University.
Haskell development environment
I finally found some time to adjust my Haskell development environment. Up to now, I was just trying some snippets in GHCi. But as I am used to IDEs, I would prefer to have at least some kind of build tool connected to my editor. As it turned out, I already have something installed.
Cabal is a build tool for Haskell. I had chosen to install the Haskell Platform and Cabal is included there. Cabal reminds me a bit of Apache Maven or Microsoft dotnet
tool for .NET. You can easily create and run a hello world project as follows.
cabal init -n --is-executable cabal run
After reading some documentation, I was confused about another tool called Stack. It is my understanding that Stack is used to created isolated Haskell environments. Somewhat like virtualenv or venv for Python. I will stick with Cabal for now. For a discussion of Cabal vs. Stack, see the following discussions on StackOverflow: What is the difference between Cabal and Stack? and How to install Haskell (Platform or Stack) in 2018 on Linux?.
I had already installed Haskell Mode for Emacs, so I think that I can now start little projects.
Articles about Rust
I found these articles about Rust just recently.
How I Start: Rust
Rust has a reputation of being difficult because it makes no effort to hide what is going on. I’d like to show you how I start with Rust projects.
https://christine.website/blog/how-i-start-rust-2020-03-15
Copyright 2020 Christine Dodrill.
How to Learn Rust Without Installing Any Software
In this article, we’ll learn how to use GitHub Actions to learn Rust from your web browser. We’ll code, build, test, run, and release all from a web page. No software needed!
https://www.freecodecamp.org/news/learn-rust-with-github-actions/
Copyright 2020 freeCodeCamp.
Rust Lang in a nutshell: 1# Introduction
This is the first part of a mini-series of articles addressed to all who want to get familiar with Rust programming language. No previous background in Rust is expected, but understanding of basic concepts of programming languages may be of help.
https://www.softax.pl/blog/rust-lang-in-a-nutshell-1-introduction/
Copyright 2020 Softax.
Amazon Braket
Explore and experiment with quantum computing
Amazon Braket is a fully managed service that helps you get started with quantum computing by providing a development environment to explore and design quantum algorithms, test them on simulated quantum computers, and run them on your choice of different quantum hardware technologies.
https://aws.amazon.com/braket/
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Oh, whoa! Amazon lets you play on their quantum things. What are you waiting for?
Australian Space Agency
Australien hat jetzt eigene Weltraumbehörde – mehr Engagement geplant
Australien bekommt mit der Australian Space Agency eine eigene Weltraumbehörde. Dadurch sollen Tausende Jobs entstehen.
https://heise.de/-4664328
Copyright © 2020 Heise Medien
Das die Bergbau-Spezialisten aus Australien sich für den Weltraum interessieren, ist jetzt auch nicht so überraschend, oder?