Coding Away http://www.codingaway.com Philosophy for Programmers: Code, Technology & Stuff. Mon, 12 Feb 2007 04:35:31 +0000 http://wordpress.org/?v=2.1.2 en A Trick to Render Outlined Text http://www.codingaway.com/2007/02/11/simple-trick-to-outline-a-font/ http://www.codingaway.com/2007/02/11/simple-trick-to-outline-a-font/#comments Sun, 11 Feb 2007 21:36:42 +0000 Lorenzo http://www.codingaway.com/2007/02/11/simple-trick-to-outline-a-font/

In the last few years I found myself in need to render a font outlined to increase readability or to comply with UI requirements.
In both cases I had a non-outlined font, I had no choice of picking a different one, and I had to render it outlined.

To give you example, I had to render a font like this:

fontnormal.jpg

Outlined, like this:

fontoutlined.jpg

If you are not too concerned about rendering speed (in my case, it wasn’t an issue), the trick I used to accomplish this is astonishingly simple, and very effective. You just need to render the font 5 times in different positions; 4 times with the color of the outline, and one time with the color of the body of the text.

Assuming that you want the body of the text starting at position (x,y) on the screen, the algorithm is:

A) Select the outline color.
1) Draw the text at (x+1,y)
2) Draw the text at (x-1,y)
3) Draw the text at (x,y+1)
4) Draw the text at (x,y-1)
B) Select the font body color
5) Draw the text at (x,y)

Here is an example of the results you get after each draw, numbered as in the above steps. In the example the color of the outline is BLACK, and the color of the body of the text is RED. I also added a background with a color similar to color of the body of the text, to show how outlining can increase readability in cases where you don’t know what the color of the background is (like in cases where the background could be any image).

fontdemo1.jpg

To make it even clearer for you I did the same thing but this time I rendered the body of the text in gray after each steps 1,2,3 and 4. This way it becomes very clear how the outline is constructed, with each draw, around the body of the text:

fontdemo2.jpg

In Java, a very simple example of a method that does exactly what described looks like:

public void drawTextOutlined(Graphics g,
                            String text,
                            int x, int y,
                            Color cOutline,
                            Color cBody) {
   g.setColor(cOutline);
   g.drawString(text, x+1, y);
   g.drawString(text, x-1, y);
   g.drawString(text, x, y+1);
   g.drawString(text, x, y-1);
   g.setColor(cBody);
   g.drawString(text, x, y);
}

Variations:

This method of outlining can be used with pretty much anything that you can render in a given color; it doesn’t have to be only text. In some cases it can even be expanded to images. It’s somewhat of a long story, but if anybody cares I can post about that as well.

There are also many variations based on the same concept. For example you can draw the outline rendering the text in the outline color at positions (x+1,y+1) (x+1,y-1) (x-1,y+1) (x-1,y-1) with similar results. You can also try drawing the outline with only two renderings of the text in the outline color, at positions (x+1,y+1) (x-1,y-1) or (x-1,y-1) (x+1,y+1), saving two text renderings and obtaining OK results in most cases.

I prefer the variations presented here, which gave me the best results in the situations I had, but feel free to experiment. There are cases where different variations might give you better results.

Hope you’ll find this helpful.

]]>
http://www.codingaway.com/2007/02/11/simple-trick-to-outline-a-font/feed/
Developers, a Terrible On-line Advertisment Target. http://www.codingaway.com/2007/02/06/developers-a-terrible-on-line-advertisment-target/ http://www.codingaway.com/2007/02/06/developers-a-terrible-on-line-advertisment-target/#comments Wed, 07 Feb 2007 04:09:18 +0000 Lorenzo http://www.codingaway.com/2007/02/06/developers-a-terrible-on-line-advertisment-target/ I’d like to share some numbers that I gathered during a little experiment I just ran regarding the effectiveness of on-line advertisement targeted to the Software Developer’s community compared to other niches. This article obviously doesn’t represent an exhaustive research. It is just the report of one single experiment that provides very interesting results.

