How To Dynamic Web Rendering?

2011-05-12 Thread Matthew Ong
Hi,

What is the counterpart in D for replacing JSP/ASP/JRuby on Rail or some sort
of dynamic web base development?

How to compile a D code into dll to be used by apache or MS IIS?

How to also code digitally sign the DLL  that was compiled in D?

Matthew Ong


Re: How To Dynamic Web Rendering?

2011-05-12 Thread Adam Ruppe
 What is the counterpart in D for replacing JSP/ASP/JRuby on Rail or
 some sort of dynamic web base development?

I use D for web work by using the standard CGI interface and sometimes
an embedded http server. It's the best thing I've ever used.

 How to also code digitally sign the DLL  that was compiled in D?

The same way you sign any other dll/exe.


How to search news group?

2011-05-12 Thread Matthew Ong
Hi D Forum Admin,

I am using the webbase interface for the forum.
How to do forum text search instead of browsing over them one by one?

Matthew Ong



Re: How to search news group?

2011-05-12 Thread dennis luehring

Am 12.05.2011 15:24, schrieb Matthew Ong:

Hi D Forum Admin,

I am using the webbase interface for the forum.
How to do forum text search instead of browsing over them one by one?

Matthew Ong



use thunderbird as newsclient


How to break module into multiple file.

2011-05-12 Thread Matthew Ong
Hi,

According to:
http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.comgroup=digitalmars.Dartnum=135947

And also source code within dmd2/src
It seems that there is only one file per module.

Is module similar to a single java package and namespace in VC++/C#?

If yes, most name spaced programming language allow breaking of single module
into multiple
file to store various logically linked class and separate them when they are 
not.

Like module Collection may have:
Common interfaces for both HashMap, LinkedList and hashlist.

But they should be all be in different source file(HashMap.d, LinkedList.d,
HashList.d) but
logically within the same module collection.(Directory)
How do I do that within D? what is the directory layout of the project?

Matthew Ong


Re: How to break module into multiple file.

2011-05-12 Thread Adam Ruppe
Use folders as a collection of modules.

foo/bar.d = import foo.bar;

You don't actually have to separate them into folders - the directory
layout is up to you. But this is the simplest method.

Learn more here:

http://digitalmars.com/d/2.0/module.html


Re: How To Dynamic Web Rendering?

2011-05-12 Thread Matthew Ong
Hi Adam,

Thanks again for the sharp pointed answer.
 What is the counterpart in D for replacing JSP/ASP/JRuby on Rail or
 some sort of dynamic web base development?

I use D for web work by using the standard CGI interface and sometimes
an embedded http server. It's the best thing I've ever used.
Could you share how or show an URL that provide sample code to do that in D?


 How to also code digitally sign the DLL  that was compiled in D?
The same way you sign any other dll/exe.
So we use external tool to do that and not a build in one??
In java, we use jarsigner with some keygen.

Please bear in mind I am new to D.



Re: How to break module into multiple file.

2011-05-12 Thread Matthew Ong
Hi Adam,

Ok. Just to be very clear here. Please help to validate.

Common interfaces for both HashMap, LinkedList and hashlist.

But they should be all be in different source file(HashMap.d, LinkedList.d,
HashList.d)..

To have import for:

module CornerCube.Collections

class HashMap{...}

I would have to layout as:

MyLib/Collection.d  HashMap, LinkedList, HashList within this file
The single Collection.d works for me but hard to maintain manually.

For this one I use import MyLib.Collection;

or

MyLib/Collections/HashMap.d  Single class file. but module Corner
CornerCube/Collection/LinkedList.d
CornerCube/Collection/HashList.d

This one I have error.
import MyLib.Collection;
This also I have error.
import MyLib.Collection.LinkedList;
import MyLib.Collection.HashList;
// Some sort of recursive import...


How do I import them within the calling class?




Re: How To Dynamic Web Rendering?

2011-05-12 Thread Adam Ruppe
 Could you share how or show an URL that provide sample code to do
 that in D?

Check out my D api demo:

http://arsdnet.net/cgi-bin/apidemo/

Here's the source code (about 50 lines of D)
http://arsdnet.net/apidemo.d

And the HTML templates it uses:
http://arsdnet.net/apidemo-document.html
http://arsdnet.net/apidemo-javascript.html


