Jump to page: 1 2
Thread overview
D Tutorials
Mar 17, 2005
J C Calvarese
Mar 17, 2005
Joey Peters
Mar 17, 2005
AEon
Mar 17, 2005
J C Calvarese
Mar 17, 2005
Derek Parnell
Mar 17, 2005
Joey Peters
Mar 17, 2005
J C Calvarese
Mar 17, 2005
AEon
Mar 17, 2005
J C Calvarese
Mar 17, 2005
Brad Anderson
Mar 17, 2005
J C Calvarese
Trac Syntax Highlighting (was Re: D Tutorials)
Mar 19, 2005
J C Calvarese
Mar 19, 2005
Brad Anderson
Mar 19, 2005
J C Calvarese
Mar 17, 2005
AEon
March 17, 2005
Before someone has a chance to ask, I figured I'd provide some helpful links...


*The nexus of D tutorials*
http://www.prowiki.org/wiki4d/wiki.cgi?D__Tutorial

There are some subpages with help for beginners, but it's not much. Yet. I plan to add some more subpages, but I haven't gotten around to it yet. Hopefully, I'll find some time for it in the next couple months. If someone else gets tired of waiting for me, please be my guest. Don't let me stop you. ;)


*dsource tutorials*
Example database: http://www.dsource.org/tutorials/
Forum:            http://www.dsource.org/forums/viewforum.php?f=3

I (mostly) wrote the PHP that runs the tutorial section at dsource. If you have an idea for a new feature, I'm the one to whom you should mention it. I've written some of the examples, but many have been submitted by others or culled from the D newsgroups.