As you can probably imagine, on the Internet there is a great deal of traffic generated by developers and geeks surfing for information or cool stuff. That’s not hard to believe considering how much time developers spend in front of a connected computer, and given that the Internet is possibly the only “book” they really need (well, a book full of amazing errors and faulty opinions, but still a pretty good book if you know what to look for).

Anyway, I have several Blogs that I maintain, this one being the last one I opened. To pay my hosting bills I usually put some light Google Adsense ads which is usually just enough to pay for the hosting expenses. I do not care of making money with ads, but I like the idea of not having to pay for providing a service to my readers. AdSense allows me to at least Blog without having to pay for it but still choose a domain name and retain full control on the site, configuration, software, etc.

To verify something that I really already knew, I ran a little side-by-side experiment using two articles that I was going to publish anyway. One I published on this Blog a couple of days ago, and one published on a different Blog with a very different type of readership.

The article on this Blog was about an algorithm to find loops in a linked list. The topic is obviously targeted to software developers. It gained some interest in the active on-line development community and ended up on the main page of programming.reddit.com for a couple of days, receiving about 3,000 hits / day, most of them being unique visitors. On the article I placed a small Google ad at the very beginning.

The other article was on a completely different subject: dream interpretation and sleep patterns. Yeah, I have many interests in different areas :) The ”dreams” article also featured a Google ad placed in the exact same area as the linked list one. I guess people like to sleep because it received very much interest and traffic. It was positively reviewed and linked by a very well known MD offering on-line health advice, and received just about ~3,500 hits / day, most of them from unique visitors.

The lucky part was to receive a very similar amount of traffic on two completely different articles. In both cases the traffic started abruptly due to a link, and in both cases the article featured a very similar ad size and placement. To be noted that the coloring of the Blogs, the contrast between article and ad and everything else are also very similar.

How much do you think each ad campaign generated with traffic of about 3,000 hits/day?
Take a quick guess!

The article about dream interpretation and sleep patterns generated about $10.00, with a click ratio of about ~3.5%.

Are you ready? The article on linked lists generated 1 single click (yes, ONE), which is the equivalent of a few cents, or pretty much 0% click ratio.

I knew that as a group we (developers) are pretty difficult customers, but I didn’t think it was that bad! If you are a developer, you may find these results obvious. However, I ensure you that most people, especially marketing and business folks, do not understand developer’s psychology very much.

My suggestion for the reader is: if you are really thinking of generating revenue with on-line ad campaigns targeted to developers, do some research! You may change your mind :) In fact, I almost guarantee that you will.

]]>
http://www.codingaway.com/2007/02/06/developers-a-terrible-on-line-advertisment-target/feed/
A Turtle and a Rabbit to Find Loops in Linked Lists http://www.codingaway.com/2007/02/04/a-turtle-and-a-rabbit-to-find-loops-in-linked-lists/ http://www.codingaway.com/2007/02/04/a-turtle-and-a-rabbit-to-find-loops-in-linked-lists/#comments Mon, 05 Feb 2007 06:22:47 +0000 Lorenzo http://www.codingaway.com/2007/02/04/a-turtle-and-a-rabbit-to-find-loops-in-linked-lists/

One of the challenges that from time to time you may find is a program that has to deal with a linked list having a loop.

While this is not a very common situation, it can happen, desired or not, as result of a bug, the particular usage of the linked list in the program or corrupted data.

A classic example of such situation caused maliciously by viruses, is the case of directory loops in the old DOS. As in many other OSs, in DOS directories where nodes of a tree; each node, or directory, had a pointer to each of its sub-directories. A single path such as “C:\a\b\c\d\e” could be seen as a linked list a->b->c->d->e. This is not uncommon, but one thing was particularly bad in DOS 3.1. Nothing in the system was able to deal with directory loops, no even the most advanced utilities.

If you took a disk editor and connected a directory, say “e”, with anything on an upper level, say “b”, you’d cause serious issues. No utility at the time was able to catch such an issue, which was guaranteed to crash any directory crawling program, including CHKDSK. You could keep re-entering the loop ending up with a path like “C:\a\b\c\d\e\b\c\d\e\b\c\d\e”. Some old viruses took advantage of this weakness to create all sort of troubles.