The libraries it imports are available here

http://arsdnet.net/dcode/



That demo shows something relatively new I made to provide same
source access to HTML and Javascript that uses D's reflection to
auto-generate almost everything.


You can also do more traditional style web apps. Here's a gradient
generator written in D:

http://arsdnet.net/cgi-bin/gradient?w=100h=100c1=ffc2=00ff00c4=00t=50

Source:
http://arsdnet.net/gradient.d

It uses my cgi.d from the dcode folder above. This code has a few
features so it isn't the simplest demo, about 150 lines. It makes
the png and sends it right out over the web.


Hello world with cgi.d looks like this:

import arsd.cgi;
void main() {
   auto cgi = new Cgi();
   cgi.write(Hello, world!);
   cgi.close();
}


In all my examples though, I used mixins for main functions instead
of writing them directly because the mixin adds try/catch for
exceptions and handles the create and close too. This would look like:

import arsd.cgi;
void run() { cgi.write(Hello, world!); }
mixin GenericMain!run;


I also often use my D DOM library in web code too, which you see
in the first example. That library is available in my folder too.

 So we use external tool to do that and not a build in one??

Yes, something like signtool.exe from Microsoft works for Windows
programs.

Generally, if you can do it to a C++ program, you can do it to a
D program too.


Re: How to break module into multiple file.

2011-05-12 Thread Jonathan M Davis
On 2011-05-12 06:33, Matthew Ong wrote:
 Hi,
 
 According to:
 http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.comgroup
 =digitalmars.Dartnum=135947
 
 And also source code within dmd2/src
 It seems that there is only one file per module.
 
 Is module similar to a single java package and namespace in VC++/C#?
 
 If yes, most name spaced programming language allow breaking of single
 module into multiple
 file to store various logically linked class and separate them when they
 are not.
 
 Like module Collection may have:
 Common interfaces for both HashMap, LinkedList and hashlist.
 
 But they should be all be in different source file(HashMap.d, LinkedList.d,
 HashList.d) but
 logically within the same module collection.(Directory)
 How do I do that within D? what is the directory layout of the project?

A module is always one file and only one file. However, a module can 
publically import another module (the default import is private) and then any 
module that imports that module will also import the modules that that module 
publically imports. Just stick public in front of an import to make it public.

Any modules within the same directory are within the same package, so they 
would then share package access if you share the package access modifier, but 
there's no way to impor them as a group. Modules are always imported 
individually. The closest you ever get to being able to import them as a group 
is if you have a module which publically imports other modules, and you import 
that module.

- Jonathan M Davis


Re: How to break module into multiple file.

2011-05-12 Thread Alexander
On 12.05.2011 17:05, Jonathan M Davis wrote:

 A module is always one file and only one file.

  ...which could be really, really big due to this limitation (std.datetime), 
and this is not always convenient sometimes - that's why I like the idea of 
namespaces and partial classes.

  There is another inconvenience with D modules - compiler will *always* split 
module name into file system path when searching, so I couldn't have different 
namespaces (on different levels) in single directory, and this also forces me 
to match file
name with module name.

  Sure, somehow this is good - but not always, as it makes splitting of one 
logical module into several physical pieces quite hard. The idea of enforcing 
specific style of code grouping and organization is not quite good, IMHO.

  However, there is a nice trick using mixin(import(file-to-include)) - which 
could really help sometimes :)

/Alexander


Re: How to break module into multiple file.

2011-05-12 Thread Adam Ruppe
 so I couldn't have different namespaces (on different levels) in
 single directory, and this also forces me to match file
 name with module name.

No, it doesn't. You're right that it splits when it searches, but it
doesn't *have* to search.

If you use the module declaration at the top of the file and manually
list the files on the command line, the file and directory names don't
matter.


a.d

import cool.wtf;
void main() {}


b.d

module cool.wtf;


dmd a.d b.d # works!


Re: How to break module into multiple file.

2011-05-12 Thread Alexander
On 12.05.2011 19:53, Adam Ruppe wrote:

 If you use the module declaration at the top of the file and manually
 list the files on the command line, the file and directory names don't
 matter.

  Right, but this, in turn, forces me to recompile all of my modules after 
every change, no matter where :)

  For small projects this is OK, but for large - not quite, IMHO.