The best way to get my attention regarding a tutorial issue is probably either by posting in the tutorials forum or by sending me a PM (I'm "jcc7") through the dsource forums. In the case that you find a problem with an existing example, Brad and I are the only ones who can edit it. So just let me know, and I'll fix it.

-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/
March 17, 2005
 I'm interested in writing some tutorials, just to review my current D
skills. I've been using D for a few months now, I should be able to write a
few beginner tutorials.
Oh, just as a little side question; do you know what exactly the
in/out/inout parameter options mean? I find the reference explanation a bit
confusing.


"J C Calvarese" <jcc7@cox.net> schreef in bericht news:d1aob8$2kq9$1@digitaldaemon.com...
> Before someone has a chance to ask, I figured I'd provide some helpful links...
>
>
> *The nexus of D tutorials* http://www.prowiki.org/wiki4d/wiki.cgi?D__Tutorial
>
> There are some subpages with help for beginners, but it's not much. Yet. I plan to add some more subpages, but I haven't gotten around to it yet. Hopefully, I'll find some time for it in the next couple months. If someone else gets tired of waiting for me, please be my guest. Don't let me stop you. ;)
>
>
> *dsource tutorials*
> Example database: http://www.dsource.org/tutorials/
> Forum:            http://www.dsource.org/forums/viewforum.php?f=3
>
> I (mostly) wrote the PHP that runs the tutorial section at dsource. If you have an idea for a new feature, I'm the one to whom you should mention it. I've written some of the examples, but many have been submitted by others or culled from the D newsgroups.
>
> The best way to get my attention regarding a tutorial issue is probably either by posting in the tutorials forum or by sending me a PM (I'm "jcc7") through the dsource forums. In the case that you find a problem with an existing example, Brad and I are the only ones who can edit it. So just let me know, and I'll fix it.
>
> -- 
> Justin (a/k/a jcc7)
> http://jcc_7.tripod.com/d/


March 17, 2005
"J C Calvarese" <jcc7@cox.net>,

Just had a quick look at teh turorials. Very nice.

in

http://www.dsource.org/tutorials/index.php?show_example=26

I was a bit surprised that

<code>
void main()
{
printf("Hi");
}
</code>

actually works with dmd. I would have guessed it requires

<code>
import std.c.stdio;

void main()
{
printf("Hi\n");
}
</code>

an import and a \n. But the example works without these. Strange.

AEon
March 17, 2005
On Thu, 17 Mar 2005 10:59:59 +0100, Joey Peters wrote:



> Oh, just as a little side question; do you know what exactly the in/out/inout parameter options mean? I find the reference explanation a bit confusing.
On Thu, 17 Mar 2005 10:59:59 +0100, Joey Peters wrote:

> Oh, just as a little side question; do you know what exactly the in/out/inout parameter options mean? I find the reference explanation a bit confusing.

'in' parameters have their value preserved. That is, after calling a routine, the value of an 'in' parameter will not be changed after the routine has returned. The routine can change the value but when the routine returns, the value is restored to whatever it was when the routine was called. There is on tricky part though. Class instances and arrays are passed by reference. That means that a pointer to the data is passed to the array, and in this case an 'in' parameter just means that the pointer value is preserved *and* not the values in the class or array.

Example of 'in':

   import std.stdio;
   void Foo(in char[] x)
   {
       writefln("Foo Before '%s' %d", x, x.length);
       if (x.length == 0)
         x ~= 'A';
       else
         x[0] = 'A';
       x = "xyzzy";
       writefln("Foo After  '%s' %d", x, x.length);
   }
   void main()
   {
     char[] Test = "abcdef";

     writefln("Main Before '%s' %d", Test, Test.length);
     Foo(Test);
     writefln("Main After  '%s' %d", Test, Test.length);
  }
  ---------------------------
  Main Before 'abcdef' 6
  Foo Before 'abcdef' 6
  Foo After  'xyzzy' 5
  Main After  'Abcdef' 6
  ------------------------

'out' parameters are initialized by D to whatever their .init property is at the point they are passed to the routine. The routine may change the values in 'out' parameters and the changes remain after the routine returns.

Example of 'out':

   import std.stdio;
   void Foo(out char[] x)
   {
       writefln("Foo Before '%s' %d", x, x.length);
       if (x.length == 0)
         x ~= 'A';
       else
         x[0] = 'A';
       x = "xyzzy";
       writefln("Foo After  '%s' %d", x, x.length);
   }
   void main()
   {
     char[] Test = "abcdef";

     writefln("Main Before '%s' %d", Test, Test.length);
     Foo(Test);
     writefln("Main After  '%s' %d", Test, Test.length);
  }
---------------------------------
  Main Before 'abcdef' 6
  Foo Before '' 0
  Foo After  'xyzzy' 5
  Main After  'xyzzy' 5
---------------------------------

'inout' parameters are identical to 'out' parameters except that they are *not* initialized by D. The enter the routine with what ever value was in them when passed to the routine.

Example of 'inout':
   import std.stdio;
   void Foo(inout char[] x)
   {
       writefln("Foo Before '%s' %d", x, x.length);
       if (x.length == 0)
         x ~= 'A';
       else
         x[0] = 'A';
       x = "xyzzy";
       writefln("Foo After  '%s' %d", x, x.length);
   }
   void main()
   {
     char[] Test = "abcdef";

     writefln("Main Before '%s' %d", Test, Test.length);
     Foo(Test);
     writefln("Main After  '%s' %d", Test, Test.length);
  }
---------------------------------
  Main Before 'abcdef' 6
  Foo Before 'abcdef' 6
  Foo After  'xyzzy' 5
  Main After  'xyzzy' 5
---------------------------------

-- 
Derek Parnell
Melbourne, Australia
17/03/2005 9:34:49 PM
March 17, 2005
In article J C Calvarese says...

>*dsource tutorials*
>Example database: http://www.dsource.org/tutorials/
>Forum:            http://www.dsource.org/forums/viewforum.php?f=3
>
>I (mostly) wrote the PHP that runs the tutorial section at dsource. If you have an idea for a new feature, I'm the one to whom you should mention it.

A few ideas:

Example thread: http://www.dsource.org/tutorials/index.php?show_example=68

On the "Add an example" link page
(http://www.dsource.org/tutorials/index.php?add_example=1)


- It would be nice if the category section would "inherit" the category from which you clicked that link. In the above case it would be "Fundamentals".


- To avoid inadvertent "mess ups" it could be nice to have a drop-down list of the valid "Category:"s. AFAICT those are 3 presently? Fundamentals, Intermediate, Advanced.


- Under the "Submit" button, it would really be nice to have a "Preview" button, because AFAICT there is no way to edit posts to correct layout bugs etc.

IMO this would be one of the most important additions, since nice formatting greatly improves readability + understanding of code.


- In the thread above I noted the source code is automatically highlighted? I have put together a highlighting file for UltraEdit, that could possibly be used by PHP to make the source code even more readable. E.g. highlight keywords, properties, operators, comments. It has been a while, but did not PHP have some sort of highlighting feature built in, or was that got HTML... hmmm :)


- This is probably not the way "newsgroups"-like sites work. But if you added accounts, not only would the authors have it easier to add content. It would also be a "guaranteed" way to contact them. Furthermore this could allow authors to "edit" and "fix" their posts. If you want arbitrary editing to be avoided?!


Just some thoughts :)

You can contact me either here in this newsgroup, or email aeon <(-a t-)>
planetquake (<d o t>) com.

AEon
March 17, 2005
AEon wrote:

> <code>
> import std.c.stdio;
> 
> void main()
> { printf("Hi\n");
> }
> </code>
> 
> an import and a \n. But the example works without these. Strange.

This "long version" of yours is the correct one...

