D lang & Trash-D

rushsteve1

Created: 2021-08-15 Sun 09:24

Meta Stuff

This talk is in two parts: First I’ll go over the D programming language and some neat parts of it. Then in the second half I’ll go over a command line tool I wrote in D and what’s interesting about that and nice.

doomconf.netlify.app/rushsteve1/trash-d

doomconf.netlify.app/rushsteve1/trash-d.org

The D programming language

dlang.org

A C compatible and optionally garbage-collected systems programming language.

First released in 2001 and continually updated since then.

Basically C++ but better.

dlogo_opengraph.png

Notable Features

  • Actual strings
  • Dynamic arrays and hashmaps
  • Invariants and contract programming
  • Uniform Function Call Syntax (UFCS)
  • Very easy C and C++ interop
  • Lambdas and higher-order functions
  • Unit testing built-in

… and more!

The Standard Library

  • Ranges and lazy iterators
  • SQLite bindings
  • Lots of utility functions
  • Green threads / Continuations
  • CLI options parser

And all the sane normal things that C doesn’t have.

Weird Bits

  • Unicode support is odd (char and dchar)
  • Classes vs Structs
  • It’s a Big language
  • Multiple compilers

Overall not that many funky parts compared to say C++

The Ecosystem

About as dead as it can get without being totally dead.

It’s a real shame, but the language never really took off. However in recent years with renewed interest in systems programming there has been some movement.

Why You Should Care

  • If you’re looking for something…
    • nicer than C/C++
    • less daunting than Rust
    • less spartan than Go
  • If you think systems programming is neat.
  • If you just want to learn a cool language and use some rare language features.

… then give D a try!

What is trash-d

trash-d is a standalone CLI tool that’s almost completely compatible with rm but instead of permanently deleting a file it moves it to the trash bin.

rushsteve1/trash-d

Why Did I Make This?

This is something I’ve wanted for a long time but never got around to making or finding.

One day last week or so @tecosaur was talking about how he accidentally rm -rf’d his music folder, and I made a comment saying that making a version that uses the trash bin should be pretty easy.

It was not.

Why be Compatible With rm?

The entire point of this project was to create a tool that you could alias rm=trash and not even notice the difference, while still gaining all of the benefits of using the trash bin.

This was ultimately quite tricky. rm doesn’t have many flags, but their interaction and exact results required a lot of figuring out.

On top of that I even made the error messages compatible. On the off chance someone’s parsing those…

Why are Versions Missing?

If you check the git history the missing numbers actually exist in code. But they were superseded so fast I never got around to making a release page.

Also I bump the number every time I change something of note, and it’s purely sequential. The first real commit was version 1.

Competitors

As @Sifus pointed out in #programming there already exists a tool called rmtrash. But that’s just a Bash script wrapping around trash-cli.

trash-cli is a big blob of Python code with really weird UX that isn’t rm compatible at all (hence rmtrash).

😎

trash-d on the other hand is a single no-dependency binary that does everything all on it’s own.

Future of the Project

The CLI tool is mostly done. It probably still has some bugs to be squashed and cleanup to be done, but features-wise it’s more or less where I want it.

So some future goals include getting it packaged for various distros, and generally making people aware of its existence.

You have just experience phase 1 of that plan

Brief Code Walkthrough

github.com/rushsteve1/trash-d/blob/main/trash.d

That’s All Folks!

Questions? Comments? Complaints?