Anyhow, how do you write an algorithm to find out if a list has a loop? Usually people tend to go for a solution like traversing the list, marking each node as they go and, if they found an already marked node, than there is a loop. That solution works, but once you are done you have to clear that mark on all the marked nodes. In some cases this might not be desirable or even possible.

I’d like to present a small cleaver algorithm that detects loops in a list without having to alter the list in any way. I like to call this algorithm “The Rabbit and The Turtle Algorithm”, but I wonder if it has another name (does it?)

The idea is simple: you use two runners (pointers) to traverse the list. One moves one step at the time (turtle), and one moves two steps at the time (rabbit). The two keep running until the rabbit finds the end of the list, or until the rabbit passes the turtle. If the rabbit arrives at the end of the list, there is obviously no loop. If the rabbit passes the turtle, than there is a loop.

Simple, isn’t it? Here a simple implementation in Java:

// ListNode is the type of a node.
// head is a ListNode, head of the list.
// If node is of type ListNode, node.next is
// the pointer to the next element in the list.

01: public boolean hasLoop() {
02:
03:    if ((head == null) ||
04:        (head.next == null)) return false;
05:
06:    ListNode lnT = head;        // Turtle
07:    ListNode lnR = head.next; // Rabbit
08:
09:    while ( true ) {
10:       if ( lnT == lnR )
               return true;
11:       if ( (lnR = lnR.next) == null )
               return false;
12:       lnT = lnT.next;
13:       if ( lnT == lnR )
               return true;
14:       if ( (lnR = lnR.next) == null )
               return false;
15:    }
16 }

Lines 03-04 deal with the cases of (1) an empty list and (2) a list with only one node. In either case there is no loop for sure.
Lines 06-07: talk about injustice! The rabbit starts in front of the turtle already.
Line 10: checks if the rabbit encountered the turtle. If it did, we found a loop.
Line 11: Moves the rabbit forward one step. If the rabbit reached the end of the list, no loop exists.
Line 12: Moves the turtle forward.
Line 13: If the rabbit found the turtle, we have a loop!
Line 14: Moves the rabbit an extra step forward. If the rabbit reached the end of the list, no loop exists.
Line 09: Repeats until one of the conditions above is satisfied.

Hope this is useful.

]]>
http://www.codingaway.com/2007/02/04/a-turtle-and-a-rabbit-to-find-loops-in-linked-lists/feed/
When You Miss The Case http://www.codingaway.com/2007/01/31/when-you-miss-the-case/ http://www.codingaway.com/2007/01/31/when-you-miss-the-case/#comments Thu, 01 Feb 2007 05:27:29 +0000 Lorenzo http://www.codingaway.com/2007/01/31/when-you-miss-the-case/ One rainy day you write some code in C++, and compile it with no errors. It might just work, you hope. You run it and it just doesn’t do what it should be doing. You debug it, look at it, think about it, tweak it… but… nothing! You try to understand. The code is there. Only a few lines, doing something that doesn’t seem right.

[Am I going mad?]

typedef enum
{
	FIRST_ONE,
	SECOND_ONE,
	THIRD_ONE
} T_states;

int main()
{
	T_states x=FIRST_ONE;

	switch(x)
	{
		FIRST_ONE:
			printf("First one! Yeah.n");
			break;
		SECOND_ONE:
		THIRD_ONE:
			printf("Second or third one?n");
                        break;
		default:
			printf("None of them!n");
                        break;
	}
	return 0;
}

…you find yourself kneeling down in front of your desk with your fists ready to smash the screen… then… with your amazement… you figure it out… you completely missed the case… Bad words associated with the compiler pop to mind.

There are mistakes that you never made, and that you’d never think you would make. When you do make them, you just don’t see them, because everything looks so innocent and normal… except… that you missed the darn case…

Yep, the code above compiles just fine. No errors, at least not with VS and with another embedded compiler I’ve compiled it with. In fact, it is perfectly syntactically valid code. Evil, but valid.

When you run this code it prints “None of them!”. Yep. You missed the case!!!! (the “case” keywords before the constants inside the switch).

