Developers Club geek daily blog

[Transfer] Associative arrays in language D

1 year, 1 month ago
It is transfer of the article "Associative arrays" published on January 1, 2016. On my taste article is a little excessively superficial and does not contain a large number of details, but it can be useful that who is familiar with associative arrays in other programming languages.

In language D there is a built-in support of the associative arrays also known as a hash table.
They are similar Map in Java or std::unordered_map in C ++.

Declaration of associative array



To declare associative array, use the following syntax:

// Прим. перев.: value — тип значения, key — тип ключа
value[key] myAssociativeArray;


Read more »


It is a little sugar in combination theory

1 year, 1 month ago
Hello, habr!

Each programmer respecting himself knows that deep enclosure — bad style. But there are algorithms which are implemented by the cascade of nested loops (3 and more). In this article I want to tell how it is possible to cope with a problem of nested loops at search of combinations in favourite language D.

Read more »


[Transfer] Work with files in a programming language D

1 year, 3 months ago
It is transfer of article of Gary Uilloubi (Gary Willoughby) of "Working with files in the D programming language" published on September 28, 2015.

On this post I was inspired by article written a few weeks ago and the entitled Work with files in Go (article in English — a comment perev.). In this article the author describes a set of methods of interaction with files, in detail stopping on features of the Go language. And I thought to write the accompanying post, this time having described how to work with files in language D.

Interaction some problems in language D are how exactly solved with files — one of fundamental problems of any programming language and though a solution of such tasks — the everyday occurrence, can be not always obvious. I hope, this article will show simplicity and power of language D during the work with files.

In some of the code samples given below so-called uniform syntax of a challenge of functions is used (Uniform Function Call Syntax, UFCS). Let it do not confuse you: his simple explanation can be found here (so far too English — a comment perev.).

Read more »


Compile-time reflection of D, practice

1 year, 7 months ago
Hello, habr!

In last article Basic Elements of compile-time of reflection, those bricks of which build the "real" metaconstructions have been considered. I want to show some such receptions in this article. Let's try to implement signals and slots, similar that in Qt, will be approximately so:
class Foo : XObject
{
    @&8203;signal
    void message( string str );
}
class Bar : XObject
{
    @&8203;slot
    void print( string str ) { writefln( "Bar.print: %s", str ); }
}
void main()
{
    auto a = new Foo, b = new Bar;
    connect( a.message, b.print );
    a.message( "hello habr" ); // Bar.print: hello habr
}

Carefully: it is a lot of code (with comments).

Read more »


Compile-time reflection of D

1 year, 7 months ago
Hello, habr!

Today we will talk that does metaprogramming in the D such flexible and powerful — reflection compile-time. D allows the programmer to use directly information with which the compiler operates, but not to output it in the cunning ways. So what information the compiler and how it can be used allows to receive?

Read more »


D for beginners, part 2

1 year, 8 months ago
Hello, habr!

Let's continue subject of the previous article. There will be explanation of such concepts, as @ ​safe, @ ​trusted, pure, nothrow, some moments concerning OOP.

Read more »


D for beginners, part 1

1 year, 8 months ago
Hello, habr!

Already rather adult language, and in network is not enough material in Russian. It is necessary to meet lack. In this note I want to tell about rather boring, but very important subject of modifiers, attributes and to that similar. Their abundance in D can frighten off people who only start getting acquainted with language. And not everything who uses language has complete idea. But not everything is so terrible, it is not more difficult than at others)

Read more »


Contracts in D

1 year, 8 months ago
Hello, habr!

Today I want to tell you about contract programming and its implementation in D. It is very interesting concept of creation of API. The sense consists in the formal specification of work of function or class at the level of code, but not the comment.

Example of the similar specification for function:

Read more »


Management and cleaning in D

1 year, 8 months ago
Hello, habr!

All of us know that in D the garbage collector is used. It manages memory allocation. It is used by implementations of such built-in types as associative and dynamic arrays, lines (that too arrays), exceptions, delegates. Also its use vtroyenno in language syntax (concatenation, the operator new). GC relieves responsibility and loading from the programmer, allows to write more compact, clear and safe code. And it is, perhaps, the most important pluses of a garbage collector. Whether it is worth refusing it? Payment for use of the collector will be an excess expenditure of memory that is inadmissible at strongly limited resources and pauses of all flows (stop-the-world) on assembly per se. If these points for you are critical welcome under kat.

Read more »


Python and D

1 year, 8 months ago
Hello, habr!

Here we will not argue on pluses and minuses of languages.



We will use them together!


Read more »