If this script is intended to teach perl, or programming in general, then i agree that there are things here the students should not learn. I also think that, in that case, the for(;;) loop should be made legible. However, i got the idea that this perl was for something else; he did, after all, say it was a teaching aid, not an aid for teaching perl.

Spacewarp's script is much more readable for a student, i think. As such, it is better for making a point that can be easily followed about the nature of binary mathematics. If the algorithm was, in fact, presented in class as he coded it, then it is an accurate representation of the algorithm the teacher picked; since representing that algorithm was one of the stated goals, that's a good thing, even if the algorithm was bad. After all, you don't teach someone the french for "I went to the store" is "J'irai au cinéma" just because they should go to a movie instead. (This may seem like a nitpick, but i was given a few such programs to "learn" from and they drove me up a wall, because they did things totally unlike what they were said to do.)

And, really, if we're talking about a better algorithm, you should start with whatever power of two is the first one under the target number IMO. (int (log($n)/log(2)))

But to return to my point, i think his perl was not to teach perl, but to introduce them to the basic idea of programming. Actually, it might be a neat recurring theme for the class; take this bit of code and change it as they learn more code concepts, to include subroutines and be able to split things into different bases (ord(A) in trinary looks very different than ord(A )in binary...)

just my take.

thanks to OeufMayo for the french snippet.

.

In reply to Re: Re: Perl as a teaching aid by Vynce
in thread Perl as a teaching aid by spacewarp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.