ImageMagick

ImageMagick is a cool toolkit; not only it’s a complete set of command-line applications, ported to Windows, Mac and Linux, supporting hundreds of different image formats, it’s also a C++ library that you can use in your own applications!

On Mac OS X, I installed it via MacPorts using the all-time classic:

sudo port install ImageMagick

Then I created a C++ command-line application with Xcode, set the header and library paths in the target properties (/opt/local/include/ImageMagick and /opt/local/lib in this case) and I was ready to code. The API documentation and the tutorial give some hints, and using those examples I’ve cooked a quick image transformation utility to play with:

[source:c]

include

using Magick::Image; using Magick::Geometry; using Magick::Blob;

int main (int argc, char * const argv[]) { Blob blob;

Image png;
png.read("pic.png");
png.write(&blob);
Image jpg(blob);
jpg.magick("jpg");
jpg.zoom(Geometry(100, 200));
jpg.write("newpic.jpg");
Image tiff(blob);
tiff.magick("tiff");
tiff.zoom(Geometry(3000, 84000));
tiff.write("newpic.tiff");
Image gif(blob);
png.magick("pdf");
png.write("newpic.pdf");
return 0;

} [/source]

Interesting stuff indeed! The API provides a complete set of “Photoshop-like” operations on images, which I plan to study further in the near future.

On the Need of Minimalist Polyglots

Many companies, at some point of their history, ask themselves a simple question: what programming language should I use? The answer to this question is tricky, and has big, big consequences, for every single line of code of your future products will be written, read and suffered by it. This single choice defines the level of salaries you will have to pay, the skills of programmers you will have to deal with, the relative length and performance of your systems, the availability of tools (or lack thereof), the kind of support you will get (or not), the number of operating systems your code will work in, etc.

Given the fact that Web Development equals Software Development, this discussion will be of interest to those building the smallest websites, as well as old desktop-intensive apps. It will not be a “Tell me what programming language you use, and I will tell you who you are” type of article, though it may look like one, because that is something you have to figure out all by yourself.

If you take a look at the list of programming languages, any business person would have an instant headache. There are lots of them. With the strangest names. You cannot possibly guess which one to pick from such a list, obviously. So, how do companies choose the languages they use? There are some straightforward methods that I have seen so far, in no particular order:

  • Looking at what other companies use (typically Google, Microsoft, Apple or Sun, but it could be 37signals too).
  • Following the advice of the CIO, the Lead Architect or some other politically-powered person, which might or might not have read this article ;)
  • Looking at what the current pool of programmers in the company know how to use. Rinse, wash, repeat.
  • Following hype.
  • Because there is a market plenty of available, cheap programmers that I could use for this project.
  • Taking into account the characteristics of the languages themselves (static vs. dynamic, etc).
  • Following the company’s history of past projects (successful or not).
  • Following what your the client suggests (or mandates).

I think that it is a very bad idea to take any of the above methods in isolation, without considering other factors. Doing so is a path to self-destruction in the medium to long term, even if you succeed in the short term.

Continue reading

Playing with HTTP libraries

It’s fun to find out how to tackle the same task in different programming languages; in this case, it’s all about doing HTTP requests over a network: fortunately, there are networking libraries in virtually all major programming languages. In my current project, I’m generating wrappers easing the access to the core of the project itself, a RESTful API. This way, developers interested in using the API can just take a wrapper, include it in their projects, and start coding right away. No need to know this (relatively low-level) stuff; just use the API. The wrappers themselves are auto-generated from the API definition itself, but that’s another story ;)

Below there is a sample of the different ways I’ve found to do a network access to a remote server, using HTTP Basic Authentication and a couple of headers, in PHP, Ruby, Python, JavaScript, and even Objective-C! I’m even generating ActionScript 3.0 code, but I’m not a Flash coder :) So I’ll post the wrappers that work best at the moment, and in the future I’ll include other examples, particularly for .NET, C++ and Java.

