RFC (was: Re: Just for fun brainfuck'a'like textprocessor)

Gregor Kopp gregor.kopp at chello.at
Wed May 23 23:39:59 PDT 2007


Hi davidb, thank you for your improvements, and hitting me to the ',' issue ;)

> So, what about a kind of "official" RFC - please comment my code
> so I can improve my style? (just put "RFC ..." in the topic)

Okay.

> This way, you could not only learn through your own code
> being commented upon, but also through watching other people's
> style & improvements!

That was my intention for posting it here ;)

> That said, I'll make a first try @Gregor Kopp's code:
> 1) You'd definitely want a default case in your switch statement
>     which btw. fits nicely with "other characters (which are ignored)"
>     (http://en.wikipedia.org/wiki/Brainfuck)
>     (currently it exits with an "Error: Switch Default ..."
>      if it encounters any other symbol than the ones checked for)

Your right, I started this small program to learn about the d, so
I've learned several things, but as I see, not enough ;)

> 2) Just personal preference, but I'd try not to put too much
>     functionality in main(), makes code more clear and above all:
>     easier reusable
>     (okay, its a bf interpreter, no big reuse here ;-).

Normally I split up my code more modular, but here, its only about 100
loc.

> 3) []-handling: not quite the specs implemented, but nicely done with
>     a stack :-)

I just wanted to demonstrate the stack, I know it could also be done with
pointers and other technics.

> 4) line 61:
>     I don't quite see why you use char[] initialized with 1 for cells,
>     but that's probably just me.

Here i have to think about it again how to improve this.

> 5) line 62:
>     if "for (;;) ... " has only one statement(?), you don't need
>     enclosing {} (just cosmetics, but hey - 2 chars less typing *g*)
>     (or did you use it here as a means to show your intention
>      more clearly?)

Normally I do it like you described it. I also put private, public and so
on in front of every type and variable, just to say: I mean it that way.
I'm curious.

> 6) descriptive names in addition to clear indentation
>     => very easily readable code, nice!

I want to be capable reading my code years after. My Ruby programs are
looking also that way and are "written", not obfuscated. My intetion
behind is also, that others can read my code without hurting there eyes.
 
> Considering the Stack class:
> I'm not quite sure about the use of "this.length" in the various
> contexts, could someone please explain it to me?

I used the length of my stack outside other programs. I wanted to know
the elements nested inside my stack in other programs. My future plan is
to write a small ide for the bf interpreter. So I have to rewrite the whole
thing.
 
> and attached, also a little bf interpreter
 
Thank you for that, I will study it.


More information about the Digitalmars-d-learn mailing list