Re: Auto keyword and when to use it

2018-08-21 Thread QueenSvetlana via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 18:44:15 UTC, Jim Balter wrote: Python is not statically typed; D is. Why are you talking about Python? You asked whether D's auto is like C#'s var ... it is, but it doesn't have C#'s pointless restriction of not being allowed for non-local declarations. I think

Re: Auto keyword and when to use it

2018-08-21 Thread QueenSvetlana via Digitalmars-d-learn
On Monday, 20 August 2018 at 17:55:11 UTC, JN wrote: class Foo { auto bar; } because now the compiler doesn't know what type 'bar' is supposed to be. Just to clarify, even if I set bar in the constructor, I can't declare it with auto first, correct? I would have to declare a specific ty

Re: Auto keyword and when to use it

2018-08-21 Thread QueenSvetlana via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 16:15:32 UTC, XavierAP wrote: Only if someone likes "Type x = new Type()" instead of "auto x = new Type()" I would say they're clearly wrong. As you stated it's up to the programmer to decided. I'm in favor of Type x = new Type() because when it comes to construc

Re: Auto keyword and when to use it

2018-08-20 Thread QueenSvetlana via Digitalmars-d-learn
Great! So I can't declare class level variables with auto, correct? only local method variables?

Auto keyword and when to use it

2018-08-20 Thread QueenSvetlana via Digitalmars-d-learn
I'm new to D programming, but have I have a background with Python. I'm struggling to understand what the auto keyword is for and it's appropriate uses. From research, it seems to share the same capabilities as the var keyword in C#. From the C# documentation, it states: https://docs.micros

Are properties mature enough?

2018-08-19 Thread QueenSvetlana via Digitalmars-d-learn
In the D Style Guide, it says: Properties https://dlang.org/dstyle.html#properties Functions should be property functions whenever appropriate. In particular, getters and setters should generally be avoided in favor of property functions. And in general, whereas functions should be verbs, pro

Re: Using .length returns incorrect number of elements

2018-08-19 Thread QueenSvetlana via Digitalmars-d-learn
On Sunday, 19 August 2018 at 15:53:25 UTC, Chris M. wrote: On Sunday, 19 August 2018 at 15:49:18 UTC, Chris M. wrote: On Sunday, 19 August 2018 at 15:44:07 UTC, QueenSvetlana wrote: [...] auto appendNumber = appender(arrayofNumbers); This returns a separate object. You probably meant to put

Using .length returns incorrect number of elements

2018-08-19 Thread QueenSvetlana via Digitalmars-d-learn
When using the .length property of a dynamic array why does it return the incorrect number of elements after I use the appender? import std.stdio; import std.array : appender; void main() { //declaring a dynamic array int [] arrayofNumbers; //append an element using the ~= syntax