Showing posts with label systems-programming. Show all posts
Showing posts with label systems-programming. Show all posts

Saturday, April 8, 2017

The reference D compiler is now open source (dlang.org)

By Vasudev Ram


Just saw this discussion on HN:

DMD, the reference D compiler is now open source (dlang.org)

It is about this news about the D language:

dmd Backend converted to Boost License

I read part of the discussion, and also commented. As often happens, though the original post is about the change in the licensing of the back=end of the DMD compiler (Digital Mars D), the thread devolved (partly at least) into a discussion of the pros and cons of D versus some other languages, and that kind of thread is often interesting.

Updating the post to add:

- Link to this post on programming.reddit.com about the news:

The Official D Compiler Is Now Free (as in "freedom")

- As user bionsuba says there:

[ bionsuba[S] 30 points 4 hours ago
The front end as been Boost licensed for several years now. But now the backend has been relicensed thanks to Symantec giving their permission.
This has big implications for the language as a whole, as the compiler can now be included in Linux package managers. Meaning, D programs can be distributed on those same package managers. There's also the possibility that DMD can become part of the default packages on a distro! ]

And Andrei Alexandrescu (of Modern C++ Design fame), who now works with Walter Bright on the D language, adds:

[ andralex 16 points 3 hours ago
We will discuss more details and implications of the impact of open sourcing the compiler at DConf in Berlin in May. Registration is open! ]

Update 2 to add:

I'm putting below, an Ask HN thread that I had started some months ago. It got some interesting replies:

Ask HN: What are you using D (language) for?

The replies give some examples of non-trivial things that D can be used for.

Update 3 to add:

As Walter Bright say here, it's the #1 story on HN at the moment (and for a while now).

- Vasudev Ram - Online Python training and consulting

Get updates (via Gumroad) on my forthcoming apps and content.

Jump to posts: Python * DLang * xtopdf

Subscribe to my blog by email

My ActiveState Code recipes

Follow me on: LinkedIn * Twitter

Are you a blogger with some traffic? Get Convertkit:

Email marketing for professional bloggers



Tuesday, December 20, 2016

Simple parallel processing in D with std.parallelism

By Vasudev Ram



Phobos image attribution

The D language has a module for parallel processing support. It is in Phobos, D's standard library (guess why it is called Phobos :). [1]
The module is called std.parallelism.

From the Phobos page:

[ Generally, the std namespace is used for the main modules in the Phobos standard library. The etc namespace is used for external C/C++ library bindings. The core namespace is used for low-level D runtime functions. ]

Here are a couple of simple D programs that together show the speedup that can be obtained by using the parallelism module. Note that this is for tasks that involve the CPU, not I/O.

The first one, student_work_sequential.d, does not use the std.parallelism module, so it does 4 tasks sequentially, i.e. one after another.

The second one, student_work_parallel.d, does use it. It does the same 4 tasks as the first. But it uses the convenience function called parallel from std.parallelism, to run the 4 tasks in parallel.
I timed the results of running each program a few times, and the parallel one was consistently over 3 times faster than the sequential one.

Each of the D programs below can be compiled with the command:
dmd program_name.d
Here is the code for student_work_sequential.d:
/*
student_work_sequential.d
Author: Vasudev Ram
Copyright 2016 Vasudev Ram
Web site: https://vasudevram.github.io
Blog: http://jugad2.blogspot.com
Product Store: https://gumroad.com/vasudevram
Twitter: https://mobile.twitter.com/vasudevram
*/

import std.stdio;
import core.thread;

struct Student {
    int number;
    void doSlowOperation() {
        writefln("The work of student %s has begun", number);
        // Wait for a while to simulate a long-lasting operation
        Thread.sleep(1.seconds);
        writefln("The work of student %s has ended", number);
    }
}

void main() {
    auto students =
        [ Student(1), Student(2), Student(3), Student(4) ];
    foreach (student; students) {
        student.doSlowOperation();
    }
}
Here is the output from running it, under the control of a command timing program written in Python:
$ python c:\util\time_command.py student_work_sequential
The work of student 1 has begun
The work of student 1 has ended
The work of student 2 has begun
The work of student 2 has ended
The work of student 3 has begun
The work of student 3 has ended
The work of student 4 has begun
The work of student 4 has ended
Command: student_work_sequential
Time taken: 4.07 seconds
Return code: 0

And here is the code for student_work_parallel.d:
/*
student_work_parallel.d
Author: Vasudev Ram
Copyright 2016 Vasudev Ram
Web site: https://vasudevram.github.io
Blog: http://jugad2.blogspot.com
Product Store: https://gumroad.com/vasudevram
Twitter: https://mobile.twitter.com/vasudevram
*/

import std.stdio;
import core.thread;
import std.parallelism;

struct Student {
    int number;
    void doSlowOperation() {
        writefln("The work of student %s has begun", number);
        // Wait for a while to simulate a long-lasting operation
        Thread.sleep(1.seconds);
        writefln("The work of student %s has ended", number);
    }
}

void main() {
    auto students =
        [ Student(1), Student(2), Student(3), Student(4) ];
    foreach (student; parallel(students)) {
        student.doSlowOperation();
    }
}
Here is the output from running it, under the control of the same command timing program:
$ python c:\util\time_command.py student_work_parallel
The work of student 1 has begun
The work of student 2 has begun
The work of student 3 has begun
The work of student 4 has begun
The work of student 1 has ended
The work of student 2 has ended
The work of student 3 has ended
The work of student 4 has ended
Command: student_work_parallel
Time taken: 1.09 seconds
Return code: 0
We can see that the parallel version runs 3 times faster than the sequential one. And though there was some fluctuation in the exact ratio, it was in this range (3:1) over the half-dozen tests that I ran.

Not bad, considering that the only differences between the two programs is that the parallel one imports std.parallelism and uses this line:
foreach (student; parallel(students)) {
instead of this one used by the sequential program:
foreach (student; students) {
Also, messages about tasks started later in the sequence, appear before earlier tasks have ended, which shows that things are running in parallel, in the second program.

So (as the docs say) the parallel function from std.parallelism is a convenient high-level wrapper for some of the lower-level functionality of the parallelism module, and may suffice for some parallel processing use cases, without needing to do anything more. That is useful.

[1] The D standard library is called Phobos because Phobos is a moon of Mars (and hence a satellite of it. And Mars was the original name of the D language, given by its creator, Walter Bright (his company is/was called Digital Mars). But he says that many of his friends started calling it D (as it was like a better C), so he did too, and changed the name to D. So, Phobos (the library) is a "satellite" of D, a.k.a. Mars (the language) :) You can read an interview of Walter Bright (on the D blog) via this post:

Interview: Ruminations on D: Walter Bright, DLang creator

The post also has an HN thread about the interview. It also links to a video about D and other systems programming languages.

The Wikipedia article on Phobos is interesting. It says that the 'orbital motion of Phobos has been intensively studied, making it "the best studied natural satellite in the Solar System" in terms of orbits completed'. It also says where the name Phobos came from (a Greek god), and the source of the names of geographical features on Phobos (the book Gulliver's Travels). Also, Phobos has very low gravity (not even enough to keep it round in shape), so low that:

"A 68 kg (150 lb) person standing on the surface of Phobos would weigh the equivalent to about 60 g (2 oz) on Earth.[29]"

Maybe that is why the astronomers named some of the places on Phobos after Gulliver's Travels - because of Lilliput :)

The image at the top of the post is of Phobos and Deimos orbiting Mars.

- Vasudev Ram - Online Python training and consulting

Get updates on my software products / ebooks / courses.

Jump to posts: Python   DLang   xtopdf

Subscribe to my blog by email

My ActiveState recipes

FlyWheel - Managed WordPress Hosting



Wednesday, August 31, 2016

Interview: Ruminations on D: Walter Bright, DLang creator


By Vasudev Ram

I read this interview yesterday:

Ruminations on D: An Interview with Walter Bright (creator of the D programming language).

(Walter Bright (Wikipedia))

The interview also links to this talk between Walter and Andrei Alexandrescu, of Modern C++ fame, who joined Walter to work on D (after working at Facebook for some time)) about a D project, warp (a C++ preprocessor), that Walter did for Facebook; the talk is about the D benefits Walter found while working on the project (such as the ease of changing the data structures to try different approaches, and how the ranges and the algorithms that operate upon them are somewhat decoupled).

(Andrei Alexandrescu (Wikipedia))

HN thread about the interview.

You can also check out this video, about the creators or key team members of 4 languages, C++, D, Golang and Rust, talking at LangNext '14:

Video: C++, Rust, D and Go: Panel at LangNext '14

- Vasudev Ram - Online Python training and consulting

Get updates on my software products / ebooks / courses.

Jump to posts: Python   DLang   xtopdf

Subscribe to my blog by email

My ActiveState recipes




Friday, August 5, 2016

The D Language Playground site

By Vasudev Ram


The D language playground site:


is a web site (created somewhat recently, IIRC), where you can write or paste in a chunk of D code into a text box, click Run, and it will run it on their server, and send back the results to be displayed. It also has a tour of the language, and you can go from one example to another, and just run, or modify and run, each of them. So the same site serves both as an online sandbox to experiment with D language snippets, and as an interactive tutorial for D. In both these ways it is similar to the Go language playground/tour site. Either or both are worth checking out, if you are interested in those languages.

- Vasudev Ram - Online Python training and consulting




My Python posts     Subscribe to my blog by email

My ActiveState recipes



Monday, August 1, 2016

Video: C++, Rust, D and Go: Panel at LangNext '14

By Vasudev Ram

I recently came across this video of a panel discussion (in 2014) on modern systems programming languages. Yes, I know the term is controversial. Andrei and Rob say something about it. See the video.

The languages discussed are: C++, D, Go and Rust, by a panel at LangNext '14.

The panel consisted of key team members from the teams working on those languages:

- Bjarne Stroustrup for C++
- Andrei Alexandrescu for D
- Rob Pike for Go
- Niko Matsakis for Rust

(that's by language name in alphabetical order :)

Here is the video embedded below, and a link to it in case the embed does not work for you (sometimes happens).



I have only watched part of it so far (it is somewhat long), but found it interesting.

You can also download it with youtube-dl (written in Python, BTW) or some other video downloading tool, for watching offline. It's about 1.34 GB in size, so plan accordingly.

- Enjoy.

- Vasudev Ram - Online Python training and consulting
Follow me on Gumroad for product updates:



My Python posts     Subscribe to my blog by email

My ActiveState recipes



Tuesday, January 29, 2013

BareMetalOS, x86-64 OS in assembly language

Return Infinity - BareMetal OS

It is being written purely in assembly language, with plans to let apps for it be written in assembly or C.

Programming in assembly language is interesting and fun, because you work very close to the actual hardware, dealing with registers, memory locations, addressing modes, bit manipulation, etc.

I've only done a little of it, much earlier, on the  Commodore-64, the BBC Micro, and PCs running DOS, but enjoyed it.

I once bought a book that had the entire listing for a C-64 assembler, written in BASIC, using POKE, and entered it into the machine, including re-entering a large part of it due to finding bugs, probably due to typos while entering the hex codes. IIRC, it took me the better part of a week to complete that job and get a running assembler, but it worked :)

Friday, October 12, 2012

The Go language FAQ is interesting

By Vasudev Ram


Start reading it here: Origins of Go.

- Vasudev Ram - Dancing Bison Enterprises


Go by example: Online set of Go language examples

By Vasudev Ram


Go by example is a recently started site. It has examples for various topics in the Go programming language (often called golang), which was created by Google a few years ago, and is currently getting a good amount of interest among programmers.

Article by Mark McGranaghan introducing Go by example.

Twitter account for Go by example.

Hacker News post announcing Go by example.

For background: Go language on Wikipedia.

- Vasudev Ram - Dancing Bison Enterprises