/Alexander


Re: How to break module into multiple file.

2011-05-12 Thread Adam Ruppe
 For small projects this is OK, but for large - not quite, IMHO.

I don't know about that. I always compile everything at once
now - in my experience, it's negligibly slower than linking alone.

druntime: compiled all at once takes ~1 second on my box. 65k lines of (light) 
code.

phobos: compiled all at once takes ~1 second. 150k loc.

my web app for work: 3 seconds, all at once. 50k loc, does some crazy stuff.


Maybe million line programs will be unacceptably slow, but I don't
know, I'd have to actually see it being a problem in practice
before I get worked up about it. tbh I wouldn't be surprised if
the incremental build was actually slower than the all at once in
a lot of situations.

(Though, naming the packages and modules to match the filesystem is
a small cost anyway - it makes it easier to find the files so usually
the best choice anyway.)


Re: How to break module into multiple file.

2011-05-12 Thread Robert Clipsham

On 12/05/2011 19:25, Adam Ruppe wrote:

Maybe million line programs will be unacceptably slow, but I don't
know, I'd have to actually see it being a problem in practice
before I get worked up about it. tbh I wouldn't be surprised if
the incremental build was actually slower than the all at once in
a lot of situations.


It's a lot slower in almost all situations I've encountered... It's also 
buggier due to templates only being emitted once (though I've never run 
into this issue personally, I know others have).



(Though, naming the packages and modules to match the filesystem is
a small cost anyway - it makes it easier to find the files so usually
the best choice anyway.)



--
Robert
http://octarineparrot.com/


Re: How to break module into multiple file.

2011-05-12 Thread Jonathan M Davis
  For small projects this is OK, but for large - not quite, IMHO.
 
 I don't know about that. I always compile everything at once
 now - in my experience, it's negligibly slower than linking alone.
 
 druntime: compiled all at once takes ~1 second on my box. 65k lines of
 (light) code.
 
 phobos: compiled all at once takes ~1 second. 150k loc.
 
 my web app for work: 3 seconds, all at once. 50k loc, does some crazy
 stuff.
 
 
 Maybe million line programs will be unacceptably slow, but I don't
 know, I'd have to actually see it being a problem in practice
 before I get worked up about it. tbh I wouldn't be surprised if
 the incremental build was actually slower than the all at once in
 a lot of situations.
 
 (Though, naming the packages and modules to match the filesystem is
 a small cost anyway - it makes it easier to find the files so usually
 the best choice anyway.)

It was designed that way to make finding and managing the files easier. The 
compiler is actually able to locate modules easily and reliably. It's 
generally easy for _you_ to find them too, because the import tells you where 
they are (the fact that you can have multiply directories being searched for 
imports being the main complicating factor). It's what pretty much any D 
programmer will expect. Doing anything else will just cause confusion. Sure, 
you can do whatever you want with your own code, but I would definitely advise 
just following the normal directory structure with modules rather than trying 
to mess around with it. It is the way that it is for a reason.

- Jonathan M Davis


Re: How To Dynamic Web Rendering?

2011-05-12 Thread Nick Sabalausky
Matthew Ong on...@yahoo.com wrote in message 
news:iqgo17$2nqv$1...@digitalmars.com...
 Hi Adam,

 Thanks again for the sharp pointed answer.
 What is the counterpart in D for replacing JSP/ASP/JRuby on Rail or
 some sort of dynamic web base development?

I use D for web work by using the standard CGI interface and sometimes
an embedded http server. It's the best thing I've ever used.
 Could you share how or show an URL that provide sample code to do that in 
 D?


 How to also code digitally sign the DLL  that was compiled in D?
 The same way you sign any other dll/exe.
 So we use external tool to do that and not a build in one??
 In java, we use jarsigner with some keygen.

 Please bear in mind I am new to D.


Here's a basic Hello world CGI app in D:

// hellocgi.d
import std.conv;
import std.stdio;

void main()
{
// Read in HTTP request headers
string[] requestHeaders;
while(true)
{
string line = readln();
if(line.length = 1)
break;

requestHeaders ~= line;
}

// Send response headers
writeln(Status: 200 OK);
writeln(Content-Type: text/html; charset=UTF-8);
writeln();

// Send content
writeln(biHello world/i/b);
}

