SBTB 2019: Richard Whaling, A brief introduction to systems programming, with Scala Native

preview_player
Показать описание
With Scala Native's new unsafe API, Scala programmers have access to just as much power as C programmers have had for 50 years. But what does systems programming even look like in a modern language, with Scala's immensely expressive type system? We'll find out as we explore the fundamental concepts of systems programming: pointers, structs, arrays, and strings. As we proceed, we'll see how Scala can provide safer and more ergonomic patterns than C, and compare Scala Native's capabilities to languages like Rust and OCaml. And finally, we'll look at the ways hardware is changing, and the role systems programming (and Scala) can play in defining the patterns and architectures of the future.
Рекомендации по теме
Комментарии
Автор

Hey! I came here, because I'm interested in fast starting, tiny binary programs which I can write in a language I like, like Scala, instead, for example, bash. Using c-libraries is not so much my intent.
I had a small program, 2 files, maybe overengineered, one was an interface, the other one a class file, both written in Java about 10 years ago, less than 150 fluffy, vanilla lines but written, as a replacement for the awk-idiom `foobar DATA | awk {print $3 $2}`, when you want to pick few parameters from an output by position, where `cut` is not useful, because it takes delimiters character wise, which is not always the case. It's just lazyness and a bit of anger, that there is no standard gnu tool I know of, which is more ergonomic to call.
Long story short: The downside of the Java solution is, that it takes 1.5s to start. Once started, the speed is fine for big input, but the input is most of the time small.

So I downloaded scala.native today, translated the Java program in a non canonical way to Scala block- and line wise, and gave it a try. Some excessive work on first compilation, and got an ELF-binary. Tested it, worked like a charm. Measured it, about 0.01s to run!

Well, of course, the size… - about 4 MB. Comparable native programs only take 40kb. I've already seen, that there are options, to reduce the size and maybe I'm somewhat successful in that regard. For using small tools, fast startup time is more important than size, but smaller sizes would be a nice to have.

Big thanks to all, who contributed!

unbekannter_Nutzer