"%s"-format template function arguments
Hello people of D-land. In a template function, I want to format all arguments as if it was an array. Se this snippet of code: foo(1,2,3); void foo(T...)(T args) { writefln("expected: %s", [1,2,3]); writefln("actual: %s", args); } The code above will output expected: [1, 2, 3] actual: 1 How would I go on about to print all the arguments as I expected it, using "%s"? Best regards, Vladimirs Nordholm --- P.S. I do not understand why only a `1` is printed in the actual result.
@property get/set or public varaible?
Hello! I have a question not directly related to D as it is with coding standards. My issue at hand is if I have one variable for a class, which I want to be directly accessible for anything else, should it be 1. public, or 2. private, with @property get/setters? From what I have been told is that variables should be private. But if I do not want to make any checks whatsoever when setting a variable, I see no benefit to the private approach. Are there any other reasons to use get/setters?
Re: Access vialotion
On Wednesday, 22 June 2016 at 12:47:31 UTC, TheDGuy wrote: On Wednesday, 22 June 2016 at 12:45:29 UTC, TheDGuy wrote: I have an array of buttons: class Window : MainWindow{ private Button[4] bArr; this(){ Button btn_1 = new Button(); Button btn_2 = new Button(); Button btn_3 = new Button(); Button btn_4 = new Button(); Button[4] bArr = [btn_1,btn_2,btn_3,btn_4]; } private void letButtonsFlash(){ for(int i = 0; i < 4; i++){ writeln(this.bArr[i].getName()); } } } i don't understand why i get an 'Access Violation' - Error in the 'for'-loop? Okay, i solved it, instead of: Button[4] bArr = [btn_1,btn_2,btn_3,btn_4]; this: bArr = [btn_1,btn_2,btn_3,btn_4]; I would also suggest you use a foreach loop to iterate over the buttons: private void letButtonsFlash() { foreach(button; bArr) { writeln(button.getName()); } } //Also, question to anyone: should a ref be used here?