Re: Recommend: IDE and GUI library
On Saturday, 25 February 2017 at 00:45:24 UTC, Moritz Maxeiner wrote: I use Visual Studio Code on Linux and macOS, not sure how the experience on Windows is, but I'd expect it to be the same. Windows is fine, can also debug mscoff x86 or x64 projects with MS 'cpptools' plugin that has visual studio debugger for C++
Re: Getting nice print of struct for debugging
On Saturday, 25 February 2017 at 01:27:09 UTC, Minty Fresh wrote: On Wednesday, 22 February 2017 at 11:18:15 UTC, Martin Tschierschke wrote: [...] Since structs are Plain-old Data and don't do inheritance, the best option is a template mixin. ie. template mixin PrettyPrint { string toString() { // . . . } } From there, you can mix it into any struct you want. struct MyStruct { mixin PrettyPrint; } If you're familiar with Rails, this is similar to a Concern. Errata on that. Should actually be declared as: mixin template PrettyPrint() This is why I shouldn't make posts from my phone.
Re: Getting nice print of struct for debugging
On Wednesday, 22 February 2017 at 11:18:15 UTC, Martin Tschierschke wrote: On Tuesday, 21 February 2017 at 14:02:54 UTC, Jacob Carlborg wrote: [...] Yes, this works, I would say this is the simplest: MyStruct s; foreach (index, name ; FieldNameTuple!MyStruct) writefln("%s: %s", name, s.tupleof[index]); If you want something more close to "send" in Ruby, you need to use a string mixin, like this: foreach (name ; FieldNameTuple!MyStruct) writefln("%s: %s", name, mixin("s." ~ name)); The string mixin example works for methods, opDispatch and similar as well. The tupleof example, the first one, works only for fields. Exactly what I was looking for, **thank you!** Both ways of accessing the struct elements are very interesting, giving an impression what is possible with D. Is it possible to overwrite "toString" for all structs in one step? Regards mt. Since structs are Plain-old Data and don't do inheritance, the best option is a template mixin. ie. template mixin PrettyPrint { string toString() { // . . . } } From there, you can mix it into any struct you want. struct MyStruct { mixin PrettyPrint; } If you're familiar with Rails, this is similar to a Concern.
Re: Recommend: IDE and GUI library
On Friday, 24 February 2017 at 22:44:55 UTC, XavierAP wrote: Hi I've looked at wiki.dlang.org/IDEs, and I see that Visual D is linked from dlang.org/download.html. Still I was looking for personal opinions and experiences beyond hard specs, I wonder if one of the IDEs is already dominant at least for each OS for any good reason. My requirements are quite ordinary: make x64, debug, go to definition, manage projects, code completion. My platform is Windows; interested if the choice would be different for Linux, if the same nice, otherwise I'd prefer to use whatever is best on each OS. I use Visual Studio Code on Linux and macOS, not sure how the experience on Windows is, but I'd expect it to be the same. With the dlang extension[1], the usual development tools dcd, dfmt, dscanner, dfix (see code.dlang.org for these), and the native debug extension[2] all your requirements are covered. After the setup everything has been working smoothly and I'm very happy with it. The *only* little gripe about it is that Visual Studio Code uses the Electron framework and drains about 10-20% more power than e.g. neovim, though the comparison is apples vs oranges. And second question, is DWT the de facto standard for creating GUIs? Or are there good competitors. AFAIK there is no standard in creating GUIs with D. I suppose if any one of them has what it takes to take that position in the future it'd be dlangui[3], but considering the issue tracker and the manpower available that'll likely still take a while. In the meantime I personally use dqml[4] (QtQuick 2.0 bindings) since I like MVC, and this allows me to write application logic and model in D, visual in QML, and controller in JS (and this also allows me to swap out the application core without changing a single line in the QML or JS). Sorry if I'm asking something too obvious, though I've looked around for answers before. If it's obvious, I missed it myself; I pretty much tried out all the GUI/TUI things on code.dlang.org until I found something I liked. [1] https://github.com/dlang-vscode/dlang-vscode [2] https://github.com/WebFreak001/code-debug [3] https://github.com/buggins/dlangui [4] https://github.com/filcuc/dqml
Recommend: IDE and GUI library
Hi I've looked at wiki.dlang.org/IDEs, and I see that Visual D is linked from dlang.org/download.html. Still I was looking for personal opinions and experiences beyond hard specs, I wonder if one of the IDEs is already dominant at least for each OS for any good reason. My requirements are quite ordinary: make x64, debug, go to definition, manage projects, code completion. My platform is Windows; interested if the choice would be different for Linux, if the same nice, otherwise I'd prefer to use whatever is best on each OS. And second question, is DWT the de facto standard for creating GUIs? Or are there good competitors. Sorry if I'm asking something too obvious, though I've looked around for answers before. And I've also searched the forum but really equivalent questions were over 2 years old and many things may have changed. Thanks!
Re: Serializer class
I'm pretty sure you need to use "value.tupleof[i][0]" instead of "mm[0]" as well. it does not work but I found a solution, that's what I do : abstract class BaseClass { uint[] a = [9, 10, 5]; } override class Test : BaseClass { int t = 0; string s = "holla"; } public static JSONValue Serialize(BaseClass value) { foreach(member; __traits(allMembers, typeof(value))) { static if (__traits(compiles, to!string(__traits(getMember, value, member { auto result = __traits(getMember, value, member); static if(isArray!(typeof(value)) && !is(typeof(value) == string)) { // process } else static if(is(typeof(value) == class) || is(typeof(value) == struct)) { // process } else { // process } } } void main(string[] args) { Serialize(new Test()); } The problem is that I can not retrieve the variables from the parent class.
Re: template parameter inference and introspection
On Friday, 24 February 2017 at 11:17:46 UTC, John Colvin wrote: Unfortunately that only works by accident of my example. A counterexample: T foo(Q = float, T = short)(T t) { return t; } alias Typeof(alias v) = typeof(v); template getInstantiation(alias f, T...) { import std.meta; alias getInstantiation = f!(staticMap!(Typeof, T)); } static assert(is(typeof(foo(3)) == int)); // ok static assert(is(typeof(getInstantiation!(foo, 3)(3)) == int)); // fails This looks like VRP is kicking in when it shouldn't, or maybe it's a different bug. 3 should be typed as int by default unless we explicitly ask for something else.
Re: template parameter inference and introspection
On Friday, 24 February 2017 at 14:06:22 UTC, Meta wrote: On Friday, 24 February 2017 at 11:17:46 UTC, John Colvin wrote: Unfortunately that only works by accident of my example. A counterexample: T foo(Q = float, T = short)(T t) { return t; } alias Typeof(alias v) = typeof(v); template getInstantiation(alias f, T...) { import std.meta; alias getInstantiation = f!(staticMap!(Typeof, T)); } static assert(is(typeof(foo(3)) == int)); // ok static assert(is(typeof(getInstantiation!(foo, 3)(3)) == int)); // fails This looks like VRP is kicking in when it shouldn't, or maybe it's a different bug. 3 should be typed as int by default unless we explicitly ask for something else. VRP propagation is what makes the call possible, but that's a distraction. The problem is that getInstantiation is setting Q to int and leaving T to be it's default type of short, which is not the same as if you just call with an int (which infers T from t and leaves Q as it's default float. Fundamentally, you can't assume the same order of runtime and template arguments.
Re: Debugging D applications from VS code with webfreak.debug
On Friday, 24 February 2017 at 03:15:11 UTC, Jerry wrote: You can use the C++ plugin, which provides a debugger. Just make sure you aren't using optlink, I don't think it generates compatible files. Also you might need to use "-gc" which generates debug names to be in C format. https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools You might also need to enable breakpoints anywhere in VS code user setting file. Awesome! After finding the right combination of flags (-g and -m64 fed to dmd via dflags-dmd in my dub.json) this works quite nicely. Thanks a lot! Is there anywhere I can contribute this as documentation?
Re: Serializer class
On 2017-02-22 20:13, thedeemon wrote: On Wednesday, 22 February 2017 at 18:34:26 UTC, houdoux09 wrote: void Read(T)(T value) { foreach(i, mm; value.tupleof) { writeln(__traits(identifier, value.tupleof[i]), " = ", mm); if(isArray!(typeof(mm))) { Read(mm[0]); //Error } } } You need to use "static if" here inside foreach. Otherwise the body of your "if" gets compiled for all the different fields of "value" and of course fails for the fields that are not arrays. I'm pretty sure you need to use "value.tupleof[i][0]" instead of "mm[0]" as well. -- /Jacob Carlborg
Re: Class Order Style
On 2017-02-20 14:47, Jolly James wrote: How to sort the members of a class? like: 1. properties then 2. private 3. methods 4. ctors ... and so on. are there any recommendations? In my opinion: 1. Manifest constants (enum) 2. Static variables 3. Instance variables 4. Constructors 5. Properties 6. Methods And what is better? class A { private: int a; int b; public: int c; int d; } or class A { private { int a; int b; } public { int c; int d; } } I usually go with "private int a;" if there are four or less fields (static or instance). Otherwise I use the block style (with curly braces). For the methods I use the Java style with the protection attribute attached for each method. Sometimes I put a bunch of internal methods at the end, then I use the label (C++) style. class Foo { enum a = 1; enum b = 2; static int c = 3; static int d = 4; private int e_; private int f_; this(int e, int f) {} static void g(); static void h(); int e() { return e_; } int f() { return f_; } void i(); void j(); private: void k(); void l(); } -- /Jacob Carlborg
Re: template parameter inference and introspection
On Thursday, 23 February 2017 at 18:33:33 UTC, Meta wrote: On Thursday, 23 February 2017 at 18:21:51 UTC, Meta wrote: On Thursday, 23 February 2017 at 16:01:44 UTC, John Colvin wrote: Is there any way to get a reference/alias to the instantiation of a template function that would be called, given certain parameters? I.e. to get the result of whatever template parameter inference (and overload resolution) has occurred? E.g. for some arbitrarily complex foo: static assert(__traits(compiles, foo(3))); alias fooWithInt = someMagic(foo(3)); so if foo was `void foo(T)(T t) {}` then `fooWithInt` would be `foo!int`, but if it was `void foo(Q = float, T = long)(T t)` then `fooWithInt` would be `foo!(float, int)` I don't believe so, because foo(3) is a value (void), not a type like foo!int would be. You can't get it back after you've called the function. You would have to do something like: alias fooWithInt = someMagic!foo(3); Where someMagic constructs the alias to foo!int based on the type of arguments passed, or something like that. A quick and rough example I threw together. Annoyingly, I can't figure out a way to tell the compiler that I want to printout the symbol of fooWithInt, not call it without parens. The best I can do is print out its type. void foo(T)(T t) {} void foo(Q = float, T = long)(T t) {} alias Typeof(alias v) = typeof(v); template getInstantiation(alias f, T...) { import std.meta; alias getInstantiation = f!(staticMap!(Typeof, T)); } alias fooWithInt = getInstantiation!(foo, 3); alias fooWithLong = getInstantiation!(foo, 3L); void main() { pragma(msg, typeof(fooWithInt)); pragma(msg, typeof(fooWithLong)); } Unfortunately that only works by accident of my example. A counterexample: T foo(Q = float, T = short)(T t) { return t; } alias Typeof(alias v) = typeof(v); template getInstantiation(alias f, T...) { import std.meta; alias getInstantiation = f!(staticMap!(Typeof, T)); } static assert(is(typeof(foo(3)) == int)); // ok static assert(is(typeof(getInstantiation!(foo, 3)(3)) == int)); // fails
Re: Getting nice print of struct for debugging
On 2017-02-22 12:18, Martin Tschierschke wrote: Exactly what I was looking for, **thank you!** Both ways of accessing the struct elements are very interesting, giving an impression what is possible with D. Is it possible to overwrite "toString" for all structs in one step? It depends. You can create a template mixin containing the implementation of toString, which need to be mixed in in all structs. Or you can create a new function that can convert any passed in structs in a generic way. It depends on what you need the string for. -- /Jacob Carlborg