www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Things to look up in the docs

reply bearophile <bearophileHUGS lycos.com> writes:
In a language like C/D1 there are common simple parts that's easy to remember,
like:
int x = 10;

Other parts are more complex, but they are common enough that you usually
remember them:
for (int x = 10; x < foo.bar(); x += 2) {}

Other parts of the language or its standard library are less easy to remember,
but in normal programs they are uncommon enough that looking them into the docs
is acceptable. You don't need to keep in memory all the standard library of
Java or C# to use such languages.

But in a language (like D1/D2) there can be parts that are both common enough
and hard enough to remember, those are a problem, because looking in the docs
each time is a waste of programming time (especially if you don't have an IDE
under your hands) and more. Realistically it may be impossible to remove or
simplify all such parts from a large system language as D1/D2, but it's
important to write down a list of such parts, to keep such list in memory
during the language design, and to try to minimize the length of such list. In
theory some of the things in such list can be modified to make them more easy
to remember, etc.

It's nice to program in Python also because most common parts of the language
are easy to remember, for example the are't one undred string/list methods as
in Ruby, so after few months you memorize the most common Python string
methods, and this helps speed up programming significantly. 

What are the parts of the D1/D2 languages that are both common enough in
programs and not easy to remember, so you need to look them often in the docs
(or in an example list, code snippets list, already written code, etc)? This
list is partially subjective, but probably there are also some common trends.

For example the syntax of opApply is one of the things I have often to look up
in the docs (while I never need the manual to remember how to write a generator
in Python, that has very similar purposes).

Do you have other parts to add to this list?

Bye,
bearophile
Jan 01 2010
next sibling parent reply Don <nospam nospam.com> writes:
bearophile wrote:
 What are the parts of the D1/D2 languages that are both common enough in
programs and not easy to remember, so you need to look them often in the docs
(or in an example list, code snippets list, already written code, etc)? This
list is partially subjective, but probably there are also some common trends.
 
 For example the syntax of opApply is one of the things I have often to look up
in the docs (while I never need the manual to remember how to write a generator
in Python, that has very similar purposes).
 
 Do you have other parts to add to this list?
 
 Bye,
 bearophile

is() expressions.
Jan 01 2010
next sibling parent reply "Simen kjaeraas" <simen.kjaras gmail.com> writes:
On Fri, 01 Jan 2010 11:01:07 +0100, Don <nospam nospam.com> wrote:

 bearophile wrote:
 What are the parts of the D1/D2 languages that are both common enough  
 in programs and not easy to remember, so you need to look them often in  
 the docs (or in an example list, code snippets list, already written  
 code, etc)? This list is partially subjective, but probably there are  
 also some common trends.
  For example the syntax of opApply is one of the things I have often to  
 look up in the docs (while I never need the manual to remember how to  
 write a generator in Python, that has very similar purposes).
  Do you have other parts to add to this list?
  Bye,
 bearophile

is() expressions.

Seconded. Often I end up using is( typeof( { something } ) ) because it's faster than looking up and understanding how to write the equivalent isExpression. Yet, I don't have much of an idea of how to make it better. Is there a DIP for this? -- Simen
Jan 01 2010
parent bearophile <bearophileHUGS lycos.com> writes:
Simen kjaeraas:
 Seconded. Often I end up using is( typeof( { something } ) ) because
 it's faster than looking up and understanding how to write the
 equivalent isExpression. Yet, I don't have much of an idea of how
 to make it better. Is there a DIP for this?

I think is() has to be split in different things with a different (more intuitive) syntax/naming. Bye, bearophile
Jan 01 2010
prev sibling next sibling parent "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> writes:
Don wrote:
 bearophile wrote:
 What are the parts of the D1/D2 languages that are both common enough 
 in programs and not easy to remember, so you need to look them often 
 in the docs (or in an example list, code snippets list, already 
 written code, etc)? This list is partially subjective, but probably 
 there are also some common trends.

 For example the syntax of opApply is one of the things I have often to 
 look up in the docs (while I never need the manual to remember how to 
 write a generator in Python, that has very similar purposes).

 Do you have other parts to add to this list?

 Bye,
 bearophile

