5 ms·
D is a great language. I just found out today about a feature called "Uniform Function Call Syntax" which acts similarly to extension methods in C#. Essentially
by mostly_harmless 13y ago
D is a great language. I just found out today about a feature called "Uniform Function Call Syntax" which acts similarly to extension methods in C#. Essentially, you can call any function with a prototype of:
func(T, ...)
as
t.func(...)
where t is an instance of some type T. This may seem trivial, but it allows for functions to be added to a class or type which is out of your control.
For example, the function to convert a 'string' to a C-style zero terminated string is:
toStringz(string s).
calling the function as s.toStringz() has a much more natural feel, and allows for a much more modular approach than "throw everything in the class", since it can just simply be added on as a uniform function in another module (toStringz is a library feature on the concrete string type). This even works on basic types:
(5.0).sqrt();
!!