Why Gtk+ May Just be the Best GUI Toolkit Ever

June 2nd, 2009 | C/C++, Gtk+, GUI, Toolkits | Comments Off

When it comes to programming a lot of people look to C/C++ for answers. They’re pretty straightforward languages that are general-purpose(they aren’t really good at anything in particular, but can be used to do just about anything). The only strike against these languages is that unlike Java, they don’t bring a GUI API built in. Instead, C/C++ coders must rely on other libraries and even system APIs to get the job done.

Introduction
Nowadays almost every application has to have a GUI. Users rely on graphical interfaces, and a programmers job isn’t only to code up an app, but to also make it best for the consumer. Now this leads one to wonder, “What should I use to make the GUI part of my program?”.

Well, the answer isn’t always straightforward, but there is one toolkit that looks a little better than the rest. It’s Gtk+. GTK+, or The GIMP Toolkit, is a cross-platform GUI toolkit and, is one of the most popular toolkits for the X Window System, along with Qt.

So what makes Gtk+ so speacial? Why could it possibly deserve the title of “Greatest GUI Toolkit Ever”? That is the point of this article. Here we will discuss a little bit about it, and see why it is a very good choice for developers.

1. Simple Syntax
One of the best features of Gtk+ is its simplicity of syntax. Almost everything is predefined, you just gotta point everything in the right direction.

For example, this little snippet below creates a pretty basic window (300px wide, 150px high, aligned to the center of screen, and says “A Window” in the titlebar):

#include 

int main( int argc, char *argv[])
{
 GtkWidget *window; // creates the window object

 gtk_init(&argc, &argv); // this handles commandline arguments, don't worry to much about it

  /* Here we setup the window */
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_default_size(GTK_WINDOW(window), 300, 150);
  gtk_window_set_title(GTK_WINDOW(window), "A Window");

  gtk_widget_show(window); // this makes it appear

  gtk_main(); // this puts the program in a loop waiting for events

  return 0;
}

Amazing. That was all done in about twenty lines of code, and you could even reduce that more by getting rid of whitespace. Just for fun, I tried making something similar in Win32; my result was more than 70 lines of code, and that was just for the basics.

In case you’re wondering why you would choose a toolkit just because of syntax ease (or if you should even care), you must consider that the easier it is to write a program, the easier it would be to take care of it, as well as find bugs. As you will see later, Gtk+ has many features that help to make maintenance easier.

2. Great Structure
Not does only does Gtk+ have sytax that’s easy to follow, but is also designed in a way that makes it easier to work with. For example, you define the objects and widgets (a button or window, or dialogue), you pass it parameters and set it up, and you then either pack it into the window, or a box etc. Then all that’s left is to make it show up. Of course a real application would have callbacks so that widgets would respond to events, but still that’s pretty good.

It’s structure like this that helps programs for becoming “code soup” and lets developers worry less about “how they’re gonna setup the application”, and more about “when they are gonna code that badboy up”.

3. Lightweight and Fast
One of the best things about Gtk+ is its weight and execution times. This toolkit is especially good if resources are a concern to you. Applications written with Gtk+ are far less likely to crash due to not enough memory, freeze up, etc.

Here’s a good example: I’m working on creating a open source project right now. So far all I’ve coded is the GUI, and while I still have a long way to go before it has full functionality, the bare-bones app is only 30.4KB and executes in well under a second. Now it’s been a while since I’ve done a lot in Win32, but from what I remember even very simple applications were in the “200KB” range. That’s more than 6 times as big. In the long run, that could really add up.

4. Portable
Last but not least is the fact that Gtk+ is portable. It’s pretty much write once, work anywhere (Of course the users have to have the right stuff to run you’re program, but this generally wouldn’t be an issue).

This is a great thing for programmers. A lot of programmers are turning to Java because of its “multi-platformism”; but this gives C/C++ coders a real alternative to learning a whole new language, or having to be greatly limited by another language. The portability of Gtk+ is a truly great advantage and is also a good explanation for success of toolkits like “WxWidgets” and “QT”

Conclusion
In conclusion I hope you considered many of the things I’ve mentioned here, and are now looking into getting to know/use Gtk+. My goal here was to show you that Gtk+ is an amazing resource for C/C++ developers, and I hope I did so in as best as I could. If you find any errors, or have any suggestions, etc. please comment (I love it when people comment :D ).