is() expressions.

...and template parameter specialisations, which are somewhat related since they use some of the same syntax. // Does T end up being the array or element type here? template Foo(T: T[]) { ... } // How many template parameters do I have to specify when // instantiating this template? template Bar(T: U*, U: int) { ... } -Lars
Jan 01 2010
prev sibling next sibling parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
--0015175d0a4c7932d5047c35814f
Content-Type: text/plain; charset=ISO-8859-1

On Fri, Jan 1, 2010 at 17:26, Lars T. Kyllingstad
<public kyllingen.nospamnet> wrote:

  // Does T end up being the array or element type here?
  template Foo(T: T[]) { ... }

everywhere: template Foo(T) if isDynamicArray!T { alias ElementType!T E; }
// How many template parameters do I have to specify when
// instantiating this template?
 template Bar(T: U*, U: int) { ... }

And is it the same than template Bar(U: int, T: U*) {...}? Some others of the same kind: why, to test if type U is a composite type (Cycle!(T), for example), do I have to write is(U u == Cycle!T, T) and not is(U == Cycle!T, T)? (If I'm not mistaken). And to detect if some type is a std.typcons.tuple with is(T t = Tuple!U, U...) doesn't work, because the is() doesn't accept variadic template arguments. Too bad. --0015175d0a4c7932d5047c35814f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On Fri, Jan 1, 2010 at 17:26, Lars T. Kyllingsta= d <span dir=3D"ltr">&lt;public kyllingen.nospamnet&gt;</span> wrote:<br><bl= ockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, 204= , 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> <div><div></div>=A0// Does T end up being the array or element type here?<b= r></div> =A0template Foo(T: T[]) { ... }<br>=A0 <br></blockquote><div>Yeah, me too. So I end up putting external constrain= ts and static ifs everywhere:<br><br>template Foo(T) if isDynamicArray!T {<= br>=A0=A0=A0 alias ElementType!T E;<br>}<br><br>&gt;// How many template pa= rameters do I have to specify when<br> &gt;// instantiating this template?<br>&gt; template Bar(T: U*, U: int) { .= .. <font color=3D"#888888">}</font><br> <br>And is it the same than template Bar(U: int, T: U*) {...}?<br><br>Some = others of the same kind:<br><br>why, to test if type U is a composite type = (Cycle!(T), for example), do I have to write <br>is(U u =3D=3D Cycle!T, T) = <br> and not <br>is(U =3D=3D Cycle!T, T)? (If I&#39;m not mistaken).<br>And to d= etect if some type is a std.typcons.tuple with <br>=A0is(T t =3D Tuple!U, U= ...) <br>doesn&#39;t work, because the is() doesn&#39;t accept variadic tem= plate arguments. Too bad.<br> <br><br><br><br><br><br><br><br></div></div> --0015175d0a4c7932d5047c35814f--
Jan 02 2010
prev sibling parent retard <re tard.com.invalid> writes:
Fri, 01 Jan 2010 15:45:42 +0100, Simen kjaeraas wrote:

 On Fri, 01 Jan 2010 11:01:07 +0100, Don <nospam nospam.com> wrote:
 
 bearophile wrote:
 What are the parts of the D1/D2 languages that are both common enough
 in programs and not easy to remember, so you need to look them often
 in the docs (or in an example list, code snippets list, already
 written code, etc)? This list is partially subjective, but probably
 there are also some common trends.
  For example the syntax of opApply is one of the things I have often
  to
 look up in the docs (while I never need the manual to remember how to
 write a generator in Python, that has very similar purposes).
  Do you have other parts to add to this list? Bye,
 bearophile

is() expressions.

Seconded. Often I end up using is( typeof( { something } ) ) because it's faster than looking up and understanding how to write the equivalent isExpression. Yet, I don't have much of an idea of how to make it better. Is there a DIP for this?

It's funny how many of the original ideas in D (e.g. is()) feel so irrational and kludgy that at least I try to avoid them at all costs or at least build some wrappers around them.
Jan 04 2010
prev sibling next sibling parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
--00151758a4c480107b047c35240a
Content-Type: text/plain; charset=ISO-8859-1

On Fri, Jan 1, 2010 at 09:12, bearophile <bearophileHUGS lycos.com> wrote:


 What are the parts of the D1/D2 languages that are both common enough in
 programs and not easy to remember, so you need to look them often in the
 docs (or in an example list, code snippets list, already written code, etc)?
 This list is partially subjective, but probably there are also some common
 trends.

- variadic functions. I can't for the life of me remember if it's foo(...) foo(a...) foo(a, ...) and I always forget there is also foo(int[] a ...). Quick, what's the difference with foo(int[] a) ? And when I look at them in the docs, I'm, like "OMG, *void!". So I end up writing foo(T...)(T args) and all is for the best: I got the types, I got the length, I can static-if-act on them, I can put guards and I can even recurse on them! void foo(T...)(T args) { writeln(args); static if (T.length) foo(args[1..$]); } - mixin. I have template Foo(T, U). In my code, should I write: Foo!(int, double); mixin Foo!(int, double); mixin( Foo!(int, double)); When I discovered D some time ago, that was something that stalled me :( Philippe --00151758a4c480107b047c35240a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <br><br><div class=3D"gmail_quote">On Fri, Jan 1, 2010 at 09:12, bearophile= <span dir=3D"ltr">&lt;<a href=3D"mailto:bearophileHUGS lycos.com">bearophi= leHUGS lycos.com</a>&gt;</span> wrote:<br><div>=A0</div><blockquote class= =3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, 204, 204); margin= : 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> What are the parts of the D1/D2 languages that are both common enough in pr= ograms and not easy to remember, so you need to look them often in the docs= (or in an example list, code snippets list, already written code, etc)? Th= is list is partially subjective, but probably there are also some common tr= ends.<br> </blockquote><div><br>- variadic functions. I can&#39;t for the life of me = remember if it&#39;s <br>foo(...) <br>foo(a...)<br>foo(a, ...)<br>and I alw= ays forget there is also foo(int[] a ...). Quick, what&#39;s the difference= with foo(int[] a) ?<br> And when I look at them in the docs, I&#39;m, like &quot;OMG, *void!&quot;.= <br>So I end up writing foo(T...)(T args) and all is for the best: I got th= e types, I got the length, I can static-if-act on them, I can put guards an= d I can even recurse on them!<br> <br>void foo(T...)(T args)<br>{<br>=A0=A0=A0 writeln(args);<br>=A0=A0=A0 st= atic if (T.length)<br>=A0=A0=A0=A0=A0=A0=A0 foo(args[1..$]);<br>}<br><br>- = mixin. I have template Foo(T, U). In my code, should I write:<br>Foo!(int, = double);<br>mixin Foo!(int, double);<br> mixin( Foo!(int, double));<br><br>When I discovered D some time ago, that w= as something that stalled me :(<br><br><br>Philippe<br></div></div> --00151758a4c480107b047c35240a--
Jan 02 2010
prev sibling parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Philippe Sigaud <philippe.sigaud gmail.com> wrote:

 - mixin. I have template Foo(T, U). In my code, should I write:
 Foo!(int, double);
 mixin Foo!(int, double);
 mixin( Foo!(int, double));

I feel there should be 'mixin templates', which require no 'mixin' prefix at the instantiation site. See bug #3666 (http://d.puremagic.com/issues/show_bug.cgi?id=3666), -- Simen
Jan 02 2010