Short overview on D
Bayan Rafeh via Digitalmars-d
digitalmars-d at puremagic.com
Sun Aug 3 03:57:25 PDT 2014
Wow clearly I misunderstood a lot of stuff.
On Sunday, 3 August 2014 at 08:07:04 UTC, Rikki Cattermole wrote:
> On 3/08/2014 7:36 p.m., Bayan Rafeh wrote:
>> A small background on this:
>>
>> I'm a university student about to start my graduation project
>> with two
>> teammates, both of which have a C/Java/Python background and I
>> suggested
>> we use D for our project. They're not familiar with it, so I
>> wrote a
>> short tutorial for them here:
>> https://github.com/bayanr/d-tutorial.
>>
>> I wanted to see what you guys thought, and if this could be a
>> useful
>> introduction for people with similar backgrounds. It's a first
>> draft so
>> it probably has a lot of mistakes, omissions, etc. so any
>> criticism is welcome.
>
> Your introduction to templates is far too simplistic.
> What you introduced was template blocks. But showing them as
> templated classes.
> There is also templated functions, methods ext. After all.
> It may also be wise to introduce CTFE as well. But not so
> important.
That's definitely going in there but I'm just making sure I fix
everything I have so far. If the responses so far are any
indication there is a lot of fixing that needs to be done.
>
> I.e.
>
> class ArrayList(T) {
> T[] l;
> }
>
> alias IntList = ArrayList!int;
> IntList list = new IntList();
>
> would probably be better.
Could you give any suggestions for some example use cases that
can properly demo templates? If not I'll think of some.
> Everything else looks good including mixin templates. But just
> for food for thought. With statements are cool.
I'll be sure to add those as well. I just remembered I forgot to
add scope too.
>
> Hope to hear more of how the project goes.
We're presenting at the end of the next spring semester, I'll be
sure to share it here once it's complete.
> -- Functions --
>
>> Ref implies the type is a reference type, i.e. changes inside
>> the functions will change the variable outside the function.
>> in means immutable out is an alias for ref(preferably used for
>> parameters)
>
> `ref` doesn't "imply" a reference, it "declares" or "states" or
> something.
I'm basing this on the wiki: http://dlang.org/function.html
"ref parameter is passed by reference"
If that is not the case, in practical terms what does that mean
exactly?
> `in` doesn't mean immutable, it means scope const.
> `out` is similar to `ref`, but it's not an alias. Unlike `ref`,
> an out "parameter is initialized upon function entry with the
> default value for its type".
>
Sorry I'll fix those shortly.
> -- Operator Overloading --
>
> The wording suggests that the list of operators is supposed to
> be
> exhaustive. It's not.
>
I intended it to be comprehensive(with regard to types at least).
What am I missing regarding the different types of operators
besides the opAssigns?
>> unitary
>
> unary
>
Ah crap, ok will fix that as well.
> -- Templates --
>
>> Templates are D's response to Java generics and C++ templates.
>
> At least put C++ first if you have to include Java ;)
>
Riots would ensue. To put it lightly we're not fans of C++. Well
we're not exactly fans of Java either :p
>> Basically templates are metaclasses that take types as
>> parameters.
>
> Template parameters are not restricted to types. They can also
> be values or symbols.
>
I guess I need a more exhaustive list of examples.
>> alias List!int.ArrayList IntList;
>
> Maybe use the more fashionable assignment syntax:
> alias IntList = List!int.ArrayList;
>
> -- Arrays --
>
>> a[x..y] is an array containing a[x] all the way to a[y]
>
> To avoid confusion: all the way up to, but not including, a[y].
Will fix that as well.
PS. I applied some of the changes, though I left the stuff that I
need clarification on.
Thank you very much for the comments so far, please keep them
coming.
More information about the Digitalmars-d
mailing list