Compile with:
dmd hellocgi.d

And just stick the resulting hellocgi.exe (windows) or hellocgi (other) 
in whatever cgi-bin-capable directory you have on your server.

Everything else (such as fancy CGI libraries/frameworks like Adam's) can 
ultimately be built out of that basic idea.

Keep in mind though, that since D is natively compiled, you'll have to 
compile it on either the same OS and CPU architecture as your server, or an 
OS/CPU that's compatible with your server. (This would be true of C/C++ as 
well.)

I'm sure it's possible to make an ISAPI filter or Apache module in D, but 
I've never really done that in any langauge, and I haven't really dealt with 
DLLs much, so I wouldn't know how. But even as CGI, a web app in D is likely 
to still be much faster than one in, for instance, PHP or Ruby.




Re: How to break module into multiple file.

2011-05-12 Thread Nick Sabalausky
Matthew Ong on...@yahoo.com wrote in message 
news:iqgnj9$2n0j$1...@digitalmars.com...
 Hi,

 According to:
 http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.comgroup=digitalmars.Dartnum=135947

 And also source code within dmd2/src
 It seems that there is only one file per module.

 Is module similar to a single java package and namespace in VC++/C#?

 If yes, most name spaced programming language allow breaking of single 
 module
 into multiple
 file to store various logically linked class and separate them when they 
 are not.

 Like module Collection may have:
 Common interfaces for both HashMap, LinkedList and hashlist.

 But they should be all be in different source file(HashMap.d, 
 LinkedList.d,
 HashList.d) but
 logically within the same module collection.(Directory)
 How do I do that within D? what is the directory layout of the project?


--- Convert this... ---

// libfoo.d
module libfoo;
void a() {}
void b() {}
void c() {}

// main.d
import libfoo;
void main()
{
a();
b();
c();
}

-- ...to this: ---

// libfoo/all.d
module libfoo.all;
public import libfoo.partA;
public import libfoo.partB;
public import libfoo.partC;

// libfoo/partA.d
module libfoo.partA;
void a() {}

// libfoo/partB.d
module libfoo.partB;
void b() {}

// libfoo/partC.d
module libfoo.partC;
void c() {}

// main.d
import libfoo.all;
void main()
{
a();
b();
c();
}




Re: How To Dynamic Web Rendering?

2011-05-12 Thread Adam Ruppe
// Read in HTTP request headers