The compiler takes “FIRST_ONE”, “SECOND_ONE” and “THIRD_ONE” as goto labels, and doesn’t complain. Everything compiles. Obviously when you run it, the execution runs straight to the default case.

Never miss a case, especially when you are tired!! :)

]]>
http://www.codingaway.com/2007/01/31/when-you-miss-the-case/feed/
Is Swap Without Temporary a Good Idea? http://www.codingaway.com/2007/01/31/is-swap-without-temporary-a-good-idea/ http://www.codingaway.com/2007/01/31/is-swap-without-temporary-a-good-idea/#comments Wed, 31 Jan 2007 21:02:18 +0000 Lorenzo http://www.codingaway.com/2007/01/31/is-swap-without-temporary-a-good-idea/

The classic way of swapping to variables uses a temporary variable. In C++ it looks something like:

void swap1(int &a, int &b)
{
     int c=a;
     a = b;
     b = c;
}

Some developers can’t stand that they need a temporary variable to make the swap, and prefer to write:

void swap2(int &a, int &b)
{
     a ^= b;
     b ^= a;
     a ^= b
}

Assuming that a and b are pointing to different memory locations, this actually works.
It is based on the fact that [ (a^b)^a = b ] and [ (b^a)^b = a ]

While this seems like a cool trick, is it really worth writing it? Or should you stick with the classics?
I say it is not worth it! Stick with the classics!!!

In fact:

It is slower

swap1 requires 3 assignments.
swap2 requires 3 XORs and 3 assignments.

If you are not convinced, here is the assembly generated by VS for swap1 (you get similar results with gcc and other compilers):

6:    void swap1(int &a, int &b)
7:    {
00401030   push        ebp
00401031   mov         ebp,esp
00401033   sub         esp,44h
00401036   push        ebx
00401037   push        esi
00401038   push        edi
00401039   lea         edi,[ebp-44h]
0040103C   mov         ecx,11h
00401041   mov         eax,0CCCCCCCCh
00401046   rep stos    dword ptr [edi]
8:        int c;
9:        c = a;
00401048   mov         eax,dword ptr [ebp+8]
0040104B   mov         ecx,dword ptr [eax]
0040104D   mov         dword ptr [ebp-4],ecx
10:       a = b;
00401050   mov         edx,dword ptr [ebp+8]
00401053   mov         eax,dword ptr [ebp+0Ch]
00401056   mov         ecx,dword ptr [eax]
00401058   mov         dword ptr [edx],ecx
11:       b = c;
0040105A   mov         edx,dword ptr [ebp+0Ch]
0040105D   mov         eax,dword ptr [ebp-4]
00401060   mov         dword ptr [edx],eax
12:   }

While for swap2 the assembly generated by VS is:

14:   void swap2(int &a, int &b)
15:   {
00401080   push        ebp
00401081   mov         ebp,esp
00401083   sub         esp,40h
00401086   push        ebx
00401087   push        esi
00401088   push        edi
00401089   lea         edi,[ebp-40h]
0040108C   mov         ecx,10h
00401091   mov         eax,0CCCCCCCCh
00401096   rep stos    dword ptr [edi]
16:        a ^= b;
00401098   mov         eax,dword ptr [ebp+8]
0040109B   mov         ecx,dword ptr [ebp+0Ch]
0040109E   mov         edx,dword ptr [eax]
004010A0   xor         edx,dword ptr [ecx]
004010A2   mov         eax,dword ptr [ebp+8]
004010A5   mov         dword ptr [eax],edx
17:        b ^= a;
004010A7   mov         ecx,dword ptr [ebp+0Ch]
004010AA   mov         edx,dword ptr [ebp+8]
004010AD   mov         eax,dword ptr [ecx]
004010AF   xor         eax,dword ptr [edx]
004010B1   mov         ecx,dword ptr [ebp+0Ch]
004010B4   mov         dword ptr [ecx],eax
18:        a ^= b;
004010B6   mov         edx,dword ptr [ebp+8]
004010B9   mov         eax,dword ptr [ebp+0Ch]
004010BC   mov         ecx,dword ptr [edx]
004010BE   xor         ecx,dword ptr [eax]
004010C0   mov         edx,dword ptr [ebp+8]
004010C3   mov         dword ptr [edx],ecx
19:   }