Dearest Readerz

April 21st, 2009 | Uncategorized | Comments Off

Dear Readers,

I haven’t had as much time as I would have liked to post on this blog. I’m sorry to inform you that I won’t be able to keep up this site as I had initially planned, however, I am going to look for others to help the contributing process, and they, along with me from time to time, will help keep this site with lots of fresh content.

If you wanna help, feel free to contact me
~mike

Linux or Windows, Which is Best For Developers???

March 31st, 2009 | Linux, Opinions, Windows | Comments Off

When a programmer chooses his hardware, he doesn’t go around like most people. He has to greatly consider what he’s buying. Well, we’ll leave that aside for now, and we’ll look at software, more specifically the OS. The two most used operating systems in development have to be Windows and Linux; Mac OS X is a terrible platform, and hardly anyone develops for it, except major companies like Skype. When considering what platform to choose as a development environment consider these things. Which has a better API???, Which will more people use???, How much will this cost me (both in time and money), and What Compilers/IDEs are available???
Now we’re gonna look at all of those.

Which has a better API??? – OK, I’ve never programmed under Linux, but I think in some ways it would be easier than Windows. The Win32 API has to be the worlds most complex piece of crap ever written! I love Windows but it takes forever to learn as well as master(I know, I’ve tried; and I’m an OK Windows programmer). Now Linux is really Unix deep down inside, which is a system fewer are familiar with. However, if you can use Windows you could learn Unix. Its structure is a little more “system-like” if you will, but you can figure it out. The only problem with is that Linux doesn’t really have an API. I must state that I’ve never programmed under Linux, but from what I’ve heard, it’s application programming interfaces are truly messy and even surreal. You see, their are hundreds of Linux Distros, each written by different people, and the all include different things. Some have KDE, some GNOME, other XFCE. Some have GTK+ others QT. You see, there is no universal Linux, except for the Kernel. While Windows is more difficult, it’s stable. Sadly Linux lost this round because of it’s non-standards

Which will more people use??? – Let me start out simply by saying that if you want your software to be used by the masses, then it better be Windows. Microsoft ran a commercial the other day stating they had over 1,000,000,000 PC users!!!!! However, if your software is not meant for common user usage (like Server stuff), or is meant to be Open Source, then Linux is the way to Go. For this round, Windows definitively won.

How much will this cost me (both in time and money) – There are three factors that affect resources. Time, Money, and Development Team. Those three things in my opinion are the most important in software development. Now the third really isn’t affected by the OS your running, so we’ll look at the first two. Time! Time is of the essence! If you have to spend more time configuring a system than coding, then you my friend have a problem. Let’s look at Windows first. You buy a PC and it’s pretty much ready to go! You get rid of some of the software it brings, install an Antivirus/Firewall, your development tools, and maybe even Mozilla Firefox. The whole thing is done in an hour or two. Now look at Linux, you pop in the disk. It’s pretty much good to go, unless you encounter a problem!!!! If you were to let’s say be unable to get your wi-fi to run, you’d have to find the right driver; and with it’s low support that could take hours. Then there’s the configuration. Linux is not point and shoot, it’s point, Google, then shoot. I don’t wanna be to mean to Linux, but that OS can be a real time consumer. I spent hours with many failed attempt before getting it right, all in the name of Linux! Now, sometimes Windows takes a while to fix, or in that case reinstall, but the upkeep of Linux is a great disadvantage. Now for the second, money. Windows Vista Home Basic costs $99 bucks at the store; Debian free. Most free software for Windows is either a trial, express, or has a marketing strategy behind it. The exact oppisite is in Linux. Debian has over 20,000 free pieces of software (that_a_lot = true;).  So when it comes to money, Linux is champ. Now to illustrate this I think I’ll use one of those MasterCard Commercials

Example 1: Windows Vista Home Basic…99 Dollars, Extra Goodies…250 dollars, Getting a Wonderful, Rich, Development Environment…Priceless

Example 2: Debian 5.0 Sid…Free, Extra Goodies…Free, Getting a Platform Hardly Used, With no Solid API…Worthless