Walter has just added printf to object.d "while debugging Phobos",
and printing a newline is the only way to make sure it shows up...

Of course, the return value of void is still broken in current DMD. :(
(hopefully that will be fixed one day, so that we can use "void main")


But the canonical forms are either of:

> import std.stdio;
> void main()
> {
>   writefln("Hello, World!");
> }
> 
or: (C-style)

> import std.c.stdio;
> int main()
> {
>   printf("Hello, World!\n");
>   return 0;
> }

--anders
March 17, 2005
I think I understand how it works now, thanks.

"Derek Parnell" <derek@psych.ward> schreef in bericht news:eg34k000ed53$.45l1iy5k4huv$.dlg@40tude.net...
> On Thu, 17 Mar 2005 10:59:59 +0100, Joey Peters wrote:
>
>
>
>> Oh, just as a little side question; do you know what exactly the
>> in/out/inout parameter options mean? I find the reference explanation a
>> bit
>> confusing.
> On Thu, 17 Mar 2005 10:59:59 +0100, Joey Peters wrote:
>
>> Oh, just as a little side question; do you know what exactly the
>> in/out/inout parameter options mean? I find the reference explanation a
>> bit
>> confusing.
>
> 'in' parameters have their value preserved. That is, after calling a
> routine, the value of an 'in' parameter will not be changed after the
> routine has returned. The routine can change the value but when the
> routine
> returns, the value is restored to whatever it was when the routine was
> called. There is on tricky part though. Class instances and arrays are
> passed by reference. That means that a pointer to the data is passed to
> the
> array, and in this case an 'in' parameter just means that the pointer
> value
> is preserved *and* not the values in the class or array.
>
> Example of 'in':
>
>   import std.stdio;
>   void Foo(in char[] x)
>   {
>       writefln("Foo Before '%s' %d", x, x.length);
>       if (x.length == 0)
>         x ~= 'A';
>       else
>         x[0] = 'A';
>       x = "xyzzy";
>       writefln("Foo After  '%s' %d", x, x.length);
>   }
>   void main()
>   {
>     char[] Test = "abcdef";
>
>     writefln("Main Before '%s' %d", Test, Test.length);
>     Foo(Test);
>     writefln("Main After  '%s' %d", Test, Test.length);
>  }
>  ---------------------------
>  Main Before 'abcdef' 6
>  Foo Before 'abcdef' 6
>  Foo After  'xyzzy' 5
>  Main After  'Abcdef' 6
>  ------------------------
>
> 'out' parameters are initialized by D to whatever their .init property is at the point they are passed to the routine. The routine may change the values in 'out' parameters and the changes remain after the routine returns.
>
> Example of 'out':
>
>   import std.stdio;
>   void Foo(out char[] x)
>   {
>       writefln("Foo Before '%s' %d", x, x.length);
>       if (x.length == 0)
>         x ~= 'A';
>       else
>         x[0] = 'A';
>       x = "xyzzy";
>       writefln("Foo After  '%s' %d", x, x.length);
>   }
>   void main()
>   {
>     char[] Test = "abcdef";
>
>     writefln("Main Before '%s' %d", Test, Test.length);
>     Foo(Test);
>     writefln("Main After  '%s' %d", Test, Test.length);
>  }
> ---------------------------------
>  Main Before 'abcdef' 6
>  Foo Before '' 0
>  Foo After  'xyzzy' 5
>  Main After  'xyzzy' 5
> ---------------------------------
>
> 'inout' parameters are identical to 'out' parameters except that they are *not* initialized by D. The enter the routine with what ever value was in them when passed to the routine.
>
> Example of 'inout':
>   import std.stdio;
>   void Foo(inout char[] x)
>   {
>       writefln("Foo Before '%s' %d", x, x.length);
>       if (x.length == 0)
>         x ~= 'A';
>       else
>         x[0] = 'A';
>       x = "xyzzy";
>       writefln("Foo After  '%s' %d", x, x.length);
>   }
>   void main()
>   {
>     char[] Test = "abcdef";
>
>     writefln("Main Before '%s' %d", Test, Test.length);
>     Foo(Test);
>     writefln("Main After  '%s' %d", Test, Test.length);
>  }
> ---------------------------------
>  Main Before 'abcdef' 6
>  Foo Before 'abcdef' 6
>  Foo After  'xyzzy' 5
>  Main After  'xyzzy' 5
> ---------------------------------
>
> -- 
> Derek Parnell
> Melbourne, Australia
> 17/03/2005 9:34:49 PM


March 17, 2005
J C Calvarese says...
>*dsource tutorials*
>Example database: http://www.dsource.org/tutorials/
>Forum:            http://www.dsource.org/forums/viewforum.php?f=3

Sorry about a few error / oversights on my part. E.g. you seem to have *many* categories. Plus these can AFAICT be "freely" extended.


Some more thoughts/suggestions:


- Highligthing suggestions
e.g http://www.dsource.org/tutorials/index.php?show_example=64

- Comments blue green (ie. the color you use for links, no block
background color)
- String literals colored (no block background), gray or something
else less eye-poking.
- Operators green
- Blue keywords are fine.
- Numbers etc. red (everything presently shown in green)

Both string literals and comments are too prominant IMO (destracting), making it very hard to read the source code.


- The code block framing might be a bit nicer to read by adding a empty 1st and last lines, i.e. blue dotted frame keeping it's distance from all sides of the code.


- Pardon my saying so, but after reading some 20 source examples, the dotted frame around the source code is kind of an eye-saw IMO, possibly replace it with a thin solid line, in a darker gray tone to mellow down the visual impact of code blocks frame.


- Formatting Turorial?
http://www.dsource.org/tutorials/index.php?show_example=15
It would be helpful to have some sort of "formatting" tutorial, how
exactly you did the standard test, headlines etc. And how code
blocks are inserted. To help folks keep formatting consistent.


- http://www.dsource.org/tutorials/index.php?show_example=37

    printf("Press a key (using 'std.c.stdio.getch();' to wait) . . .\n\0");
    getch();

is the \0 actually correct and/or needed or useful? I have never seen string literals requiring a \0. (is used 3 times in the example).


- It could be interesting to allow folks to add examples to existing examples, to avoid the spamming of similar code sniplets. I.e. to have them all in the proper "thread".

AEon
March 17, 2005
In article <d1bogs$lr7$1@digitaldaemon.com>, AEon says...
>
>In article J C Calvarese says...
>
>>*dsource tutorials*
>>Example database: http://www.dsource.org/tutorials/
>>Forum:            http://www.dsource.org/forums/viewforum.php?f=3
>>
..snip...
>- It would be nice if the category section would "inherit" the category from which you clicked that link. In the above case it would be "Fundamentals".

Yes, that's a good idea. I've thought the same thing a few times. I can't remember why I haven't implemented that yet. I guess I just haven't gotten around to it yet.

>- To avoid inadvertent "mess ups" it could be nice to have a drop-down list of the valid "Category:"s. AFAICT those are 3 presently? Fundamentals, Intermediate, Advanced.

There are many categories and I'd like you contributors to be able to add their own. I think implementing your first suggestion would lessen the need for doing something like this (since I don't know that I could get this to work the way I'd like it to work).

>- Under the "Submit" button, it would really be nice to have a "Preview" button, because AFAICT there is no way to edit posts to correct layout bugs etc.
>
>IMO this would be one of the most important additions, since nice formatting greatly improves readability + understanding of code.

I've also thought about doing this. It shouldn't be too hard to do, so maybe I'll add this soon, too.

>- In the thread above I noted the source code is automatically highlighted? I have put together a highlighting file for UltraEdit, that could possibly be used by PHP to make the source code even more readable. E.g. highlight keywords, properties, operators, comments. It has been a while, but did not PHP have some sort of highlighting feature built in, or was that got HTML... hmmm :)

