Like this article? We recommend

Like this article? We recommend

The vampire bot discussed in this article writes files to the user's
hard drive. If the bot is implemented incorrectly, damage may result and data
may be destroyed. Proceed with caution.

Vampire bot is a term we made up for programs that "drain"
content out of web sites. We use vampire bots and the C# programming language as
a backdrop for teaching you code improvisationa semi-structured technique
for developing code when you program recreationally.

Level: Advanced Beginning Programmer

Assumes that the reader has written at least one C++ or Java program and is
comfortable with the syntax for methods and classes. Also assumes that the
reader has successfully installed the Microsoft .NET Framework SDK (see InformIT
Visual Tutorial 6). You can find the SDK
here.

Introduction

Programming is one of the most enjoyable and rewarding of mental activities.
As a programmer, you are an information or "computational" artist (see
note)taking reality or imagination and expressing it on an electronic
canvas for others to use or enjoy. And like any artistic endeavorwhether
painting, music, or even a martial art such as judoit takes a long while
for a practitioner to become proficient. But people keep at it because, as
they're learning (and this is very important), they can see or experience
results that are both immediate and significant. This is where
programming differs from the other arts. A novice programmer experiences more
frustration than results, in the form of compilation errors and execution bugs
(to name a few). Moreover, in learning to program, the novice is given
programming tasks that are probably not very interesting. So it's not
surprising that many people don't become proficient at programmingor
even bother learning to program.

NOTE

Some programmers take offense at the notion that what they do is art,
instead preferring to view it as engineering. But the two terms are not
mutually exclusive when you look at programming in terms of product and process.
The product of programming can be viewed as a piece of artan
individual or group's unique expression of an idea or specification. The
process that programmers use to create the product can be (software)
engineering, such as object-oriented analysis and design, or the process can be
more freehandjust sitting down and typing code "off the top of your
head."

To alleviate these problems, we take a software archetype approach to
teaching programming to beginners. Beginners don't learn by just building
programs from scratch; instead, we give them useful working programs and have
them modify these programs to suit their specific needs. Now, although we give
beginners working programs, these programs typically just implement some basic
function in the most straightforward manner possible. Beginners have to modify
these archetypes by enhancing functionality, adding error handling, and coding
more efficient algorithms, just to name a few. In our experience, by modifying
these archetypes to suit specific needs, a beginner internalizes the knowledge
needed to create them in their entirety.

Finally, all the practice in the world won't amount to much if your
technique is inefficient. When programming recreationally and when modifying
archetypes, beginners have a tendency to code kludgespoorly-fitting code
pieces that are difficult to debug and understand. So, in addition to the
software archetype approach to teaching programming, we also teach beginners a
semi-structured methodology known as codeimprovisation for
developing new programs and also for understanding existing ones. For people
learning how to program and for those programming recreationally, code
improvisation keeps design activity to just the bare minimum and implementation
at the forefront, which helps keep programming fun. Now, before the software
engineering design purists get upset, note that we aren't advocating using
code improvisation for industrial software developmentjust for
recreational software of small and medium complexity.

In this article, the software archetype that we'll discuss is a basic
vampire bota term we developed for a program that drains content
from other web sites. As the vampire bot is an archetype, it only downloads GIF
files from a single web page. It's your task after completing this tutorial
to modify it to download other image types and to crawl across multiple web
pages as well as add the error-handling code to make it robust. The key code
blocks (motifs) needed to do so are contained within the archetype, if
you understand how it works. Before going over the vampire bot's
implementation, let's first discuss code improvisation.