HNHacker News
TopNewBestAskShowJobs

m-ou-se

369 karma · joined February 18, 2015

submissionscomments
m-ou-se··on Methods for Array Initialization in Rust (2018)
It was stabilized in 2019 by accident:

https://twitter.com/m_ou_se/status/1396827152859942921

https://github.com/rust-lang/rust/pull/79270

m-ou-se··on Methods for Array Initialization in Rust (2018)
An important one is missing from this overview: using a const. This is sometimes useful, because it does not require the type to be Copy; only that the value is a constant:

    const EMPTY: String = String::new();
    let a: [String; 1000] = [EMPTY; 1000];

    const NONE: Option<String> = None;
    let b: [Option<String>; 1000] = [NONE; 1000];

    const SEVEN: AtomicU32 = AtomicU32::new(7);
    let c: [AtomicU32; 200] = [SEVEN; 200];
m-ou-se··on Ask HN: Who wants to be sponsored? (February 2021)
SEEKING SPONSOR: I work on the Rust standard library and compiler. As of a few months ago, I'm part of the Rust library team, which is the team that manages everything in and around the standard library. I'm currently working on the panicking infrastructure, improving the synchronization/locking primitives*, and on a new (more efficient) implementation of how formatting arguments are represented**. I also spend a lot of time reviewing incoming pull requests for the standard library, and am working on streamlining the organization around all this.

https://github.com/sponsors/m-ou-se/

*: Much of which has already landed: On Windows, mutexes etc. are no longer heap-allocated. And on many platforms, thread parking now directly uses futex(-like) syscalls/APIs.

**: That is, how a format_args!() is represented at runtime, which is relevant for all println!(), format!(), etc. macros that do any formatting.