Actually, that's not quite right. The HTTP headers are sent
as environment variables. stdin gives you the POST variables -
with the encoding given in the HTTP_CONTENT_TYPE envvar iirc.
(that's where the Content-Type http header is found).

The most common type is urlencoded, so it's just like parsing the
query string. The other one I handle is multipart - the encoding for
file upload forms.

Getting all that stuff out is the main benefit of a basic cgi library..
it's a bit of a pain to do yourself every time.


Re: How To Dynamic Web Rendering?

2011-05-12 Thread Nick Sabalausky
Adam Ruppe destructiona...@gmail.com wrote in message 
news:iqhha9$17dp$1...@digitalmars.com...
// Read in HTTP request headers

 Actually, that's not quite right. The HTTP headers are sent
 as environment variables. stdin gives you the POST variables -
 with the encoding given in the HTTP_CONTENT_TYPE envvar iirc.
 (that's where the Content-Type http header is found).


Ugh. Apperently, too much Flash/PHP/HTML/etc has rotted my mind...




[going OT] Re: How To Dynamic Web Rendering?

2011-05-12 Thread Adam D. Ruppe
 Ugh. Apperently, too much Flash/PHP/HTML/etc has rotted my mind...

Speaking of brain rot, the first version of my cgi.d actually aimed
to mimic PHP! Some stupid part of me actually started to *like* the
superglobals for a while...

It had a static module constructor that built the arrays, and gave
them global names like PHP does:

import cgi;

void main() {
 auto my_var = _POST[my_var]; // works in D
}

It even simulated PHP's session_start() thing, though bugs in
std.variant kept it from being particularly useful at the time.
While std.variant is now fixed, I haven't had a need for sessions
like that, so never updated that to the new module.



For some reason, I actually liked it at the time. But, it broke
down when I decided to write my own little http server to avoid
Apache bloat for an app. A shared, mutable global is obviously
nasty there.

(I did stick with it for a while, but it got so complicated I
ditched the whole stupid thing and started over, writing the
new class based cgi.d. If you look at my code though, you'll see
a couple things that are very bizarre according to the CGI standard:
these are the things that let it work with the embedded httpd too.
It reads all headers itself and writes the raw protocol to sockets
instead of stdout when constructed that way. Thus, aside from the
constructor arguments, the rest of the client code looks the same,
so I can switch from embedded to apache/iis and back easily enough.
The functions being mixin GenericMain!() instead of main() is also
due to this, though the try/catch it provides is nice too.)


Anywho.

Another bad experience with PHP led me to make the get and post
vars in cgi.d completely immutable - something that leads to
some pain, since phobos and druntime don't care much for
immutable(char[])'s (instead opting to work with
immutable(char)[]'s. This has gotten worse in the new beta with
even the replace() function no longer working on the former! Ugh!)

But, some minor hacks here and there make it work, so yay.

And, unlike PHP, if some asshole decides to write $_POST[evil] =
$whatever; in his vile function, I won't have to deal with it later!
Whoo hoo!


Re: How to break module into multiple file.

2011-05-12 Thread Alexander
On 12.05.2011 20:34, Jonathan M Davis wrote:

 It's generally easy for _you_ to find them too, because the import tells you 
 where 
 they are (the fact that you can have multiply directories being searched for 
 imports being the main complicating factor). It's what pretty much any D 
 programmer will expect. Doing anything else will just cause confusion.

  For those who are started with D, or had something similar before - probably.

  But not for all people this is natural way to handle their sources. In 
general, I agree, the reasoning is good enough - I follow it.

  One thing though is really annoying (to me, at least) with this binding to 
file name - if file is named with dashes, compiler wouldn't find it by itself. 
For those who prefer underscores this is not a problem, of course.

/Alexander


Re: How to break module into multiple file.

2011-05-12 Thread Jonathan M Davis
 On 12.05.2011 20:34, Jonathan M Davis wrote:
  It's generally easy for _you_ to find them too, because the import tells
  you where they are (the fact that you can have multiply directories
  being searched for imports being the main complicating factor). It's
  what pretty much any D programmer will expect. Doing anything else will
  just cause confusion.
 
 For those who are started with D, or had something similar before -
 probably.
 
 But not for all people this is natural way to handle their sources. In
 general, I agree, the reasoning is good enough - I follow it.
 
 One thing though is really annoying (to me, at least) with this binding
 to file name - if file is named with dashes, compiler wouldn't find it by
 itself. For those who prefer underscores this is not a problem, of course.

Dashes aren't legal in module names, because they're not legal in indentifier 
names. However, if you insist on naming your files that way for whatever 
reason, you can always put dashes in the file name and just name the module 
appropriately with the module statement at the top of the file. As long as the 
names are close (like the module name with underscores and the file with 
dashes), it shouldn't pose much problem for programmers, and the compiler can 
find them just fine. Still, I wouldn't have though that dashes would have been 
a big enough deal to really care. I would have thought that you'd name the 
module whatever made sense for the code and then just name the file 
accordingly. However, the module statement does allow you to make them not 
match if you really want to, so that situtation has been designed for.

- Jonathan M Davis


Re: [going OT] Re: How To Dynamic Web Rendering?

2011-05-12 Thread Nick Sabalausky
Adam D. Ruppe destructiona...@gmail.com wrote in message 
news:iqhkdn$1co1$1...@digitalmars.com...
 Ugh. Apperently, too much Flash/PHP/HTML/etc has rotted my mind...

 Speaking of brain rot, the first version of my cgi.d actually aimed
 to mimic PHP! Some stupid part of me actually started to *like* the
 superglobals for a while...


Heh. Well they are at least convenient. I'm sure that's probably why PHP did 
it in the first place.

 It had a static module constructor that built the arrays, and gave
 them global names like PHP does:

 import cgi;

 void main() {
 auto my_var = _POST[my_var]; // works in D
 }

 It even simulated PHP's session_start() thing, though bugs in
 std.variant kept it from being particularly useful at the time.
 While std.variant is now fixed, I haven't had a need for sessions
 like that, so never updated that to the new module.


I don't know how yours works, but PHP's session system has a number a pains. 
The whole way it handles session timeouts is just bizarre, and the fact that 
it's even possible for the sysadmin to enable session.auto_start has caused 
me big headaches.

Actually, that get's into one of the big things I hate about PHP: there's 
far too much it allows sysadmins to fuck with. And it's not always possible 
for the programmer to override dumb php.ini settings. As a result, even a 
single specific point release of PHP is essentially 5 million different 
languages, depending what server you're on and your sysadmin's day-to-day 
whims. And a lot of the settings are just stupid features that never should 
have been put in in the first place (granted, those ones tend to become 
deprocated, but by then the damage is already done).

Which reminds me of the PHP4-PHP5 debacle. I can certainly appreciate the 
occasional need for changes that break backwards-compatibility (especially 
as a D user), so I don't have a problem per se with the fact that PHP5 broke 
backwards compatibility (although it's not like compatibility in PHP has 
ever been anything but a joke). But there are so many ways it would have 
been so trivial to avoid the problems it caused. Probably the simplest and 
most obvious would be a decree Scripts targeting PHP5 and up must end with 
the extension .php5, otherwise it will either refuse to run or get sent to a 
PHP4 installation if available. Or instead of the extension, require the 
first line to be ?php PHP5..., etc. So many easy ways to avoid the 
problems they had. And that's all just off the top of my head. But PHP's 
primary design principle seems to be Be sloppy whenever possible.

Of course, D2 broke backards compatibility with D1 and doesn't have anything 
like what I suggested above for PHP5. But it works for D because the 
language exists completely on the development side, not on the server side 
like PHP.


 For some reason, I actually liked it at the time. But, it broke
 down when I decided to write my own little http server to avoid
 Apache bloat for an app.

Cool :)

