HNHacker News
TopNewBestAskShowJobs

JoshMcguigan

429 karma · joined November 17, 2018

https://www.joshmcguigan.com/
submissionscomments
JoshMcguigan··on Ask HN: What were your most impactful podcast episodes from 2019?
I'll second this recommendation. Every episode so far has been top notch! I really hope they are able to keep the quality bar high as they continue to make episodes.
JoshMcguigan··on Blue-Green Deployments and Immutable Infrastructure
Hey HN, OP here. This is the third post in a series about running your own authoritative DNS infrastructure.

The previous posts were about why I'm doing it and how to setup an authoritative DNS server [0], and how I monitor these machines [1].

This post provides an overview of how I automated the deployment of these servers.

[0]: https://www.joshmcguigan.com/blog/run-your-own-dns-servers/

[1]: https://www.joshmcguigan.com/blog/low-cost-infrastructure-mo...

JoshMcguigan··on Null References: The Billion Dollar Mistake
In my experience, languages with strict non-null guarantees (and optional types), do the exact opposite of "mask the error". If anything, they are sometimes faulted for being too verbose.

The idea is, by explicitly marking things which can be null (wrapping them in an Option[T], for example), you can be sure that everything else is not null. This alone relieves the developer of a large cognitive load.

Further, the language can provide syntax to make handling optional types obvious without being painful. Rust match statements are one example of this.

Can you provide a specific example of how using an optional type makes a potential "missing-thing" type of bug harder to see?

JoshMcguigan··on Null References: The Billion Dollar Mistake
The goal of `Optional[T]` is not to "make the problem magically go away", in fact that is almost the opposite of the goal.

Optional[T] exists to make it very obvious when a value is nullable. Having non-nullable types as default, with Optional[T], allows a developer to model a system more accurately. This is helpful both to the compiler as well as anyone else who reads/maintains that code.

> Imagine, for example, in an Optional based language, that you just map the optional to a lambda to execute on the optional, and the behaviour of the optional is to then simply silently do nothing if it's optional.none. That'd be a much harder to find bug than a nullpointer error. (errors with stack traces pointing at the problem are obviously vastly superior to mysterious do-nothing behaviour with no logs or traces of any sort!).

This is just one of the things a developer could decide to do when faced with an optional which is none. It is up the language design to make it easy to express this behavior (or any other behavior they might choose) without hiding it.

JoshMcguigan··on Let the Compiler Do the Work
For your `sqr` function, what is the benefit of writing `x * x` over using `x.powi(2)` [0]? You didn't mention it in the article, but did you find a performance improvement from doing this?

[0]: https://doc.rust-lang.org/std/primitive.f64.html#method.powi

JoshMcguigan··on Actix Web: Optimization Amongst Optimizations
Thanks for the response.

So it sounds like it is not so much the allocation/de-allocation savings that matters, but rather that you get to skip initializing the memory because it is already known to be a valid instance of a given struct type?

JoshMcguigan··on Actix Web: Optimization Amongst Optimizations
> On startup, 128 request and response objects are pre-allocated in per-thread pools. As a request comes in, one of them is checked out, populated, and handed off to user code. When that code finishes with it and the object is going out of scope, Drop kicks in and checks it back into the pool for reuse. New objects are allocated only when pools are exhausted, thereby saving many needless memory allocations and deallocations as a web server handles normal traffic load.

As someone not very familiar with systems programming, I would have expected this is an optimization that would already happen automatically within the system memory allocator. Is that not the case?

JoshMcguigan··on A Thought Experiment: Using the ECS Pattern Outside of Game Engines
I look forward to seeing the ladder logic editor. I run PLCFiddle [0], which is a purely React ladder logic editor.

[0]: https://www.plcfiddle.com

JoshMcguigan··on Run Your Own Authoritative DNS Servers
Hi all, author here. I recently took an interest in running more of my own infrastructure, as I think that is the best way to deepen my understanding of how things work.

This blog post outlines why and how I run my own authoritative DNS servers.

JoshMcguigan··on Things end users care about but programmers don't
For those who haven't seen it, I believe reacweb is referencing this [0].

[0]: https://www.folklore.org/StoryView.py?story=Calculator_Const...

JoshMcguigan··on Quadcopter Programming Part 2: Using the CMSIS Library and First Takeoff
I found quadcopters to be a great way to get into embedded development. There are a couple posts on my blog [0] [1] related to getting Rust running on a quadcopter controller, although I never actually got my code controlling the drone in flight. The lesson I learned was that if I was going to do it again I'd definitely choose a board with an exposed debugger port, as I spent a lot of time repurposing one of the motor outputs into a serial transmit port just to do some "println debugging".

Not sure if OP is here, but I'd be interested in hearing about which debug options are easily exposed on that board. Can you use the port you are flashing the drone with as a standard serial port after your code is loaded? Looking forward to the future post about SWD that is introduced at the end of this post as well.

[0]: https://www.joshmcguigan.com/blog/betafpv-drone-flight-contr...

[1]: https://www.joshmcguigan.com/blog/betafpv-drone-flight-contr...

JoshMcguigan··on Beating C with one line of Brainfuck
Is the 85MB test file available? I wasn't able to find it. I'd like to test this result against nerve [0], a brainfuck to x86_64 asm compiler I wrote (like funkicrab, it is also written in Rust).

[0]: https://github.com/JoshMcguigan/nerve

JoshMcguigan··on Show HN: Hacker News Title Edit Tracker
> Any titles for specific story IDs that change get tracked..

Can you talk more about the data infrastructure?

