Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.perl.modules > #205

bytes, English, and prototypes

From Ivan Shmakov <oneingray@gmail.com>
Newsgroups comp.lang.perl.modules, comp.lang.perl.misc, alt.barcodes
Subject bytes, English, and prototypes
Followup-To comp.lang.perl.misc
Date 2013-03-13 17:28 +0000
Organization Aioe.org NNTP Server
Message-ID <87y5drky5b.fsf_-_@violet.siamics.net> (permalink)
References <87ehfjmst4.fsf@violet.siamics.net> <u0m61a-t5i1.ln1@anubis.morrow.me.uk>

Cross-posted to 3 groups.

Followups directed to: comp.lang.perl.misc

Show all headers | View raw


>>>>> Ben Morrow <ben@morrow.me.uk> writes:
>>>>> Quoth Ivan Shmakov <oneingray@gmail.com>:

	[Dropping news:comp.lang.perl.modules and news:alt.barcodes from
	Followup-To:.]

[...]

 >> $ cat < 89br96tnpoogun68sfh1jkj1sb.perl 

 >> use bytes;

 > You should not use 'bytes'.  It doesn't ever do anything useful and
 > sometimes lets you look at parts of the perl internals you shouldn't
 > be looking at.

	Indeed, I've read the documentation.  It was my understanding
	that, in the nutshell, the "bytes" pragma makes Perl operate
	strictly on octet sequences for its strings, instead of allowing
	either strings of octets /or/ strings of Unicode characters.

	Frankly, I do not see any harm in using this pragma /provided/
	that the code doesn't switch it on and off at will.

	The question on what setting do the loaded modules use remains
	open, but for the specific example I've given (which uses no
	text-processing modules) I'd expect the chances of running into
	issues to be quite low.

[...]

 >> use English;

 > You should not use English, it makes your code harder to read for
 > anyone who knows Perl, and teaches you bad habits.

	?  I may be having a bit too much Lisp background, but I've
	always considered something_that_one_can_read to be a way better
	identifier for a global than, say, ~.

	Besides, there's a chance that the code I write will be read by
	someone not quite knowing Perl.

[...]

 >> sub rand_blob (;$) {

 > You should not use prototypes unless you need the special parsing
 > effects they cause.

	Is there a practical reason to forgo the compile-time arguments'
	type checking they offer?  For me, code that fails to compile is
	better than code that suddenly dies after running for hours.
	(Which is still better than the code that dies at the wrong
	place; or doesn't die, but silently gives a wrong result.)

[...]

 > Unless you need cryptographic randomness (and since you're using
 > urandom, you don't), it would be better to use something like

 > sub rand_blob {
 >     my ($len) = @_;
 >     $len //= 24;
 >     return join "", map chr rand 0xff, 0..$len;
 > }

	ACK, thanks.  (Although, my guess is that even if urandom(4) is
	worse than random(4), Perl's rand is worse, randomness-wise,
	still.)

-- 
FSF associate member #7257

Back to comp.lang.perl.modules | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Imager::QRCode-ing octet sequences vs. zbarimg(1) Ivan Shmakov <oneingray@gmail.com> - 2013-03-13 11:40 +0000
  Re: Imager::QRCode-ing octet sequences vs. zbarimg(1) Ben Morrow <ben@morrow.me.uk> - 2013-03-13 16:27 +0000
    bytes, English, and prototypes Ivan Shmakov <oneingray@gmail.com> - 2013-03-13 17:28 +0000
    Re: Imager::QRCode-ing octet sequences vs. zbarimg(1) Ivan Shmakov <oneingray@gmail.com> - 2013-03-14 20:25 +0000
    Re: Imager::QRCode-ing octet sequences vs. zbarimg(1) Ivan Shmakov <oneingray@gmail.com> - 2013-03-17 17:57 +0000
      Re: Imager::QRCode-ing octet sequences vs. zbarimg(1) Ben Morrow <ben@morrow.me.uk> - 2013-03-18 23:42 +0000
        [OT] reporting bugs Ivan Shmakov <oneingray@gmail.com> - 2013-03-30 11:02 +0000
          Re: reporting bugs Ben Morrow <ben@morrow.me.uk> - 2013-04-01 22:58 +0100
            Re: reporting bugs Ivan Shmakov <oneingray@gmail.com> - 2013-04-06 13:50 +0000
          configuring CPAN to apply patches (such as #29468, IPv6 in Net::HTTP) Ivan Shmakov <oneingray@gmail.com> - 2013-06-28 19:48 +0000

csiph-web