It's amazing how simple a basic http server is. Yea, there's some details 
and gotchas to be careful of if you're really trying to follow the HTTP1.1 
spec properly (which is probably a good idea anyway). But even still, 
someone who's never written a server would probably think it would need to 
be some major Apache-level undertaking. That's what I originally thought. 
But unless you're really going for 
super-flexibility/configurability/bells-and-whistles, etc., you really don't 
need 99% of that, and it actually ends up being pretty simple.

...Unless you want to run it on a shared web host. Then you're just plain 
shit-out-of-luck ;)

 A shared, mutable global is obviously
 nasty there.

 (I did stick with it for a while, but it got so complicated I
 ditched the whole stupid thing and started over, writing the
 new class based cgi.d. If you look at my code though, you'll see
 a couple things that are very bizarre according to the CGI standard:
 these are the things that let it work with the embedded httpd too.
 It reads all headers itself and writes the raw protocol to sockets
 instead of stdout when constructed that way. Thus, aside from the
 constructor arguments, the rest of the client code looks the same,
 so I can switch from embedded to apache/iis and back easily enough.

That's pretty cool.

 The functions being mixin GenericMain!() instead of main() is also
 due to this, though the try/catch it provides is nice too.)


 Anywho.

 Another bad experience with PHP led me to make the get and post
 vars in cgi.d completely immutable - something that leads to
 some pain, since phobos and druntime don't care much for
 immutable(char[])'s (instead opting to work with
 immutable(char)[]'s. This has gotten worse in the new beta with
 even the replace() function no longer working on the former! Ugh!)

 But, some minor hacks here and there make it work, so yay.

 And, unlike PHP, if some asshole decides to write $_POST[evil] =
 $whatever; in his vile function, I won't 

Re: How to break module into multiple file.

2011-05-12 Thread Nick Sabalausky
Alexander aldem+dm...@nk7.net wrote in message 
news:iqh6gk$hpn$1...@digitalmars.com...
 On 12.05.2011 17:05, Jonathan M Davis wrote:

 A module is always one file and only one file.

  ...which could be really, really big due to this limitation 
 (std.datetime), and this is not always convenient sometimes - that's why I 
 like the idea of namespaces and partial classes.

...

  However, there is a nice trick using mixin(import(file-to-include)) - 
 which could really help sometimes :)


One could also just use public imports. Although using public imports for 
this sort of situation would probably would work even better if modules were 
allowed to have the same name as packages. I have no idea how difficult that 
would be to implement in DMD, though.