This should make it clear how swap2 is less efficient than swap1.

Provides no real advantage

The only real advantage is the rush you get from having written a piece of unreadable code using cool tricks.

The fact that you save sizeof(int) bytes on the stack in 99.99% of the cases is not a real good reason to write swap2 instead of swap1. Perhaps it is advantageous in some recursive situation, where every byte in the stack counts and where you don’t want to make an extra function call to a swap function. I’d have to see such code to believe it.

It is not readable

I know. If you wrote it, you know what it does. But what about the rest of the world?
The problem is that for many others swap2 is not going to be readable and it is going to generate only confusion, not amazement.

In the long term it is far better to write readable code than some cool unreadable and inefficient piece of work.

Keep it simple!!

]]>
http://www.codingaway.com/2007/01/31/is-swap-without-temporary-a-good-idea/feed/
Bits And The Power of Two http://www.codingaway.com/2007/01/27/bits-and-the-power-of-two/ http://www.codingaway.com/2007/01/27/bits-and-the-power-of-two/#comments Sat, 27 Jan 2007 10:21:18 +0000 Lorenzo http://www.codingaway.com/2007/01/27/bits-and-the-power-of-two/ Sometimes it is useful to find out if a particular integer represents a power of two. You can find that out with a simple trick.

A power of two in binary is represented by a all zeros, except for a single one. For example 00010000 is a power of two (2^4).
In fact you can calculate the n-th power of 2 with:

int power2(int n)
{
     return (1<

If you subtract one from a power of two, you obtain a number which binary representation is a sequence of ones. Example in binary:

00010000 - 1 = 00001111

If you take this number and perform a logical AND with the original power of two you obtain a flat zero!
Example:

00010000 &
00001111
———
00000000

If you have any other number that is not a power of two, this doesn’t work anymore and you’d never obtain a zero.
For example let’s take 18, which is not a power of two.

18 in binary is 00010010
00010010 - 1 = 00010001

00010010 &
00010001 =
———
00010000

Another example. Let’s take 14 which is another number that is not a power of two:

14 in binary is 00001110
00001110 - 1 = 00001101

00001101 &
00001110 =
———
00001100

In general you’ll find that the result of (X-1)&X always contains at least a one… unless X is a power of two! Cool!

For this simple reason you can find out if an integer is a power of two with something like:

boolean isPowerOf2(int x)
{
    return ((x-1) & x)==0;
}

Enjoy! :)

]]>
http://www.codingaway.com/2007/01/27/bits-and-the-power-of-two/feed/
Leap Year Calculation http://www.codingaway.com/2007/01/26/leap-year-calculation/ http://www.codingaway.com/2007/01/26/leap-year-calculation/#comments Sat, 27 Jan 2007 06:27:53 +0000 Lorenzo http://www.codingaway.com/2007/01/26/leap-year-calculation/ I keep seeing code to calculate leap years implemented with functions like:

bool isLeap_wrong1(unsigned int year)
{
    return !(year%4);
}

bool isLeap_wrong2(unsigned int year)
{
    return !(year%4) && (year%100) ;
}

These are inaccurate because they don’t take in consideration all the rules of the Gregorian calendar adopted by most countries in the world.

In the Gregorian calendar before the year 1600 AD a leap year was defined as follows:

A year is a defined as “leap year” if it is divisible by 4 but not by 100.

After the year 1600 AD the Gregorian calendar was revised and the leap year defined as follows:

A year is a defined as “leap year” if it is divisible by 4 but not by 100 unless it is also divisible by 400.

This definition is destined to be revised in the future (before 2800 AD) since it is still not perfect; however, in your lifetime you should be fine with it and it is currently the official rule.

Based on this definition, the correct “modern” (past 1600AD) way to find out if a year is a leap year is the following:

