Website message overhaul, pass 2

Peter Alexander peter.alexander.au at gmail.com
Sun Nov 20 06:17:43 PST 2011


On 20/11/11 1:09 PM, Robert Clipsham wrote:
> - The code sample at the top is terrible, the equivalent C is only a
> couple of lines longer and it doesn't show off any of what makes D
> better! Admittedly you're limited in what you can do here as the code
> needs to be fairly understandable by non-D programmers, but what's there
> is... Not good at all.

It's hard to come up with something that is short, easily-understandable 
and demonstrates D's (numerous) powerful features.

How about this one:

// Match email addresses on each line of standard input
// using a compile-time generated regular expression engine.
import std.stdio, std.regex;

void main() {
     string email = r"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b";

     foreach (line; stdin.byLine()) {
         foreach (m; match(line, regex(email, "i"))) {
             writefln("%s[%s]%s", m.pre, m.hit, m.post);
         }
     }
}

Demonstrates:
- Syntax
- Imports
- Raw string literals
- Foreach with type deduction
- CTFE with regex
- "Batteries included" library (std.byLine(), regex, match, writefln)
- General succinctness of D code

> - Rotating the example is a brilliant idea, particularly if powered by a
> continuous contest.
> - This is less about the message, but how about an "explain this" link
> in the corner of examples with little hints for C/C++/Java programmers,
> so when clicked additional comments appear in the code or bubbles appear
> above on hover or something, they would include small bits of text like
> "auto can be used in place of a type to infer the type from what is
> being assigned"... But better worded of course.
> - Maybe it's just me, but I don't like the title being so long. I think
> "The D Programming Language" on its own is fine. The rest of it may
> still have a place, but it needs to be elsewhere in my opinion (even if
> it just moves to the line below).
> - Your summary sentence at the start reads "It pragmatically combines
> efficiency, control, and modeling power, with safety and programmer
> productivity." You then go on to talk about convinience, power and
> efficiency... http://en.wikipedia.org/wiki/Topic_sentence The sentence
> needs to be changed to reflect what you go on to detail below -
> currently you're making statements without backing them up (note that
> you do back up most of it, not all of it though, and the subheadings
> don't make it obvious where you can find out more about the claims).
> - convinience -> convenience
> - I can't really fault the bullet points, they're a huge improvement.
> - I have a reasonably large screen and can't see the news section
> without scrolling. To me this means there is no news ;)
>
> I'm starting to nit-pick, it must be getting better.

+1 to everything


More information about the Digitalmars-d mailing list