I like Perl and I like C (most of the time), and sometimes I like to mix the two. The two main reasons I might want to mix the two is for performance, or because something is written in C which I would like to use from Perl. I’ve only really ever used C from Perl, I’ve never used Perl from C. Today’s demonstration is how to implement a simple binary search algorithm in C, but using Perl internals, and calling the algorithm from Perl. Continue reading “Gist of the Day: Inline::C in Perl”
Continue reading “Gist of the Day: Automated Testing With CUnit”
Have you ever struggled with how to structure your class hierarchy, given a common type of functionality which applies to some classes but not others? Say for instance you have a class named
Animal. With this
Animal class you can derive all of your animal classes. Take for instance a chicken, for which you subclass
Animal to a class you call
One of the features you’d like to implement is that an animal makes a noise. Chickens, for instance, cluck. Some animals, however, don’t make a noise. Take a seahorse for instance, it doesn’t make noise. It is every bit an animal, but it doesn’t make noise. There are many other mute animals across many different families of animals, so it doesn’t really seem to fit in to your hierarchy. For this purpose, you can use a Role in Moose. A role allows you to dynamically add functionality to an existing Moose class (as many of them as you like) without having to mangle your nice, clean class hierarchy. Think of it as a grab-bag of functionality for your class which can also be used by other classes regardless of their parentage.
So, way back when I used to be a guy who thought up interview questions for super-senior Perl developers. I actually developed quite the reputation for being a very effective first-round interview for senior Perlers. My interviews were perceived to be so tough that headhunters would debrief the candidates so they could create cheat-sheets. I never considered my interviews very difficult at all. Despite the fact that very few of the candidates passed my first round, none of these questions seemed very difficult to me. Mind you, the client I was interviewing for wasn’t looking for someone who was a good programmer, they were specifically looking for a good Perler (a very good Perler). It is important for interviewers to ask questions relevant to the job they are hiring for, and if you have a legacy application which is using a lot of the in-depth features of a language then that language may become something very important to your hiring.
This is one of those “gotcha” questions that I actually had a recruiter try to call BS on me with, and I think it’s a fundamental one since it really reflects whether or not you understand how modules work in Perl:
What is the difference between
require in Perl?
Hey all, so I’ve been asked to do something a little more in-depth, and I’ve been given no requests, so I picked closures in Perl.
A closure is a function which was created dynamically inside of another function. In Perl (among other languages), these are sometimes referred to as anonymous subroutines. In Perl, all closures are anonymous subroutines, but not all anonymous subroutines are closures. The key differentiating feature is scope: a closure has access to lexically-scoped variables within a containing subroutine, whereas an anonymous subroutine is not necessarily even inside of a function. Continue reading “Gist of the Day: Perl Closure Extravaganza!”
So I’m trying to learn Python, as you know. I’m also trying to practice algorithms a bit more. Today you get a self-balancing binary tree in Python.
I’ve used unittest in order to prove the implementation, too.
Here’s the Gist: https://gist.github.com/manchicken/6391864
Continue reading “Gist of the Day: Self-Balancing Binary Tree in Python”
I’m not feeling awesome right now, but I still owe you a gist for the day. This one I did about a fortnight ago, it’s a circular buffer implementation.
Here’s the gist: https://gist.github.com/manchicken/6238117
Continue reading “Gist of the Day: Circular Buffer”
So, it’s been a while since I looked at the perldelta (yes, I know that makes me a terrible human being). I found some neat toys to play with, I thought you might like to see. It’s just a simple script so far, but I’m going to add features as I find them. Check it out.
So far I have only toyed with state variables and named capture buffers in regular expressions, but there’s a whole bunch of neat stuff.
Please also note that the FuckDiabetes website code is already on my GitHub, and it is already using a whole bunch of new Perl ideas, such as Mojolicious, Moose, and Mongoose (MongoDB and Moose together kinda like an ORM). You can find FuckDiabetes’ code here: https://github.com/manchicken/FuckDiabetes (please note that FuckDiabetes is not yet live).
My spirit animal as an animated GIF – The Oatmeal.
(The Oatmeal, I love your stuff. If you don’t like me linking to your stuff please let me know and I won’t post it)
So, I’m trying to learn Python better. Here’s me just doing a simple threading exercise with an anonymous function in Python. I am imitating a Perl Gist I did before with the exact same logic.
Here’s the Gist: https://gist.github.com/manchicken/6369630
Continue reading “Gist of the Day: Threading in Python”