bool isLeap(unsigned int year)
{
    return !(year%4) && ( (year%100) || !(year%400) )
}

]]>
http://www.codingaway.com/2007/01/26/leap-year-calculation/feed/
Useless Programming Interview Questions: C++ & Arrays http://www.codingaway.com/2007/01/26/useless-programming-interview-questions-c-arrays/ http://www.codingaway.com/2007/01/26/useless-programming-interview-questions-c-arrays/#comments Fri, 26 Jan 2007 20:43:23 +0000 Lorenzo http://www.codingaway.com/2007/01/26/useless-programming-interview-questions-c-arrays/ I can’t help it. I just love the nuisances of C++, and some of the weird things you can write with it.

From time to time I will share some of my favorite examples under “Useless Programming Interview Questions” (UPIQ) category.

Why did I pick this name? Well, the aspects of C++ that I am referring to allow you to write code so strange and unreadable that you’d never do it in real life! Right? The only time you might seriously consider these aspects of the language is if you are a twisted individual asking an useless interview question to a job candidate.

Why do I call these questions “useless”? Because the fact that the candidate knows the answer or not tells you very little about his or her skills. You’d better don’t waste precious interview time in such things. I know it’s fun, but I bet there are much better questions you can ask.

Useless Interview Questions:

Mr.Candidate, please look at this code:

int main()
{
	int a[3]={1};
	int b=1;
	int c[3]={0,2,1};

	a[b[c]]=2;

	printf("a[0]=%dn",a[0]);
	printf("a[1]=%dn",a[1]);
	printf("a[2]=%dn",a[2]);
	return 0;
}

1) Is this valid C++? Can you compile it?
2) If so, what is it going to print to stdout?

Answers:

(more…)

]]>
http://www.codingaway.com/2007/01/26/useless-programming-interview-questions-c-arrays/feed/
Nulling Pointers With memset http://www.codingaway.com/2007/01/24/nulling-pointers-with-memset/ http://www.codingaway.com/2007/01/24/nulling-pointers-with-memset/#comments Wed, 24 Jan 2007 20:50:18 +0000 Lorenzo http://www.codingaway.com/?p=3 Let’s say that you have the following structure:

struct
{
     char *sPtr1;
     char *sPtr2;
} S_something;

In C it is very tempting to initialize such a structure with something like:

   S_something s;
   memset(&s,0,sizeof(S_something));

That code seems OK at first, but there is a subtle issue. Can you spot it?

The problem is that this code is not always portable!! Most of the time you’ll be fine, however depending on the system (in rare cases, I admit) a null pointer might not be represented by a bitwise zero, but something else. In fact in some architectures 0 is a valid address (Example: IBM z/Architecture)

When you use memset to initialize the structure above, you are forcing the pointers in the structure to be set to bitwise zero. As noted that might not be equivalent to null, creating all sort of issues.

Conversely, when you assign a pointer to “0″ or to “null” on one of these systems, the compiler does the conversion automatically. memset doesn’t.

I’ll give you an example. The following code:

   S_something s;
   memset(&s,0,sizeof(S_something));
   if (s.sPtr1==0) printf("Good");
       else printf("Bad!");

Could potentially print “Bad!”.

Solution: simply initialize the structure by hand:

   S_something s;
   s.sPtr1 = 0;
   s.sPtr2 = 0;

This is guaranteed to work on all ANSI C compliant compilers.

]]>
http://www.codingaway.com/2007/01/24/nulling-pointers-with-memset/feed/
About http://www.codingaway.com/2007/01/24/about/ http://www.codingaway.com/2007/01/24/about/#comments Wed, 24 Jan 2007 19:50:44 +0000 Lorenzo http://www.codingaway.com/about/ Mission

The CodingAway mission is to collect and share the author’s 23+ years of experience in the software development world and high-tech business.

Blog’s Target Audience

CodingAway is written for people interested in technology, software development, software engineering practices, coding tricks, devices and in general anything that has to do with the high-tech world and its ways. If you consider yourself a geek or a high-tech professional or enthusiast, this is the place for you.

The Author

It was 1983 when the movie “WarGames” came out. It was that movie, believe it or not, that fascinated me to the point of changing and shaping my life forever. If you watch the movie today you’d find it cheesy and almost embarrassing, but at the time, when I was 11, it completely captivated me.