m-ou-se··on A half-hour to learn Rust
`T: 'a` means that you may keep values of type T around for lifetime 'a, but not that they will. So `T: 'static` means that you may keep values of that type around forever, as they do not refer to anything that doesn't live forever.

So neither `&'a i32` nor `MutexGuard<'a, i32>` are 'static (unless 'a is), because you shouldn't keep references like that around longer than the stuff it points to. But i32 by itself satisfies i32: 'static, because it's perfectly fine to keep an i32 around forever. (But that doesn't mean that every i32 will stick around forever.)

m-ou-se··on Writing Python inside Rust
Good point! Updated.
m-ou-se··on Writing Python inside Rust
Thanks! Updated.
m-ou-se··on Writing Python inside Rust
Imports work fine. The main reason I wrote this, was to be able to use the Python matplotlib library in Rust:

https://twitter.com/m_ou_se/status/1120577172438233088

m-ou-se··on Write Python inline in your Rust code
It doesn't translate Python to Rust or anything like that, it uses CPython both to compile to Python bytecode and to run it. It doesn't launch a separate interpreter, the interpreter is used as a library, so runs in the same process.

Python doesn't really do multithreading: https://wiki.python.org/moin/GlobalInterpreterLock

It uses Python 3 of course. Using Python 2 these days would be a crime.

m-ou-se··on Write Python inline in your Rust code
It uses the same Python interpreter, but each macro invocation is considered its own module. A later version of the crate will have the possibility to keep the context around to be re-used by a later invocation such that, for example, you don't need to import things again.
m-ou-se··on Write Python inline in your Rust code
In Python, all data (even simple integers) are all allocated on the heap. ToPyObject makes a deep copy of everything, converting everything to `PyObject` on the heap, so all data is owned.

The numpy crate helps if you need to convert large arrays to Python, as numpy does not store every element separately on the heap.

m-ou-se··on Write Python inline in your Rust code
Matplotlib was one of the reasons I made this. Works just fine: https://github.com/dronesforwork/inline-python/blob/aebabc88...
m-ou-se··on Write Python inline in your Rust code
At work, we make high performant drone control systems in Rust. But for testing and debugging, we simply use Matplotlib (a Python library) to make plots of simulations, etc. So we prefer Rust for the control systems themselves for the speed and reliability, but for plotting results of simulations, we don't care much about performance and rather just use something with all the features we need.
m-ou-se··on Write Python inline in your Rust code
Author here. Let me know if you have any questions. :)
m-ou-se··on UFO: A Drone/UAV Programming Library for Rust
Yes, this was our main worry as well. At first we switched to Rust only for the lower level code, the parts that interfaces with sensors and the motors, that do the data logging, our inter process communication library, etc. The part with the control algorithms (where all the interesting linear algebra code is) was still in C++ until recently.

For all the small vectors and matrices, things like Vector3 and Matrix3x3 from nalgebra work fine. A few generic things we had to change from statically sized to dynamically sized arrays/matrices, but since these were rather big already, the difference in performance was neglegible. The type safety was maintained by directly wrapping those in a generic struct where the template parameter describes the contents of the matrix or vector. Such template parameter is basically a struct where the members describe the meaning of all the columns/rows of the related vector/matrix. A custom derive proc macro generated the conversions to and from this type (which are all optimized away by the compiler). It looks something like this:

    struct Foo<T: VectorLike> {
        matrix: DynanamicallyAllocatedMatrix<f64>,
    }

    impl<T: VectorLike> Foo<T> {
        fn new() {
            Foo { matrix: DynanamicallyAllocatedMatrix::zeros(T::N, T::N) }
        }
        fn get_diagonal(&self) -> T { ... }
        ...
    }
We were already doing something like this in C++, but with some hacky preprocessor macros instead of Rust's procedural macros.

In the end, keeping track of the meaning of the entire vector/matrix in the type system provides us with even a lot more safety than only keeping the size of them in the type system. And it has the advantage that you don't need const generics, since you're keeping track of whole types, and not just numbers. The downside is that we have to maintain a few procedural macro implementations.

m-ou-se··on UFO: A Drone/UAV Programming Library for Rust
We do, but it's very minimal for now: https://dronesforwork.nl/

We'll be changing our company name in a few weeks, followed by the launch of a new website which should have a lot more information than the current one.

m-ou-se··on UFO: A Drone/UAV Programming Library for Rust
Yes! I'm founder of a start-up (about 10 employees now) that makes flight controllers for Drones, and all the software that runs on them is written in Rust.

We don't use STM chips though. Since the way we do state estimation and fault tolerant control requires a lot of computational power, we settled on 64-bit ARM Cortex A series processors. Since there was nothing available that fit our requirements, we produce the hardware ourselves as well.

When we started a bit more than two years ago, we started in C++, but have been slowly switching to Rust starting less than a year later. Now that everything is in Rust, our productivity went up a lot, together with the reliability of our systems (which is our main selling point).

The thing we miss most from C++ is the Eigen library, but the alternatives in Rust are pretty okay, though less complete. We are adding features and optimizations to some of these libraries, which we'll publish open source in a few months probably.

m-ou-se··on Moving from Ruby to Rust
C does not have a modulo operator. It has a remainder operator, which works perfectly fine. Calling C's `%` a 'broken modulo operator' is like calling `+` a 'broken minus operator'. Quite a few languages have separate operators, keywords, or functions for 'modulo' and 'remainder'.
m-ou-se··on Nothing Can Stop Google. DuckDuckGo Is Trying Anyway
They have duck.com and ddg.gg. Both Firefox and Chromium make <ctrl-enter> wrap the url in 'www.' and '.com', so 'duck<ctrl-enter>' works.
m-ou-se··on Show HN: I built a puzzle / programming challenge with a 0.125 BTC prize
All of the first challenge's puzzles can be solved with:

    .thing {
      background: url(data:image/png;base64,iVBO...);
      width: ...px;
      height: ...px;
    }
Where the image data is just the target image itself. :)
m-ou-se··on Fitness app gives anyone names+address for 1000s of soldiers and secret agents
Note: It's not a paywall. Simply click 'Eerst verder lezen' to read the full article.
m-ou-se··on C++17 Standard Published
> basically all the symbols you can find on a keyboard

C++ doesn't even use @ and $, yet ;)

m-ou-se··on C++17 Standard Published
Some do. More are active on Reddit. But new proposals can come from anyone. Though, before writing and submitting any, check on the public std-proposals mailinglist if your idea would get any traction. See https://isocpp.org/std/submit-a-proposal

std::set does have a contains() function, it's called count(): http://en.cppreference.com/w/cpp/container/set/count

m-ou-se··on C++17 Standard Published
You can build the pdf yourself from the LaTeX source: https://github.com/cplusplus/draft

Or get the latest public draft from https://wg21.link/standard

Or an html version: http://eelis.net/c++draft/

m-ou-se··on C++17 is formally approved
C++ already had syntax for pulling out one member by name: ;)

    const auto x = f().x1;
m-ou-se··on FE-Schrift: forgery-impeding typeface
Dutch license plates have similar properties. Not by changing the proportions of the letters, but by cutting out parts of letters. For example, the R is missing a piece so you can't make it from a P and some black tape: https://commons.m.wikimedia.org/wiki/File:Netherlands_licens...
m-ou-se··on Fangle: create interactive documents from plain text
This made me laugh: "His power level is [3000.1]. That's 0.09999999999990905 more than 3000."
m-ou-se··on Australian PM Calls for End-To-End Encryption Ban
The police doesn't make the law.
m-ou-se··on Ask HN: What are the 3 websites you visit every single day?
1. Hacker News 2. Comic Rocket (tracks new web comics that I haven't read yet, like xkcd, etc.) 3. Local news site
m-ou-se··on Replace a running Debian installation by Arch remotely over ssh
At the start, /dev/xvda2 mounted as /, with Debian installed on it. The goal was to wipe it and install arch on it, all remotely over ssh, since I didn't have access to the console.
m-ou-se··on Whiteboard Clock
Indeed. It's just a udev rule with: SYMLINK+="whiteboard