Jump to page: 1 25  
Page
Thread overview
Why are homepage examples too complicated?
Oct 13, 2016
Karabuta
Oct 13, 2016
Meta
Oct 13, 2016
Karabuta
Oct 13, 2016
cym13
Oct 13, 2016
Guillaume Piolat
Oct 14, 2016
Karabuta
Oct 16, 2016
Adam D. Ruppe
Oct 17, 2016
Karabuta
Oct 16, 2016
Nick Treleaven
Oct 16, 2016
Nick Treleaven
Oct 20, 2016
Nick Treleaven
Oct 20, 2016
Chris
Oct 20, 2016
Chris
Oct 20, 2016
Karabuta
Oct 20, 2016
Karabuta
Oct 21, 2016
Chris
Oct 21, 2016
Mark
Oct 21, 2016
Chris
Oct 17, 2016
Benjiro
Oct 17, 2016
Karabuta
Oct 18, 2016
Jesse Phillips
Oct 18, 2016
MakersF
Oct 18, 2016
Chris
Oct 18, 2016
Benjiro
Oct 18, 2016
Chris
Oct 18, 2016
Benjiro
Oct 19, 2016
Chris
Oct 18, 2016
Karabuta
Oct 19, 2016
Benjiro
Oct 19, 2016
rikki cattermole
Oct 19, 2016
Chris
Oct 19, 2016
Karabuta
Oct 20, 2016
Chris
Oct 21, 2016
Benjiro
Oct 22, 2016
Chris
Oct 19, 2016
Chris
Oct 19, 2016
Benjiro
Oct 19, 2016
Chris
Oct 20, 2016
Chris
October 13, 2016
I assume the purpose for those demonstrations are to win the interest of the user as to how easy and clean D code can be. Then why;

// Round floating point numbers
import std.algorithm, std.conv, std.functional,
    std.math, std.regex, std.stdio;

alias round = pipe!(to!real, std.math.round, to!string);
static reFloatingPoint = ctRegex!`[0-9]+\.[0-9]+`;

void main()
{
    // Replace anything that looks like a real
    // number with the rounded equivalent.
    stdin
        .byLine
        .map!(l => l.replaceAll!(c => c.hit.round)
                                (reFloatingPoint))
        .each!writeln;
}

How is a new visitor supposed to know "!" is for templates and not some complicated syntax?
October 13, 2016
On Thursday, 13 October 2016 at 19:06:26 UTC, Karabuta wrote:
> I assume the purpose for those demonstrations are to win the interest of the user as to how easy and clean D code can be. Then why;
>
> // Round floating point numbers
> import std.algorithm, std.conv, std.functional,
>     std.math, std.regex, std.stdio;
>
> alias round = pipe!(to!real, std.math.round, to!string);
> static reFloatingPoint = ctRegex!`[0-9]+\.[0-9]+`;
>
> void main()
> {
>     // Replace anything that looks like a real
>     // number with the rounded equivalent.
>     stdin
>         .byLine
>         .map!(l => l.replaceAll!(c => c.hit.round)
>                                 (reFloatingPoint))
>         .each!writeln;
> }
>
> How is a new visitor supposed to know "!" is for templates and not some complicated syntax?

How's a new user supposed to know <> is for templates when looking at a C++ example? They don't; it's just something that has to be learned, or they know it because other languages use a similar syntax. Rust uses ! for macro invocation, and I imagine that creeps into some of their examples (OTOH, anything that prints output). Templates are such an integral part of D that any non-trivial example can't get around not using them.
October 13, 2016
On Thursday, 13 October 2016 at 19:30:30 UTC, Meta wrote:
> On Thursday, 13 October 2016 at 19:06:26 UTC, Karabuta wrote:

> How's a new user supposed to know <> is for templates when looking at a C++ example? They don't; it's just something that has to be learned, ...

