Pet Peeve: People who use Math Notation to explain Programming.

Sure, I get that many programming things have a mathematical backing underlying their working. But do we have to have Math notation that only MathGeeks understand? Especially on Wikipedia?

I mean, there's a mathematical equation ( or equations ) backing you walking to the shop, but to explain walking to the shop I really really do not want to have to take several university papers to get there.

What practical purpose could there be to using it on Wikipedia?

Its not at all immediately accessible to anyone who is a programmer trying to understand the programming concept explained

Its even less accessible to anyone who is neither a programmer or a math-geek, and face it, they're the majority of the people out there.

I'd love to understand Canonincal LR Parsers, but the whole concept flys right out the window within 3 lines of that page at that lovely asinine:

 [ A → B • C, a ]

Sure, I probably learnt that syntax at some stage aeons ago, but gosh, I don't have a clue what it means now, nor is there any way for me to know what that is even talking about in order to search for it

Ironically, theres another little problem which makes using math notation completely pointless, is there's many operations that are simply impractical to use math-notation for, and people resort to using programming notation:

action[k, b] = "shift m"

and that, just makes matters worse, because that notation seems completely incoherent with the rest of it.

So is it stupid?

... or is it just me


Funniest Phishing Scam Ever.

Today I just received the funniest phishing scam I think I've ever seen. They're claiming to be paying out to victims of scams!. Awesome!.



This is to bring to your notice that our bank (ECOBANK INTL. PLC) is
delegated by the ECOWAS/UNITED NATIONS in Central Bank to pay victims
of scam $500,000 (Five Hundred Thousand Dollars Only).

You are to send the following informations for remittance.

Your Name.___________________________
Phone .___________________________
Amount Defrauded.___________________________

Send a copy of your response with the PAYMENT CODE

     ECB/06654 $500,000 USD.
     TEL: +234 7025669085

Email: scamvictimstransfer_2010@yahoo.co.jp

Yours Faithfully,
Mrs. Rosemary Peter
Copyright 2010

I bet you Won't Guess what the country that phone number is for.

Introducing Data::Handle

Comming to a mirror near you, soon, is Data::Handle.

What does Data::Handle do?

Data::Handle solves 2 very simple problems that occur with the __DATA__ section and the associated *DATA Glob, and both of them are to do with "multiple modules trying to access the section".

1. Provide a reliable way to get a file-handle with the position at the start of the __DATA__ segment

  1. *DATA is really a pointer to the entire file, and not just the data segment
  2. The Perl interpreter sets the current position in the file to be after the __DATA__ line

The first time you read from *DATA this of course works fine, but the issue is once you read it, it moves the internal file cursor, and if you read the whole section, after the first complete read, the cursor now points to EOF. For a second block of code to re-read this data without communicating with the first block of code, it has to then rewind the file cursor back to the start prior to reading, and there is no way naturally to know where that point to rewind back to is.

Other modules so far have remedied this by trying to rewind to the start of the file, and manually emulate various parts of the Perl Parser to re-find the start of the __DATA__ section before re-reading its contents.

This module however takes a different approach, and assumes that hopefully, the first person to read that file handle will know what they're doing, and use this module to do it. This module will then record the file offset the __DATA__ section began at, so from that point onwards, rewinding to the start is a trivial exercise.

And all this happens for you simply by you doing :

my $handle = Data::Handle->new( __PACKAGE__ ); 

instead of doing

my $handle = do { no strict 'refs'; \*{ __PACKAGE__ . "::DATA"} };
. ( Note: Side perk, the new syntax is simpler, more straight forward, easier to remember, and no dicking around with strict! ;D )

2. Provide a reliable way for 2 separate logical code units to access the same __DATA__ segment without interfering with each other

Because *DATA is a filehandle, and there is only one of them, seeking around in it can be problematic.

Especially if you have 2 code units that are trying to read it from different places. For a contrived example, prior to this module if you wanted to go back and re-read the start of the section, or skip forwards and read something later in the section, without forgetting where you are now, you'd need a contrived dance of seek/tell. Instead, now, you can just create another worker that will read that stuff for you, and the original handle will retain its position.

my $handle = Data::Handle->new( 'Foo' );
while( <$handle> ){ 

   if ( $_ =~ /something/ ){ 
       # get line 1. 
       my $slave = Data::Handle->new('Foo');
       my $firstline = <$slave>;
   # continue as normal.

Internally, there is a lovely dance of Seek() going on there, but from an interface perspective, you don't need to know its seeking, all you need to know is "Get reference to DATA, get data from it".

Sure, you can probably argue you could do it easily with lots of seek() in a nice way, but that logic falls apart when you have code in 2 separate places reading the same *DATA.

Its much smarter to be defensive about it, and have some assurance that you can read a file descriptor in a safe way without something evil like this tampering with it.

my $handle = do { no strict 'refs'; \*{ __PACKAGE__ . "::DATA"} };

sub evil_function { 
  my $handle = do { no strict 'refs'; \*{ __PACKAGE__ . "::DATA"} };
  seek $handle, 0, 3; # seek to EOF.

That is spooky action at a distance!

Data::Handle solves this by meticulously tracking position in each instance, and re-seeking the file handle to the place it was at the end of the last tracked read, so regardless of how much seeking around some other module did, as long as you got on the scene first, you should be unstoppable ;)