A day of random ups and downs

An interesting day I feel, with several interesting ups and downs, so several cuts to avoid spamming people.

This one should cause experienced Perl types to say “Well yes?” and everyone else to say “Who the hell writes documentation with that side effect!”

For everyone else, read the comments (everything after a #) to follow the fun along.

# Create a new function called "foo" that takes a single argument.
sub foo { 
        my $bar = shift or die $!;   # Shift the argument off the stack of arguments for this invocation
        print "$barn"; # print the argument you just shifted, followed by n, a new-line

foo(1); # will print "1"
foo(2); # will print "2"
foo(3); # will print "3"
foo(0); # Should print "0"

print "finishedn"; # will never be reached.
exit 0; # finish as normal.

This code will print 1, 2, 3 (all on seperate lines) and then die before it can print 0 or “finished”. Explanation below:

See now heres the issue, when you “shift or die” what your basically doing is something equivilent to:

my $bar = shift;   # Take the first arg from @_ (the array of args) and put it into $bar
if (!$bar) {  # If $bar is false then...
        print "Error $!n";   # print Error, followed by $!, the last error generated.
        exit 1; # Exit with status 1, i.e. something went wrong.

Because its evaluating the boolean truth of: ( my $bar = shift )

So if you ever pass 0 as an argument to a function, and are using “shift or die” your program will die because according to the Perlish definition of truth 0 is false (“” (empty string) is also false, pretty much anything else is true).

Now there are ways around this, but ALL THE DOCUMENTATION pretty much uses this method, and even the holy Camel‘s chapter on subroutines doesn’t say “Hey now, think about this whole “shift and die” thing we’ve been pushing all this time, think what it does in boolean logic, now think about what truth means in Perl, this was covered in chapter 2 or so, you should have spotted this by now.”



At this point I left work and hiked across campus to hit the bus, to get home in time to grab some food before heading back to PaganSoc (yes I was in a rush). As I walked out past Pendle a lovely effect made me pause and chill, theres a bit hill off to the East of campus and a series of small farms and houses. I’d noticed them looking quite sunny earlier but now they were all painted golden thanks to a lovely Sunset :) Most enjoyable, first time I’ve seen that this year.

When I got home, still feeling kinda stressed from work I had a conversation with a chap I know online in which I learnt about the existence of the film It’s My Party which unsurprisingly depressed the crap out of me (even though the ending is apparently ‘touching’ I think I’d need to watch it with someone to hug and a big box of tissues).

After that miserableness I got cheered up by an enjoyable talk at PaganSoc about the varied and strange origins of Wicca, in which the various strands were unravelled in the normal manner, but a number of interesting points, people and books fell out of this unravelling that I’d not heard of before, as well as interesting points of views on it all. Groovy.

That was followed by a pleasent conversation in the pub that then got into a random, circular ramble with some drunken and philosophic types who had been bumped into by Mr Six earlier, much fun, just what I needed to unwind really.

Oh and before I forget I have pretty new boots! (well okay these are matt black boots, but what the hell they don’t leak).

In other news I’m having my arse handed to me at Go. I thought I’d be alright (I’m playing Black) by responding to B16 with C16, then White played B15. I played B14, thinking that then if White played A15 or B17 I’d be able to kill them in nice shape. White played A15 and I re-read, thinking I was doomed, I played a cunning throw in at A16 hoping to trap them… and then realised I’d played as such to make White make the Bulky Five Nakade shape.

So now I think I’m stuffed.

It makes more sense if you look at the link, or indeed play it out in front of you. I’m pondering connecting the two stones at the top and trying to abuse my external liberties, but I fear my group is dead, and quite possibly with it the game.

Still you gots to laugh ain’ts ya?

p.p.s. Heres some MLP for you, I don’t agree with the conclusions but it is a wonderfully written piece of work, so I hope you appreciate it (since I dragged it up from archive.org for Maggot):

Why I became an Emacs user

You may not be interested in tech but feel the love for the ideal behind the editor shine through the text. It reminds me of In The Beginning was the Command Line (see here for an HTML version).

These are the kinds of things that make you remember why you enjoy tech so much :)

Leave a Reply