What Compilers/IDEs are available??? – This really depends on the language your using. For Java, the JDK is cross platform, but that’s not always the case. Why don’t we consider C++??? In Linux the main compiler/linker is g++. Now, I’m not saying the command line sucks, heck I love it, but creating an application through it is a pain. In Windows that kind of thing doesn’t exsist, well it does, but forget that for now. In Windows there are tons on IDEs available. The monsterous Visual C++, Borland C++ BuilderX, Code::Blocks, that’s just to name a few. Now what IDEs are in Linux??? Anjuta???? Well, if you like limited choice, then Linux it’s for you.

Well, in conclusion, consider this article, I’m bias to Windows, but what I’m saying is true. In my opinion Windows is the best platform in the world, but truly the choice is up to you. I gave you a few things to ponder upon and I hope you can make a great choice.

Until next time,

~This is Mike Signing off

I Think Java Coderz Are Just Lazy

March 30th, 2009 | C/C++, Java, Opinions | 2 Comments »

In the world of programming, if an application needs a GUI (what doesn’t these days) the first thing that comes to mind is “Java“; aren’t I right???? Seriously! It’s easy, cross compatible, and has great reviews. Java looks like an all around great deal!

Well I don’t want to rain on all you Java coderz parades, so I’m gonna pour and flood.

When it comes to application working, it doesn’t get any better that C++. Now I’m pretty bias, but let me explain. C++ can beat Java in the three things I mentioned above.

It’s Easy – Sure Java is easy. Things are based in a OOP kinda way. However, one must remember Java is just C++ deep down inside, really it is. The only difference between the two is that Java brings it’s API built in, while C++ relies on imported/exported libraries and interfaces. However, just include the file windows.h and you have the entire Win32 API at your finger tips. C++ is better than Java, you just got to find a good library or two.

It’s cross compatible – Well while we all would love “write once work on all toasters”, that’s beyond the point. C++ will work on any platform just like Java. Sure you’ll need separate libraries for different things, but how much does it matter. While you may have to recode the GUI, most of the internal code will remain untouched. If you use Java just because you don’t want to rewrite an interface, then you are just lazy (and my parents taught me that was bad. *Tisk Tisk*) Really how hard is it to rewrite it, unless we’re talking a “extremely” large application.

Java has great reviews – So does C++, as simple as that

Example
Now to help illustrate all of this, let me share a story if you will. I have a friend called Blake. He made a pretty simple instant messaging program in Java (with the server software in C++). Well, let me tell you the trouble he’s had. In my opinion it’s GUI sucked under Linux, it didn’t work in Mac OS X (so much for platform independent), and a lot of the time it froze.

Now I don’t want to criticize my good ol’ buddy, but if he had written it in C++, I’d bet a $100,000,032.67 that he would not have a single problem.

I hope that all of you will consider my opinions and look more to C++. I’m not saying Java is a terrible language, I’m saying C++ is better

Until next time,
~ mike

Silk, a Great Icon Set For Developers

March 29th, 2009 | Icons, Resources | Comments Off

Silk Icon Preview
The Silk icon set is a set of about 1000 free icons. These icons are very nice, beautiful, and completely free.

These icons have heavily influenced many big projects, including HPLIPS (That’s a device manager in Linux).

So check them out, I really like them

~mike

Why Object Oriented Programming is so Important

March 29th, 2009 | Object Oriented Programming | Comments Off

The number one question asked by newbie OOP-ers has to be: “Why do I need object oriented programming? Can’t I just use functions???” Well, maybe I should explain a little as to enlighten you.

First, one must consider the purpose of classes to understand them. Classes were created as to help programs more closely resemble reality. Classes make things called objects, which have properties and can be manipulated. This makes any application easier to build.

Consider this example: You need to build a farm game. You have a library(like ALLEGRO) for graphics, one for sound, one for controls, etc. Now, you want to make it so the user may create animals. If you were doing this through functions, you would have to make one for pigs, one for cows, etc. Each of these would have the properties of the respected animal. However, a dog and a cow both have hair; they share that property. This is where OOP comes to the rescue. Object Oriented Programming allows something called inheritance. One class can detract from another, and in doing so, gets(or in a more sophisticated way: “inherits”) it’s properties.

This means, that you have to write once, use as many as necessary. This allows to better code that is less prone to bugs.

Now this is a pretty minimalistic example. I hope to come back to this subject later and give a larger scale presentation.

Until next time
~mike