Does that make it a standard for everyone to follow?
October 13, 2016
On Thursday, 13 October 2016 at 19:06:26 UTC, Karabuta wrote:
> I assume the purpose for those demonstrations are to win the interest of the user as to how easy and clean D code can be. Then why;
>
> // Round floating point numbers
> import std.algorithm, std.conv, std.functional,
>     std.math, std.regex, std.stdio;
>
> alias round = pipe!(to!real, std.math.round, to!string);
> static reFloatingPoint = ctRegex!`[0-9]+\.[0-9]+`;
>
> void main()
> {
>     // Replace anything that looks like a real
>     // number with the rounded equivalent.
>     stdin
>         .byLine
>         .map!(l => l.replaceAll!(c => c.hit.round)
>                                 (reFloatingPoint))
>         .each!writeln;
> }
>
> How is a new visitor supposed to know "!" is for templates and not some complicated syntax?

You are definitely taking the problem in reverse here IMHO. The goal of such example isn't to get the user to get every little bit about it like “What does ! mean?”. It is impossible to explain each detail of the syntax in such a short format and that would only confuse the user to force everything in it anyway.

The goal of such example is for users to feel the general syntax when applied to an example expressive enough that they can follow it and infer for themselves the general meaning of the syntax.

The goal is to have them think

“Oh, that looks like a sequence of instructions on stdin.. byLine obviously mean that we read it by line, the map part isn't that easy to follow ok, but the last part each!writeln looks like we're writing each of a thing to a line... ok, so the actual replacement must happen in the map, yeah I see it, and there is the round part too so map must be some iterator thingy... Ok, I mostly get it.”

because if they do then it's where they get the confidence that they can red the language, that it feels "obvious" enough for them to use. That's what builds the idea of an intuitive language. Explaining how the code does what it does is definitely not the point here, knowing that ! is used for templates brings nothing. It could be used for any kind of other data structure the fact that “each!writeln” is understood as “write each line” is what really counts.

Maybe the example is poorly choosen and doesn't get new users to that point, but my experience showing it to friends is that it's definitely not that bad.
October 13, 2016
On Thursday, 13 October 2016 at 19:06:26 UTC, Karabuta wrote:
> I assume the purpose for those demonstrations are to win the interest of the user as to how easy and clean D code can be. Then why;
>
> // Round floating point numbers
> import std.algorithm, std.conv, std.functional,
>     std.math, std.regex, std.stdio;
>
> alias round = pipe!(to!real, std.math.round, to!string);
> static reFloatingPoint = ctRegex!`[0-9]+\.[0-9]+`;
>
> void main()
> {
>     // Replace anything that looks like a real
>     // number with the rounded equivalent.
>     stdin
>         .byLine
>         .map!(l => l.replaceAll!(c => c.hit.round)
>                                 (reFloatingPoint))
>         .each!writeln;
> }
>
> How is a new visitor supposed to know "!" is for templates and not some complicated syntax?

I agree, something friendly and familiar would be called for. Instead we have weird float-rounding programs.

The goal of such program should be to push the reader to continue reading by apealing to familiarty. I think this strongly conveys the message that D is complicated and "not for me".

See also:
https://golang.org/
https://www.rust-lang.org/fr-FR/
https://crystal-lang.org/
https://www.ruby-lang.org/fr/
https://www.python.org/

Do you notice something? The language branded as "simple" have the simplest landing page programs.
October 14, 2016
On Thursday, 13 October 2016 at 22:12:42 UTC, Guillaume Piolat wrote:
> On Thursday, 13 October 2016 at 19:06:26 UTC, Karabuta wrote:

> I agree, something friendly and familiar would be called for. Instead we have weird float-rounding programs.
>
> The goal of such program should be to push the reader to continue reading by apealing to familiarty. I think this strongly conveys the message that D is complicated and "not for me".
>
> See also:
> https://golang.org/
> https://www.rust-lang.org/fr-FR/
> https://crystal-lang.org/
> https://www.ruby-lang.org/fr/
> https://www.python.org/
>
> Do you notice something? The language branded as "simple" have the simplest landing page programs.