JoshMcguigan··on 100k+ page views a month for $5 with a self-hosted static site
How do you view your Netlify usage while on the free tier? Your comment made me curious about my own usage, but I can't see a way to determine my current usage through the Netlify website.
JoshMcguigan··on Command Line Applications in Rust
I always thought it was "The Fine Article".
JoshMcguigan··on Command Line Applications in Rust
For anyone who hasn't seen it, I highly recommend structopt over clap. It is a wrapper around clap which provides type safe parsing of CLI arguments into a struct you define. It is also what TFA uses.
JoshMcguigan··on Command Line Applications in Rust
Here’s another fancy idea: Write that README before you write the code.

I find this idea to be very effective, as long as the scope can be kept to a minimum (think MVP). I've seen it work not only for CLI apps, but also for simple HTTP API servers.

JoshMcguigan··on Understanding Serde
Thanks for sharing. I'm not familiar with D, but it looks like compile time type introspection is something which is built into the language, which removes the need for something like the serde derive macro. Is that correct?
JoshMcguigan··on Understanding Serde
> I want one casing rule for one target, and a different one for another

Hmm, this is interesting, and something I hadn't thought of before. I'd probably try to solve it with a combination of the newtype pattern (create wrapper types for `MyThing`, like `MyThingJson` and `MyThingToml`) and the Serde flatten attribute. Then you could, for example, add `#[serde(rename_all = "lowercase")]` to the `MyThingJson` struct and `#[serde(rename_all = "snake_case")]` to the `MyThingToml` struct.

I haven't tested this though, so I'm not sure if the `rename_all` would flow through the flatten attribute as expected. Worst case you could duplicate the struct (or more likely, find or build a macro to do it for you) rather than use the newtype/flatten technique.

JoshMcguigan··on Kiss – A Linux distribution with a focus on “less is more”
Is there a docker image available? I'd like to experiment with the package manager, but I'd rather not setup a VM.
JoshMcguigan··on My First LLVM Compiler (2015)
I recently wrote a brainfuck compiler using Rust [0], but I targeted x86-64 asm directly. I implemented some very basic optimization (as you show at the bottom of your post), but I'd imagine llvm is able to take things much further. I'd be curious to see a performance comparison.

[0]: https://github.com/JoshMcguigan/nerve

JoshMcguigan··on The Cult of Kubernetes
I know the author has other goals (a desire to learn/practice kubernetes, and keep host their blog the same way as the other services they manage), but I'd like to point out here that if your end goal is a blog which auto-deploys on each push to master, Netlify has a fantastic free tier. I use Gatsby/Netlify, and operations/deployment is a 100% non-issue, and the site is very fast.
JoshMcguigan··on Coverage Reports as a Code Reading Tool
Hey HN, author here. Inspired by this great strange loop talk by Alan Shreve [0], which discusses a non-standard use for code coverage reports, I wrote a blog post about using kcov [1] and pycobertura [2] as a tool to help start understanding a new-to-you codebase.

As a specific example, I take the use case of understanding how keypresses are handled within Alacritty [3], a terminal emulator written in Rust.

[0]: https://www.youtube.com/watch?v=dSqLt8BgbRQ

[1]: https://github.com/SimonKagstrom/kcov

[2]: https://github.com/aconrad/pycobertura

[3]: https://github.com/jwilm/alacritty

JoshMcguigan··on What does an unprocessed RAW file look like?
This was really neat, but I wish the author went into similar detail for the auto white balance step.
JoshMcguigan··on Rust, a Raspberry Pi and Addressable LEDs
I may have overlooked some things, but I made a quick PR[0] just to see what this would look like using a Vec<u8>. Feel free to close if you prefer the original.

[0]: https://github.com/tomarrell/rasp-ws2812b/pull/2

JoshMcguigan··on Rust, a Raspberry Pi and Addressable LEDs
Thanks for sharing.

One question about the code, why does the LedPanel struct use a String as a buffer rather than using a Vec<u8>?

edit - I think I see the reason now. Using a string made it easy to print the u8 as a string of bits, which you could then iterate over using chars. This was used to help perform the conversion from bits directly representing colors to the on the wire representation.

JoshMcguigan··on Raspberry Pi 4 launch site runs on a Pi 4 cluster
The article describes the downtime as being caused by a "severe BGP error Verizon made".
JoshMcguigan··on Shell Completions in Rust
These [0] two [1] sections of the GNU Bash man pages were very useful. I also found that this tutorial [2] provided a useful perspective. I spent a small amount of time looking through the bash-completion [3] project as well as the git bash completions [4].

Generally, my process for writing is google around until I have some base level of knowledge, then building one or more demo applications to ensure my understanding is correct. Then as I'm writing the blog post I'll be refining the demo applications into examples for the blog post and/or library code that I want to open source.

[0]: https://www.gnu.org/software/bash/manual/html_node/Programma... [1]: https://www.gnu.org/software/bash/manual/html_node/Programma... [2]: https://hackaday.com/2018/01/19/linux-fu-custom-bash-command... [3]: https://github.com/scop/bash-completion [4]: https://github.com/git/git/blob/master/contrib/completion/gi...

JoshMcguigan··on Shell Completions in Rust
I did come across this work by clap while doing research for this post. The major difference in strategy is that clap is generating completion scripts in Bash, while shell_completion is a library which helps writing completion scripts in Rust. I think one exciting bit of future potential for shell_completion is it could potentially allow building something like what clap has done using the standard Rust macro system.

In any event, thanks for bringing this up.

JoshMcguigan··on Shell Completions in Rust
Your characterizations are spot on. One major potential improvement for the shell_completion crate is to provide a higher level API for use by completion script writers. This will of course make writing completion scripts easier, but it will also allow for abstraction over various shells.

Thank you for the detailed feedback.

← PreviousPage 2 of 3Next →