Around that time my aunt was buying an encyclopedia. As gift from the publisher she received a small home computer, which was quiet fashionable in the mid ‘80s. It was an Acquarious, one of these many unknown failed attempts that never made it big. A home-computer with rubber keys, an overheating problem and a cassette player as a storage device; one of these unfortunate competitors of the Commodore C64, that at the time dominated the low-budget computer market.

Since my aunt was (and still is) completely unable to deal with technology, she gave it to me. I was 12, and that cheap cheesy machine started it all. I skipped the stupid little games that came with it, and started learning the simple Basic Language of the built-in interpreter. Almost immediately I decided that Basic was not enough for anything serious, and I started studying and coding with Assembly. On home computers in that era you would typically code in assembly with a bunch of “poke”, “peek” and “data” Basic instructions that would load the machine codes directly into memory for execution. Scary, but it worked.

Not long after that I purchased a used Commodore Plus4, which was a heck of a lot more powerful and fun to use. It came with a word processor and a spreadsheet built in, and an excellent Basic interpreter. Painfully saving money week by week, I bought a 5″ disk drive, and kept coding away in Basic and Assembly. Eventually I moved to an Amiga 1000 (which I hated), and not long after to a IBM 8088. From there I kept upgrading with the various INTEL chip generations (V20, 8086, 286, 386, 486, Pentium, etc…). I worked on a first software development project for a customer when I was 14, in order to raise some cash to buy new and better technology (and go to movies and have fun), and never stopped since.

Well, to make a long story short I have been writing software everyday for well over 20 years now, and I grew up coding.

Probably due to this growth so close to technology, I felt at times that I lived in a world that was border-line with mathematics and perfect sciences. I often wrongly assumed that there was always a best way to solve any solvable problem and that it was always possible to identify not solvable problems and work around them with approximations. This sometimes led me to assume that we live in a time where science can find answers to most problems.

Well, I am changing.

I experience everyday that trying to find the perfect answer or ideal solution is impractical and unnecessary. The more I mature in age and experience, the more I realize that practical and achievable solutions are often found thanks to the experience and intuition of the engineers, and not thanks to some well known procedure that can be efficiently thought to others. For this reason, in general, the more experienced an engineer is, the better the solutions are and the quicker they come to be.

This makes software engineering more a form of art than a perfect science. Even if the basis of engineering is in well defined theory and theorems that have been proven mathematically, the success of the application of such theory and theorems in the real world is completely reliant on the skills of the people that do the work. No book can teach you how to apply theorems and theory, no book can truly and practically teach you when to pick an algorithm instead of another. Books and theories can give you an idea, but the efficient and practical application is really a form of art and a product of intuition. Almost a trade.

In this context, I define “art” as the application of procedures and theories based on experience and the artist unique perception of the world, to solve practical problems in a universe governed by laws that we don’t completely understand.

I am always amazed when I realize how much art is involved in any engineering filed, and how much engineering and science is necessary in any art field. For example a painter or a sculptor that wants to excel in the painting or sculpting of the human body, needs to study human anatomy in details and became an expert in the functioning and interactions of the body muscles and bones. Only doing so gives the artist enough knowledge to be able to visually recreate something that is close enough to reality to be considered pleasant and just right to human perception. Leonardo da Vinci knew this. Given that not much material was available he did first-hand research on human anatomy, risking his life and reputation in the process.

On the other hand, the practical application of medicine and surgery is so much based on art, steady hands, intuition and experience that is barely a science. Yes, true, surgeons need to be trained and know the theory very well, but the actual application of the theory and the process of performing a surgery is really a form of art that is susceptible to human error and miss-interpretation of cause and effects. Much like sculpting and painting! Also, a good doctor or a good surgeon is usually able to create a trust and a connection with the patient, which improves the success rate of medical treatments and surgery. This makes doctors very close to artists, in the sense that they are able to direct human perception in a particular direction, beneficial to the achievement of the end-goal.

I am always amazed that engineering and trades, science and art, mathematics and intuition, are so close in nature, if not one and the same, with a different accent and presumptions.

]]>
http://www.codingaway.com/2007/01/24/about/feed/