Apparently someone here thinks showing CPU internals is the best way to teach a beginner programming for him to write efficient code from learning stage. The art of teaching does not work that way in the real world.

The "!" is more trouble than good (IMO for the majority).  @Adam Roupe did a talk at previous DConf which he testifies to this.
October 16, 2016
On Friday, 14 October 2016 at 21:18:45 UTC, Karabuta wrote:
> The "!" is more trouble than good (IMO for the majority).  @Adam Roupe did a talk at previous DConf which he testifies to this.

Couldn't be me, I don't think I ever talked about it... and I'm actually pro-!. It is a perfectly fine syntax and not hard to learn.
October 16, 2016
On Thursday, 13 October 2016 at 19:06:26 UTC, Karabuta wrote:
>     // Replace anything that looks like a real
>     // number with the rounded equivalent.
>     stdin
>         .byLine
>         .map!(l => l.replaceAll!(c => c.hit.round)
>                                 (reFloatingPoint))
>         .each!writeln;

I think this example is a bit awkward for D newbies to decipher. I think here we are showing D's ctRegex; dropping the functional map and lambdas would make this more universally understood. Using matchAll rather than replaceAll makes the example a bit simpler too:

// Print a list of rounded decimal numbers
import std.conv, std.functional, std.math, std.regex;

// Chain functions together to round a string parsed as a real number
alias roundString = pipe!(to!real, std.math.round, to!string);

// Create a compile-time Regular Expression to match decimal numbers
static decimalRegex = ctRegex!`[0-9]+\.[0-9]+`;

void main()
{
    import std.stdio;

    // Iterate standard input lines
    foreach (line; stdin.byLine())
    {
        // Find all decimal matches
        foreach (m; line.matchAll(decimalRegex))
        {
            m.hit.roundString().writeln(); // round number and print
        }
    }
}


October 16, 2016
On Sunday, 16 October 2016 at 16:07:19 UTC, Nick Treleaven wrote:
> // Chain functions together to round a string parsed as a real number
> alias roundString = pipe!(to!real, std.math.round, to!string);

In fact if we're just printing the rounded numbers, we can drop to!string and inline roundString. If we want a functional example, let's keep it separate from the regex stuff.
October 17, 2016
On Thursday, 13 October 2016 at 19:06:26 UTC, Karabuta wrote:
> How is a new visitor supposed to know "!" is for templates and not some complicated syntax?

As a dlang newbie ( only started to learn a few days ago ), the example on the front page is just complex for new users.

Its not a lack of knowledge ( 15+ years php, some C in high school,  Perl 3 years and some other languages over the years ) but i had no clue that "!" ( used a lot in examples ) is actually templates ( or macro's ). I was focused on other parts ( shared libraries creation & loading etc ) so never got around to some of the "basics". Just assumed it was a operator.

Also, first example using regex? And the overuse of one-liners. Lets not start with so much one liners / merged lines, it makes something simple look more complex. Its great for more seasoned programmers but its less readable for people with little or first time experience.

Another issue is the "Edit/Args/Input/Run". First thing a person does is press "Run" but then your wondering, wait? What is that result? Where does it come from? Lost 20 seconds figuring out where it was hiding.

My suggestions:

A. Remove Args, Remove Input ( reworked / make any input inline in the code ). Simple is better.

B. Use multiple examples. Place buttons below instead of Args/Input [1 2 3 .. 8 Run].

Examples:

1. Hello World
2. ...
3. Templates
4. This Regex example ( reworked for inline input )
5. C/C++ Integration example
6. ...
... Show parts of the language its advantages. Its like drugs. Give people a taste and get them hooked for life. >:)

Just my 2 cents on the topic.
« First   ‹ Prev
1 2 3 4 5