I ported a program called d2html (my improved version of Pavel's original code) to PHP. It works pretty well, but I admit it's not flawless.

>- This is probably not the way "newsgroups"-like sites work. But if you added accounts, not only would the authors have it easier to add content. It would also be a "guaranteed" way to contact them. Furthermore this could allow authors to "edit" and "fix" their posts. If you want arbitrary editing to be avoided?!

Maybe I could also the submitter to edit his own example. I'll think about this idea.

>Just some thoughts :)

Thanks. You've brought up a lot of good points. I don't know how much time I have to work on this in the month or so, but maybe I'll have a chance to implement some of this before May. ;)

jcc7
March 17, 2005
J C Calvarese wrote:
<snip>

> Thanks. You've brought up a lot of good points. I don't know how much time I
> have to work on this in the month or so, but maybe I'll have a chance to
> implement some of this before May. ;)
> 
> jcc7

Justin,

We should talk.  The tutorial section of dsource.org could be a plugin/module of Trac.  I.E. each project could have a tutorial section, along with forums, tickets, downloads, news, etc.

Then we could have a project at dsource that is kind of like the "D Language" project.  People could add their PEP-like requests, have tickets to track bugs, and all the tutorials for the language in general, and not a specific project, could be in this "D Language" project.

I'm bringing it up, because if we want to integrate with Trac, you'd have to rewrite in Python and use ClearSilver templates, instead of PHP.  Obviously, we'd convert the current ones to the new system...  Let's discuss, either here, on the site forum at dsource.org, or offline.

BA
« First   ‹ Prev
1 2