J-F Bilodeau's Blog @ chronogears.com

Wednesday, June 17, 2009

BSOD(roid)

I published my first Google Android application today: BSOD(roid). The application is an adaptation of the BSOD XScreenSaver hack that simulates crashes from various operating systems. I've squeezed in 20 crashes for about a dozen operating system. If you have an Android phone, please give it a try! It's free and licensed under the GNU GPL.

BSOD(roid) Menu
Windows 3.1 BSOD


Get Application
Source code

Positive reviews!

Labels: , , , ,

Friday, December 19, 2008

Java (does|doesn't) suck

I use Java programs all the time: jEdit, Eclipse and ArgoUML just to name a few. As a programmer, Java has served me well for over a decade, and I've never once wrote a piece of Java code of which the performance was unacceptable.

However, I keep hearing other user complain and snicker about the performance of Java. Though I try to defend the performance of one of my favourite programming language, I continue to hear the same chant again and again.

Once and for all, let me say: Java is not slow. If you don't believe me, come to my Java Performance Tuning course. I'll be happy to write equivalent Java and C code and time the execution of both.

An article on Phoronix.com brought to light something that I never expected. It would seem that Java on Windows Vista actually runs slower that Java on Ubuntu. I have to admit that this was a great surprise for me! I always assumed that Windows being the larger market for Java it would be optimize for the platform. However, that doesn't seem to be the case.

Maybe that's why there are still a lot of folks out there who are disillusioned by the performance of Java.

From prior experience, I suspect that Java application take up much less memory on Linux than Windows, but I haven't investigate that yet.

Labels: , , , ,

Thursday, September 25, 2008

Is Google Harming Linux

Google is a huge supporter of Linux and open source. They strive to ensure that their products work on Windows, Mac and Linux. However, it recently hit me that their cross-platform development may actually be harming the image of my favourite OS: Linux

Recently, Google released the Chrome browser. In my opinion, the fine developers at Google did a marvelous job re-inventing the browser on every level. After trying-out the browser, I must say that I am more than impressed. There is only one detail that annoys me: Chrome is only available on Windows. Google promises that it will eventually make its way into Linux and the Mac. But when?

This is what is harming Linux (and the Mac to some degree). I personally feel that it was a mistake to release Chrome for Windows only. That seems to communicate that development on Linux is very difficult compared to Windows. I agree that there are important differences between both operating system, but there is a slew of open-source cross-platform libraries that could have been used to permit a simultaneous release between Linux, Mac and Windows.

Google is not alone in that. The MyEclipse IDE, which runs on Linux, Mac and Windows, has some features that are either stripped down, or unavailable outside of Windows. Again, that communicates not only a lack of love towards my favourite OS, but it furthers the impression that Linux is a difficult platform to develop for.

It's true that Windows has a huge market share compare to the Mac or even Linux. Thus, there is more money in the Windows world. However, the Windows market share is slowly being eroded by Apple and even Linux. I'm a very poor prophet of the future, but current trends seems to indicate that alternative operating system will become very important. For example:
  • UMPC - Ultra-Mobile PCs. Many come with Linux pre-loaded thanks to the smaller foot-print.
  • Cell phones — Again, Windows is not very prominent there
  • The rising Apple market share
  • One word: Vista

I'm willing to bet that in not too long, development for alternate operating system will be seen as a necessity. This type of situation is not uncommon. I remember the web about 10 years ago. It was considered normal by web developers to code their HTML for Internet Explorer specifically. Today, that is a big no-no. I don't remember seeing one of the infamous 'Best View With...' button on a website in so long. Thank you W3C!
Another issue to keep in mind is the current distrust that many organizations and governments have with Microsoft. The OOXML fiasco has harmed ISO's reputation in a way that it may never recover, and Microsoft's tactic of committee stuffing has been well documented. The EU still have their eye on the behemoth, and even my province of birth is challenging Microsoft's dominance.
Microsoft may be the next IBM. They will not disappear tomorrow, or even after tomorrow, but their relevance and influence over the market will lessen over time. This will open the playing field for alternative operating system.
As a software house, you have two choice:
  1. Edge your bet on the Microsoft platform, and ignore the alternatives
  2. Develop products with cross-platform compatibility in mind

Which one are you going to choose? If you choose option 1, then get ready to fork out money into the four to five digits (at least) to buy the Windows development stack. That will typically include Windows (XP, Vista or Server), Visual Studio, Microsoft Office and so on.
On the other hand, most of the cross-platform development tools are open-source with optional corporate support if desired.

Labels: , , , , , ,

Thursday, June 26, 2008

How Microsoft Won and is Loosing



Steve Ballmer had it right. Developer developer developer!

The prime reason why Windows won over OS/2, the MacIntosh and even MS-DOS was thanks to the mighty influx of application that crept up for the OS. And the only way that those applications existed was thanks to developers.

Thought the Windows API are not the most graceful API I've encountered, they were reasonably well documented. I learned the Win16 and Win32 APIs mostly by reading the MSDN help files.

Using the simple tactic of ensuring that developers would favour the Windows platform early on, Microsoft achieved dominance in the operating system market.



But what is happening today? Balmer has been singing a different tune for the past few year. Since the rocketing rise of Microsoft's stocks capped in 2000, the behemoth is now struggling to pierce new markets while retaining their heavy monopoly.

It's interesting to see Microsoft running like a chicken with it's head cut off. Vista is a disaster, they are still loosing money in their search and gaming division and .NET is barely making a dent in the Java marketplace. Let's not even mention their iPod killer: the Zune.

If it wasn't for the near monopoly on Windows and Office, Microsoft would be hemoraging money faster than the speed of sound. BANG! Bankrupcy before they know it.

I think the reason is pretty clear. Microsoft is now spitting in the face of the very people that brought them to where they are: the developers.

Balmer himself said that he would like open source innovations to happen on Windows. However, he seems (or chooses) to be clueless about the free software philosophy.



Balmer can push all he wants, but he should realize that developers are usually intelligent folks. Many open source developers are quite brilliant. I do believe that most developers can smell bullcaca when it is spewed out of someone's mouth.

Genuine honesty free of marketspeak is not something you often hear from Microsoft!



It's certainly not by forcing proprietary software or standards down the FOSS developer's throat that Microsoft is going to win any friends. Neither is it going to give developers the desire or even the posibility to innovate.

Personally, I like computers to work for me and not the other way around. That's one of the many reasons I don't use Windows &mdash I cannot stand an OS that thinks it can tell me how I should work.

Labels: , , , , ,

Friday, April 25, 2008

Control Panel for the Eee PC

This week, I wrote a small Eee PC control panel that takes advantage of the wonderful eee kernel module. The control panel runs in the background and is available through the system tray. Pointing on the icon gives the general status of your Eee PC. A click on the icon will bring up the actual panel. From there, you can control the fan, the front-side bus (overclocking) and the voltage (from what I can understand).

Obligatory screenshots:
The system tray icon & tooltip
Eee PC Control Panel Tooltip
The control panel
Eee PC Control Panel

The control panel is written in Gtk+, and works great on my eeeXubuntu. I would assume that it works fine on the default Xandros install or even (K)ubuntu. From start to end, the control panel was created on the Eee PC, proving that it can be used to get actual work done.

For the convenience of Debian or Ubuntu users, I've create a deb package. Otherwise, a tarball is available with a pre-compiled version of the control panel as well as the full source code. Of course, it's all GPL ;) Please copyleft.

