in reply to Re^2: Formatting randomised data
in thread Formatting randomised data

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^4: Formatting randomised data
by merlyn (Sage) on Jun 20, 2005 at 12:00 UTC
    I consider understanding that "%d" has to truncate to an int to do its job to be as fundamental as knowing that "int" is available. I'm not sure why you put it in a "nuance" category. What else would %d have to do?

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      As the thread author points out in his reply to my post, programming across multiple languages teaches you safe techniques for approaching problems. Sometimes this means typecasting values where there could possibly be any confusion over its meaning.

      You can argue that usage of parenthesis is a waste of time.. if one understands the order of the evaluation of the operators then typing ( or ) is wasteful. Further, I'm sure you would argue that understanding the exact order of evaluation of operators is fundamental to programming in Perl. But then this would also demonstrate a lack of experience programming in multiple languages, as not all languages treat precedence the same way.

      Therefore one can afford a new programmer to a language the mistake of typecasting something unnecessarily. One can never afford to excuse the programmer who dangerously, however, coding assuming things would just turn out as they expect without much experience behind them.

        Maybe I'm being misunderstood.

        I would never fault a beginning Perl programmer for "speaking Perl with a C accent" (see other threads for my description of that).

        However, I will always demonstrate "speaking Native Perl" (or "Perl as she is spoke").

        In this case, the "int" is definitely redundant, and would get noticed in a code review by my team. Just like the random appearance of "scalar" in definitely scalar contexts, and a dozen other "I don't quite grok Perl" mistakes that I see made on a regular basis.

        There is a "native" Perl. I'm teaching it. The llama and the alpaca and the camel define it. My columns and monk postings and usenet comments demonstrate it.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.

Re^4: Formatting randomised data
by Manawydan (Initiate) on Jun 21, 2005 at 01:38 UTC

    But I like that the thread author used int().. it shows foresight and understanding of basic programming principles.

    That comes from years of BASIC, Pascal, VB(A) etc. While new to Perl, I'm not new to programming. I'm trying to learn Perl in the same way that I moved from ZX81 BASIC and that is through a lot of reading and a greater deal of trial and error. *grin*

    The thing with Perl, which isn't as flexible in most other languages, is the number of shortcuts of shortcuts that are available. Using int() seemed reasonable but it's great that there is a shortcut of this by using sprintf. Hopefully, with a bit of time and a lot of effort, I'll get the hang of the shortcuts.

    Oh, the days of int(rnd(1)*100)+1 *grin*

    Cheers! :)