In all the cases below, there is a “request” function or method that takes an HTTP verb (GET, POST, PUT, DELETE, etc), a URL (without the slash “/” at the beginning) and some parameter data, in the form of a dictionary. The function wraps the underlying libraries of each programming language, offering a simpler interface, and allowing for HTTP Basic Authentication (for HTTP Digest Authentication it would be much, much more complex!). There are synchronous (useful for server or command-line applications) and asynchronous versions (for GUI systems). Off to the code! Continue reading

Null References

There’s an interesting discussion going on these days on Ruby blogs about, basically, how to avoid one of the most common, annoying, easy-to-create bugs in any programming language: calling a method on a null reference (or pointer, depending on your language).

This single issue happens all the time, in garbage-collected and non-managed languages, static and dynamic, weakly and strongly typed; you have a handler variable “pointing” to an object, and before calling any methods on it, you’d better be sure that the object is there; you end up using assertions, “if” statements (and all of its variants), boilerplate code all over the place, when everything you want to do is to call that damn method. It’s frustrating, time-consuming and oh so common that we just try to not to think about it anymore. Continue reading

Programmers are draftsmen

Interaction08: IxD’s in Savannah; Alan Cooper:

Programmers are draftsmen. However, they are different than pre-industrial workers. They are self-directed and know better than managers what to do. They respect intelligence, not authority. You can’t tell them what to do, you can only coerce them. Their satisfaction comes from the quality of their work. Unlike pre-industrial craftsmen, post-industrial craftsmen are smarter and more highly trained, even in the higher levels of management where they work. This creates a conflict because management is industrial. It’s based on command-and-control. It’s tracked quantitatively through cost accounting, based on the idea that you purchase raw materials and you purchase labor that transforms those materials into offerings, and you scale up with factories, and that’s how you profit. That simply doesn’t exist in the world of software.

The Truth Be Told

Reg describes 99% of all available programming jobs with incredible sincerity:

You do a clerk’s job, you settle for a clerk’s working conditions and wages, but you take solace in the thought that you are somehow more than a clerk, because you have a university degree and the dental technician who cleans your teeth doesn’t. Only everyone knows it’s a sham, especially the hiring manager who puts “University degree required” in the job advertisement. He wants to hire a clerk, someone who will work long hours doing as they’re told in a top-down, hierarchal command structure. Does that job sound like there is any Science involved? Of course not, everyone knows that, it’s why the industry is trying to weed all of the Science out of a Computer Science degree.

I do not have a university degree. Heck, I started university 4 times and finished none (Physics, Economics, Marketing and even Computer Science! :) I have been refused jobs because of this (particularly at the beginning), but I have been given jobs because of this too (particularly lately). Having some experience in your CV pays off; the hard thing is to start without that “paper”.

As a matter of fact, I’m doing an online Master’s degree right now, which I will finish this year, and I’m actually quite happy to have started. I’ve been able, in the past two years, to read books and papers that I had not heard about; I could understand some underlying issues in Software Engineering, both from technical and social points of view; I can understand more, I can learn more.

But, the truth be told, I’m also doing it to have that “paper” hanging on the wall. I know it’s silly, but I want to take that step too, and that’s why I’ve changed careers so many times. However, that is a secondary thing for me: what I am looking is something else altogether; a bit of guidance in my own learning path. I have followed an unusual way in my career, and looking backwards I’m happy to have done that (mind you, it was not at all consciously!). That’s why the 6 books and the new programming language every year. It’s all part of the same pattern.

Of course, this has worked out for me, and your mileage may vary. I know excellent developers both with and without degrees, and also horrible professionals with and without them. Some people need a physical teacher in front of them, while I prefer to learn alone.

A degree, like any decision that you take in life, should mean something to us, and in that sense, I find Reg’s arguments enlightening.

Erlang

As I said before, I like to learn a new programming language every year. I also like to read at least 6 computing-related books every year, but the article about those 6 will come later.

The reason for these two rules is twofold: first, it gives me lots of material to blog about, and helps me refine my list of preferred languages :) secondly, and more seriously, learning a new programming language makes you think differently about problems. It’s not just something to keep my CV updated; it’s to challenge what I know, how I know it, and why I know it. It is important, and it’s not easy; and I’m not the only one to do it.

From all the candidates that I had for this year, I chose to learn Erlang. Here’s some of my impressions. Continue reading