eeectl.deb
eeectl.tar.bz2

Before you install the control panel, make sure you install the eee kernel module available at http://code.google.com/p/eeepc-linux/. Detailed installation instructions are available at http://wiki.eeeuser.com/howto:overclockfsb.

This is a first for me in many ways, so please forgive any stupidity or ignorance on my part. I've used Gtk, Glade and GkSu APIs for the first time, and I've created my first .deb package. I'm more than willing to learn from any guru who may find improvements to my little application.

Of course, usage of the Eee PC Control Panel is entirely at your own risk. Though I use it on my own machine, I cannot be held responsible if you fry or brick your little machine.

Hope you enjoy!

(Before you ask, there is no Windows version, nor do I intend on creating a Windows version. For starters, I'm not willing to buy a Windows license for my Eee PC. Someone else can take care of that)

Labels: , , , , , , , , , , , , ,

Thursday, April 17, 2008

What is Computer Programming?

Most computer users are mystified by computer. They know how to use them, but they're not sure how they work. There is also the concept of computer programming — the esoteric science used by developer to make the computer do something interesting.

In this article, I would like to give a quick introduction to what is computer programming. This is not a complete course or tutorial, but I think that this will be enough to give you a better idea of what computer programming is all about. Also, I hope this will will also show you why there are bugs in most of the applications we use day-to-day.

Let's start demystifying computers. To begin with, they are machines, and only machines. In my courses, I sometimes ask my students what is the most powerful computer on the planet. Some answer the brain. However, I can't accept that as an answer, because the human mind is not a computer...and that's a good thing! Though our minds are not capable of doing billions of calculations per second, it is able to think, which a computer is simply (as of yet) incapable of doing.

So, computers are not thinking machines. They are incapable of thought. But what are they? Fundamentally they are machine capable of storing information and processing that information. To process that information, a computer follows a sequence of precise instructions. Creating those instructions is what computer programming is all about.

Without a program (a series of instruction), a computer is incapable of doing anything. The instruction given by a computer programmer falls into certain categories.
  • Accessing memory — the ability to read and change what is in the memory of the computer
  • Performing calculations like additions, subtractions, multiplications, etc...
  • Evaluating conditions like 'is A greater than B' or 'is the number of characters entered less than 50'
  • Branching — or jumping around in the program. For example, if the password matches, allow entry, otherwise, display error message.
The last point — branching — is really what programming is all about. Telling the computer how to handle different scenarios.

To give instructions to a computer, a programmer uses a programming language. There are literally hundreds, if not thousands of programming languages out there. The reason there are so many languages is that some are better suited at certain task than others. Another way to view it is road vehicles. There are compacts cars, minivans, sports cars, buses, motorcycles, transport truck, etc. The reason there are so many different cars on the road is that each is better suited to one task or another.

Programming languages, as opposed to human languages, are very strict. Since computers don't think, if a period is missing, a comma is misplaced or a word is misspelled, the computer will not be able to make sense of the code. Chances are, the computer will not even execute the program. Even if the computer can execute the program, most likely, it will not do what you expect it to do. In other words, it encountered a bug. The programmer meant something, but told the computer something else. Call it a misunderstanding if you'd like.

Here's an example: The programmer tells the computer: 'The cat is shedding fur on the couch. Move it.' The computer comes back and says: 'I finished moving the couch. Next instruction?'

I'm a strong believer that the only way to learn something is to do it. Thus, to help you learn what is programming, we are going to look at code, and see it in action. I strongly recommend you play around with the code. Don't worry, you will not be able to break anything. If you mess up the code click the 'Reset' button, and it will be brought back to it's original state.

To explore programming, we'll use a language called JavaScript. It's a reasonably easy language to start with, and is readily available to most web browsers like Firefox and Internet Explorer.

Let's start with a simple example. We'll ask our computer to execute the 'alert' function. Look at the following code, and click 'Execute.'



If all went well, you should have seen a window popup with the text 'hello.' If it did not work, it may be that your browser has JavaScript disabled for one reason or another.

In the above example, we are asking the computer to execute the JavaScript 'alert' function. It's one of many functions we can use. We'll explore a couple more as we carry along.

For the fun of it, try to change the above code to:
  • alert(1+2);
  • alert("1+2");
  • alert(1+2*3);
  • alert(8/2);
  • alert("Hello " + " World!");
Did you try all of the example? Can you explain the difference between the first and second example? Also, in the third example, can you explain the result?

Once you are reasonably comfortable with the above example, let's move to the concept of variables. A variable is simply a placeholder for information. In other words, it's a chunck of memory we are reserving for our program, and we can put whatever value we like in it, and look at the content at any time. Try the following example:



Let's disect the above example. The first line which begins with 'var' tells JavaScript I would like to declare a variable named message. You choose the name of your variable. They can be any combination of letters and numbers, but they cannot begin with a number. You cannot use spaces or punctionation in the variable name. For example, message, message1, myvar, c123 are all valid names. On the other hand, 123, hello world, my*var are not valid names.

The second line tells JavaScript to store a value in the variable. Right now, we are storing the textual value 'Hello from a variable'. Try to replace the text by 2+2 and see what happens. Try it with and without the double quotes ("). Also, try to change the name of the variable to something else, like mymessage. Again, feel free to experiment.

You probably noticed that there is a semicolumn (;) at the end of each line. This is to tell JavaScript that we are finished a statement, just like in English we use a period (.) to indicate that we are finished a line.

In the next example, we will use two variables, as well as interact with the user. Try the following code:



I hope that it's not getting too sophisticated. It if seems like a lot of goobledygook, look at the program one line at a time.

The first line, 'var name,' declares a variable called name. In the next line, 'name = prompt("What is your name?");' we are asking JavaScript to prompt the user for their name, then store it in the variable called name.

The next too lines declare a second variable called message, then 'concatenate' (merges or puts together) three textual value: The text 'Hello, ', the text that the user entered, and finally, an exclamation mark. Notice how the plus (+) sign is used to tell JavaScript to concatenate text together.

Finally, the last line text JavaScript to display (alert) the content of the message variable.

Note that I could have reduced the lines of code. For example, you could have declared and initialize your variables on a single line, as follows:
var name = prompt("What is your name?");
var message = "Hello, " + name + "!";
alert(message);


The above code is equivalent to what we executed a moment ago. Try it now if you'd like.

Let's try another example, similar to the first. This time, we are going to calculate something.


Again, read the code line by line, and try to make sense of what's it's telling JavaScript to do. Have you noticed that we are using a new function called Number? What does it do? Try to remove it from the code, and see what happens.

The Number function tells JavaScript to take what is in the bracket, and convert to a number. The thing is, the prompt method assumes that whatever the user enters is going to be text. Thus, if we write 'number1+number2', JavaScript assumes that we'd like to concatenate two textual values. To force JavaScript to treat our variables as numbers, we use the Number function.

If the above explanation is not clear, remember that computers are not intelligent. They do not think. The prompt function returns the text of whatever the user types. Even if you type in a number, for JavaScript, it's text and not a number. We can tell the difference between a word and a letter, but JavaScript cannot. We have to explicitely tell it so. This is where programming can get a bit tedious. As a programmer, we have to explicitely tell the computer what to do, step-by-step. If you forget to tell the computer something, then the computer is not going to do it.

Though it may seem tedious, the fact that computer do not think is one of their strenght. Because they follow instructions to the letter without deviation, they ensure that a process is completed error-free. AS human being, we can think and rationalize, but we are prone to error. The only way a computer can do an error is if the programmer has introduced an error in their code. Errors in code are called bugs. I'm sure you heard that term before! So, now you know that whenever a program misbehaves, it's most likely because the programmer made a small error in their code. Please don't blame the poor programmer. It is very difficult to write bug-free code. If you're not convinced, try to write a simple program and see for yourself.

Speaking of simple programs, let's get back to our code. In the next example, we will to some actual programming. So far, the programs that we wrote simply execute one instruction after another. That's not real programming. Programming involves giving decision-making ability to our program. We will look at a simple example that will prompt the user for a password and let the program 'brach' in different direction depending on the password that has been entered.



Can you figure out what the 'secret' password is? Please note that this is only an example. The above code should never be used to protect a website.

We are using a new construct called an 'if' statement. This statement allows your to tell the computer to make a 'decision.' The double equal (==) operator tells JavaScript to compare if two values are the same. The reverse of that would be the != operator that compares to see if two values are different. How about you try it! Replace the == by != and see what happens now. Execute the code with a valid, and invalid password.

You have probably notices the curly brackets { }. These are used to 'group' statements together. They tell JavaScript that every statement between the opening and closing curly bracket should be executed one after another in that branch.

It is possible to 'chain' multiple if statements. Try the following code:


How many branches (else if) can you have? The answer is as many as you'd like.

If statements are one of many constructs that we can use to give define the behaviour of our program. In the next example, I would like to explore the concept of a loop. Loops allow you to tell the computer to repeat something over and over again while a condition is met. Try the following code:



The new construct that we are using is a do-while loop. You'll notice the use of curly bracket to indicate to JavaScript that everything between the do and the while should be executed for each iteration on the loop.

The above example will prompt the user until they enter a valid password. Note that the user cannot even cancel the action. Why not? The reason is, we haven't told the computer what to do if the user clicks the cancel button. Again, computers don't think. We have to tell it exactly what to do.

If you would like to be able to cancel, try the following code:


What you are seeing is starting to look more and more like a computer program. There are actually make ways a programmer can write the same program. The above example is just one.

If you've gotten this far, don't let the length of the program scare you. Disect it bit by bit, line by line. The only thing that is new is the && operator. This tells JavaScript that both comparison (password != "abc123" and password != "") have to be true to continue the loop. Since this is an overview of what computer programming is about, I won't spend too much time on sophisticated conditional statements. As always, feel free to experiment with it.

One last example, then we are moving to the grand finale. The next example will allow three tries to get the password right. If after three tries, the right password is not entered, we exit the loop. There is nothing really new in the next example, beyond merging together many of the concepts we have explored so far.



The only new construct here is the less-than operator (<). Can you see what is does? As long as the counter is less than three, we continue the loop. The moment it's greater than or equal to three, we exit the loop.

Notice the line 'counter = counter + 1;'. Can you figure out what it does? Everytime the loop is entered, we increase the value of the counter by one. For example, the first time we enter the loop, the counter is at zero. Thus, the line reads as 'counter = 0 + 1.' The value of the counter is increased from zero to one. At the next iteration, the line reads as 'counter = 1 + 1,' thus the counter is now at 2.

Again, there are many ways the above code could have been written. Because this is an introduction to what is programming and not an introduction to JavaScript, I'm not exploring all the possible approach here — I'm just exploring how to give instructions to the computer.

For our grand finale, I would like to give you a complete program. It's a game you most likely played in primary school. The computer will pick a number between 1 and 100. You have to guess what it is. The computer will tell you if you guess was less or greater than the secret number.

Look at the code. See if you can figure out what it does, and run it. This is more or less an example of a computer program.



Can you make sense of it? I wrote the code so that it would be reasonably easy to understand, but by the same token, I did not dumb it down too much. If you managed to follow me so far, I think you should be able to make sense of it. It may require you to look closely at the code, and even taking some note on paper, but do give it a try. You can even modify it if you'd like.


So, you've looked at computer code. You now know that computers have a memory (variables) and instructions that the machine will follow to the letter. Because computers do not think, you, as a programmer, are responsibile to tell the computer exactly what you want it to do. If your code does not execute exactly as you would expect, that's because there is a bug. Computer rarely do mistakes. For that matter, we might as well say that computers never do mistakes. So, if your code does not do what you expect it to do, it's not because the computer is wrong. It's because that's what you told the computer to do.

If you've enjoyed this little foray into the world of programming, there are plenty of great resources on the Internet available to you. You can, of course, continue to edit and modify any of the code on this page, and I encourage you to do so. To continue learning JavaScript, I personally would like to recommend w3schools.com. It's not the only place on the Internet, but it's one that I've used a lot. There are many programming languages you can learn, and JavaScript is only one of them. Also, there a number of best-practices that I did not use in the above examples. The given code is only meant as a learning tool, and not as enterprise-ready solutions.

One way or another, this article should have given you an understanding of what is computer programming — that is, giving very precise instruction to the computer. There's a lot more we can discuss and I'm sure you probably have questions. If you are looking for guidance as to where you would like to go next, or have any questions, please drop me a comment.

Or hey, if you created a cool program, please feel free to share it with us!

Enjoy the rest of your day!

Labels: , ,

Wednesday, March 19, 2008

Why I (Still) Love the Pascal Programming Language

Day-to-day, I use Java, C++, Python and a host of other programming languages. I like my modern programming languages. However, my first programming language love refuses to die -- Pascal.

Pascal is not a perfect language. For that matter, there are no perfect language. However, some languages can arguably be said to be better than others. This said, I will readily accept that Pascal has important flaws, which I will discuss later. However, here are the reason why I like Pascal, and why I think you should give it a spin:

Available on Most Platform
The Free Pascal and GNU Pascal compiler is available for most platforms, including most *NIX, Macs and Windows. Heck, you can even write code for the GameBoy DS! Furthermore, the code is usually portable with minimal or no changes.
The Free Pascal motto is 'Write Once, Compile Anywhere.'

Compiled
It's not interpreted. It doesn't use bytecode or IL. It's compiled straight to machine code. Thus, your Pascal applications can run as fast as any C application.

Lightning Fast Compiler
That's one cool thing about (most) Pascal compilers I've used. It's blazingly fast. This greatly reduces the write-compile-debug cycle.

Still Active
Though far from being as popular as C or Java, there is still strong support for the language. I don't think we can consider it a 'dead' language yet.

Structured
I think many people may disagree with me, but I like Pascal's strict structure. It forces me to think my code through a bit before I hack away. Also, once the code is written, I find it's usually very readable. Nicely written Pascal code can be close to English.

Native Data Structure
Arrays and numbers with any lower and upper bounds, sets and enumeration native to the language make Pascal a lot of fun to play with. You don't even has a set data structure in .NET 2.0!

Pascal also has a fairly complete collection of basic data types, and they're all first-class citizens. In other words, they are not classes that implement the functionality. Thus, they can be optimized by the compiler.

Multiple Paradigm
Pascal supports procedural programming and object-oriented programming, and the two can coexists peacefully.

LCL
Though not a standard part of Pascal, the LCL (Lazarus Component Library) is strongly supported by the Free Pascal community. It's a wonderful way of building GUI application and is available of all major platforms (Linux (GTK2, QT), Mac OS X & Windows)

As I mentionned above, Pascal is not perfect. The language was created in 1970 and was originally designed to encourage structured programming (no gotos).

Here are some of the things I would like to see improved in modern Pascal:

Precedence of Operators
Pascal has only four level of precedence of operators, which makes writing some conditional statements (and, or, etc) ackward. Brackets can be used, but they can also make the code more difficult to read.

Garbage Collection
The memory management is Pascal is up to the programmer. Being a C++ developer, I like manual memory management is some context. However, being also a Java developer, I would like to take advantage of automatic garbage collection. It would be nice if I could choose the memory management strategy for my application.

Templates / Generics
C++, Java and .NET supports Generics. They can same a lot of dynamic casting while making your application type-safe. By eliminating dynamic typecast, the execution speed can be improved.

I would love to have a generic TList or TMap.

True Platform Independent VCL
The VCL (Visual Component Library) was born out of Delphi -- a beautiful competitor to Visual Basic that never enjoyed the success it deserved. The VCL was created on Windows for Windows and during a very short time, ported to Linux.

The Lazarus project recreated (and expanded) most of the VCL called the LCL (Lazarus Component Library, but aimed to retain compatibility with the VCL. This is great if one is developing on Windows, but makes it ackward on other platform like Gtk2 (Gnome), QT (KDE) or Carbon (Mac OS X). This is due to the fact that the (V|L)CL refers to Windows API and constants by name. A layer of abstraction between the LCL and the underlying system would make the code look native on any platform.

Furthermore, having dynamic layouts like Java that adapt themselves automatically to the platform would be almost essential.

Object Oriented Version of String, Array, Set, Enumeration, etc...
Using strings or array remains procedural. I would love to have a compatible but object-oriented version of the build-in data types (I know that seems to contradict one of my points above, but they could remains 'compiler' classes). A simple solution would be to make a string class, and recreate the string functions to call the method on the string class, thus preserving backwards compatibility.

Pascal has survived nearly 40 years mostly unchanged. There has been refinements, additions and extensions added to the language. However, a Pascal program written 30 years ago may still compile in a modern Pascal compiler.

Though nowhere near as popular as C/C++, Java or .Net, I think that Pascal has a lot to offer. If you've never used Pascal before, consider downloading Lazarus to help you get started. There are plenty of great Pascal tutorial available on the web.

Happy coding!

Labels: , , ,