digitalmars.D.learn - code formatting issue
- Alexandr Druzhinin (14/14) Oct 02 2013 I'm curious what is the best way to code like this:
- bearophile (8/18) Oct 02 2013 It's often a good idea to use typeof to keep the code more DRY
- Alexandr Druzhinin (15/21) Oct 02 2013 I'm sure keeping the code dry and clean is very good idea, but using
- bearophile (14/15) Oct 02 2013 I meant something more like this, but I don't know how much of an
I'm curious what is the best way to code like this: // request_id zoom x y path url auto msg = receiveOnly!(size_t, zoom, uint, uint, string, string)(); or like this auto msg = receiveOnly!( typeof(request_id), typeof(zoom), typeof(x), typeof(y), typeof(path), typeof(url) )(); Or may be I'm worrying about nonsense and better I'd start thinking about more useful things? :)
Oct 02 2013
Alexandr Druzhinin:auto msg = receiveOnly!( typeof(request_id), typeof(zoom), typeof(x), typeof(y), typeof(path), typeof(url) )(); Or may be I'm worrying about nonsense and better I'd start thinking about more useful things? :)It's often a good idea to use typeof to keep the code more DRY and safer. Another possible solution is to put the variables in some kind of tuple, take its types and use them with a trailing [] to pass them all to receiveOnly. Bye, bearophile
Oct 02 2013
02.10.2013 22:47, bearophile пишет:It's often a good idea to use typeof to keep the code more DRY and safer.I'm sure keeping the code dry and clean is very good idea, but using typeof is rather verbose and just is unusual and verbose a little bit.Another possible solution is to put the variables in some kind of tuple, take its types and use them with a trailing [] to pass them all to receiveOnly. Bye, bearophileSomething like this: alias Tuple!( typeof(request_id), typeof(zoom), typeof(x), typeof(y), typeof(path), typeof(url) ) TileDescription; // wait for tile descripton to process auto msg = receiveOnly!TileDescription(); ? I didn't understand about trailing []
Oct 02 2013
Alexandr Druzhinin:? I didn't understand about trailing []I meant something more like this, but I don't know how much of an improvement this is: import std.typecons, std.typetuple; template Foo(T1, T2) { enum Foo = 1; } void main() { int x; float f; enum y = Foo!(typeof(TypeTuple!(x, f))); } Bye, bearophile
Oct 02 2013