Bjarne Stroustrup, the "inventor" and first implementer of C++, is about to publish a new book. It's titled Programming - Principles and Practices Using C++ and is going to be published in August. It's already listed at amazon.com. In contrast to The C++ Programming Language, this book is on an introductory level to programming, not only C++. It's something that the C++ community was lacking for years now, with the only alternative of Accelerated C++.
Monday, June 16, 2008
Wednesday, June 4, 2008
xstartonce: Boost your productivity
I've grown accustomed to a way of working on my Desktop which greatly enhances the speed and therefore productivity of working by accelerating switching to certain applications. There are relatively few applications which I use on a daily basis. I'll mention just a few examples here: I use Firefox (well, now it's Arora) for browsing, Vim to edit files, and a shell for doing various stuff. I have to switch between those frequently. Often when coding stuff in Vim, I have to look up information on the net, so I have to switch to Firefox. When I'm done looking up stuff I'll try it out on the console and then switch back to Vim to integrate it into the program. Switching back and forth between applications can be quite a hassle because of the "most recently visited"-paradigm usual implementations of Alt+Tab (or similar) use. The most recently visited window is the one that'll appear first when switching windows. This works great if you have only two windows. It'll get irritating and slow when you have more than two windows and switch back and forth in an unstructured order.
So I've invented this methodology of work: Every regularly used application is assigned a shortcut. It's Ctrl+Alt+F for Firefox, Ctrl+Alt+V for Vim and Ctrl+Alt+C for the console. The program I use for shortcut is selfmade, because it needs one special feature: When the shortcut is activated, the program looks whether there's already a running instance of the application I want to switch to. If there is none, it'll be started (and automatically get the focus). If it is already running, the existing instance will be focused. This works great. When I need my browser, I don't have to think about whether I've already started it, and if so, where have I started it or anything. I just press Ctrl+Alt+F and have a Firefox or Arora window activated.
I have shortcuts for about 8 applications at work, including one or multiple local and several remote consoles, the aforementioned Arora and Vim, Delphi, Microsoft Visual Studio, InstallShield, the production-copy of the application I'm writing and a few more.
Without my shortcut-application I'm really at a loss and struggling with cycling through windows with Alt+Tab.
Until now, there was only one unreleased, Windows-based program which would enable this work-methodoligy: It's called KeyboardGuy, and it's written by me and exclusively used by me.
When I switched to Linux recently, I was really missing that comfort. So I looked for a way to accomplish this with as little work as possible.
The very first try was a shell-script that uses wmctrl to find out the Process- and Window-IDs that I needed. It looked up the process-name via ps and would activate the window if the basename of the specified application and the process-name in ps matched. With my relatively limited knowledge of shell-scripting, I came up with a script like this:
#!/bin/sh
PROCESSES=`wmctrl -l -p | awk '{print $3}'`
DOEXIT=
ps h -p $PROCESSES | while read i;
do
ID=`echo $i | awk '{print $1}'`;
NAME=`echo $i | awk '{print $5}'`;
NAME="`basename "$NAME"`";
if [ "$NAME" = "$1" ]; then
wmctrl -l -p | while read WID;
do
WPID=`echo "$WID"|awk '{print $3}'`;
if [ "$WPID" = "$ID" ]; then
wmctrl -i -a `echo $WID|awk '{print $1}'`
exit
fi
done
fi;
done
echo $DOEXIT
"$1"
There exists one problem, however: The script needs to completely terminate after wmctrl -a is executed. The call of exit that should accomplish this, however, did not work as expected and the line "$1" (which starts the application given as the first parameter) is always executed, even when the window was activated first. Because I was rather unsatisfied with the whole thing and couldn't get it to work, I decided to rewrite it in C++, using Qt (because Qt makes many things much easier for me here, and I wanted to get this done quickly).
The final result is the application which I call xstartonce.
xstartonce
The current version is the second iteration of the C++/Qt-version. The first version would match the basenames of the given application and the path found in ps's output. This leaves one big limitation, though: You can't assign shortcuts to one and the same program. I need this, for example, because I want shortcuts for a local and several remote consoles. Those would look like "urxvt" for the local console and "urxvt -e ssh melchior" for the remote console. Because the basenames match (both are urxvt), the shortcut-application would not be able to switch between those two distinct consoles.
Configuration file
That's why I invented the "named shortcuts". This needs a configuration file (~/.xstartonce), which has a very simple structure: It's <shortcut-name>=<command --param>. My ~/.xstartonce looks like this:
urxvt-local = urxvt
urxvt-melchior = urxvt -e ssh melchior
firefox = firefox
assistant = assistant
gvim = gvim
vim = urxvt -e vim
Currently, only named shortcuts are possible. This means that for each application you want to launch, you need a configuration-file entry. I've totally abandoned the formerly discussed algorithm to match the basenames of the processes in favor of this approach. I will, however, make both possible in the future. This has an advantage that was bugging me with the Windows-version already: When opening firefox from anything else but my shortcut-app, it'll not get "recognized" by it and a second instance will be opened when using the shortcut next time. With the basename-matching algorithm, I can use apps that I don't want to open twice with distinct shortcuts better.
Temporary Process-ID list
xstartonce creates an entry in /tmp/xstartonce-db.<user-name> for each started named shortcut. The structure is like the configuration-file: <name>=<process-id>. When executing a shortcut, first the name is searched in the configuration. If it is found, the xstartonce-db is searched for the name, and if it is found there, the window-id matching the process is looked up via wmctrl -l -p. If a window is found, it is activated. If either no window or no process is found, the command is executed.
Getting xstartonce
xstartonce has tree dependencies: A C++-compiler, Qt and a UNIX-like operating system with the X window system running. If you meet those criteria, you can download the source-code in my github-repository.
Notice:I'll clean up this blog-post and correct spelling and grammar errors tomorrow. It's already past bedtime, so I'm off to get some sleep :-)
Using keyboard-shortcuts
What I haven't mentioned, yet, is how this all works together with keyboard-shortcuts. Well, the answer is easy: Use whatever tool you know for executing keyboard-shortcuts and run xstartonce instead of the application you want to launch. I'm currently using KDE's shortcut-enabled menus together with xstartonce. You can edit KDE's menu by right-clicking it and choosing "Edit menu". Then you can add new menu-items and assign a shortcut to them.
Here's a screenshot how I do this:
Wednesday, May 28, 2008
Arora Configuration System Proposal
Introduction
First, I'd like to show you two mock-ups that I've created so you get
a feel at where I am going.
Here's the first screenshot where I used colors for each individual
section:
And here's another with the same colour for each section:
Every webbrowser has a multitude of configuration settings. Some of
them should be easily accessible by the user and some of them are for
fine-tuning and usually only the defaults should be used. There are
settings of different complexity that require different degrees of
prior (technical) knowledge. For example, an easy setting that every
user should understand is "Restore window position and size when
starting". This is just a simple checkbox in the settings dialog that
a user can either check or not check . A far more complex setting
would be a default stylesheet that should be applied to all web-pages.
First, creating such a stylesheet requires technical knowledge and
second the implications of providing such a stylesheet is not very
easy to understand.
Suggestions
My opinion is that there should be a settings-dialog that is
convenient and includes just the settings that Arora chose to be
accessible to the normal user. For advanced users, there is a
about:config page which includes all settings. But the about:config
should be nothing like Firefox's about:config. Firefox's config-page
is only for hackers and lacks usability. Here's how I'd imagine
Arora's about:config:
First of all, Opera has a nice config-page which we can base on.
You can see a screenshot here:
Navigate to opera:config and you can see it. It consists of many
sections which can be opened and closed. Every section includes
multiple settings, which sometimes have custom editors. The editors,
however, are not as convenient as they could be. For example, to enter
a color, you have to type in the hexadecimal color-value instead of
using a color-picker dialog. Every section includes a "Save" and
"Abort" button, which is very reasonable. If there was no explicit way
to save, you'd have to save after every change of the setting. And
saving often means rebuilding or redrawing something, which can be
quite annoying when just changing one simple value.
Opera has meaningful captions of each setting, too. Firefox, on the
other side, only displays the internal setting-name (which often is
quite verbose, but not as good as Opera's captions). What even Opera
is missing, though, is a description of a setting. I find that very
important, although it is, of course, very much work.
A search-functionality is also present. It even behaves awesome. If
an item in section matches, the section is displayed. Inside the
section only matching items are displayed. This way you get to the
settings you're looking for quite quickly. I think, additionally, the
config-page could include some more filters. Something like filters to
show only users or experts settings. With these filters, the
config-page could even fully replace the settings-dialog. IMHO, this
would be really cool. But again, I think the settings-dialog can
provide a much more optimized display and user interface than an
automatically created config-page ever could, so we should keep a
separate dialog that's hand-coded.
There are settings that are added to the system on-the-fly. For
example, extensions should be able to add settings and have them
displayed in the about-page like any other setting.
Implementation
To sum up which information is needed on each configuration option
that is available, it comes down to this:
- Category
- Internal name
- Display name
- Type or Class
- Editor (optional)
- Value-constraints (optional)
- Short, meaningful description
- Default value
- Flags
The Flags can be used to mark a setting as "For Experts", for example.
In the next chapter I'll discuss another usage of a flag that a
setting could have.
A Class is a combination of Type, Editor and Constraints. The
Editor and Constraints can still be overwritten when using a Class,
though.
A category, in turn, needs some more information than it's bare name,
too.
- Internal name
- Display name
- Icon (optional)
- Color
- Meaningful description, may be a bit longer
To make the config-page visually appealing and to easily find
regularly visited options, a category should have a special color. You
can see that this looks good in the mockup I provided.
With these informations, it should be relatively straight-forward
to implement some settings-classes to read and write settings and to
create the config-page.
Reading settings should be as easy as
Settings::Download::Style style = readSetting<Settings::Download::Style>("Download.DownladStyle");Writing, however, should always occur in a group. Hence there should
be a class SettingsWriter that can be used to write settings. When the
object runs out of scope, it flushes all the changes that have been
made.
SettingsWriter writer;
writer.set("Download.DefaultDirectory","/home/user/downloads");
writer.set("Download.DownloadStyle",Settings::Download::AlwaysUseDefaultDir);
If this proposal is accepted, I will work out some class-prototypes
for further discussion.
Dreams come true
To have an absolutely awesome and really magnificent
settings-system, you could think about automatically storing chosen
settings online. For example, the tab-behaviour usually should not
change no matter from where you are browsing. And now imagine that
certain settings that are marked as shared are stored on your
online-profile and automatically loaded when using Arora from a
different box with the same profile. This online-profile should, of
course, include bookmarks and history, too. Because those are more
sensitive than settings are, they are of course optional.
Friday, May 16, 2008
Arora: The first usable QtWebKit-based Browser
Arora is the name of the first QtWebKit-based browser-project that aims to become usable as a day-to-day browser for the masses. It's a spin-off of the QtWebKit demo-browser which is included in Qt and currently doesn't feature much more stuff than the demo does. It's code is managed in a git-repository at github.com and it's therefore very easy to hack on it. I have already created a git-branch and committed a small bug-fix and other changes myself, too.
This project is just a few days old and can already be used without bigger flaws. It will definitely catch on to Firefox (for basic features) soon. This is very exciting, imho, and I can't wait to see what cool things will happen to Arora in the future.
Here's a screenshot of the version that I compiled myself using Microsoft Visual Studio 2005 Express Edition:
New ELF Linker for GNU Binutils: gold
This totally slipped my radar until now. Ian Lance Taylor, an employee from Google, wrote a new ELF linker that is meant to replace ld as Linux's default linker from scratch. The new linker is called "gold" and is approximately "five times faster linking large C++ applications", according to Ian's blog-post.
It has been released to the public open-source crowd as of March 21st with this announcement.
gold is written in C++ and consists of as little as 50,000 lines of code.
Nice!
Wednesday, April 16, 2008
Passwords in Firebird
Firebird has some funny ways of handling passwords. The maximum length of passwords that is evaluated is 8 characters. Every character after the 8th is silently ignored. That's especially funny because the 'default' password for a Firebird-installation is 'masterkey', which has 9 characters. You can, however, successfully log in to freshly installed Firebird-servers providing the password 'masterke'.
I'm working with Interbase and Firebird for more than four years and just now realized that when a co-worker at our company found it out while learning SQL.
The only program that I know that makes note of that is gsec, which prints a warning when setting the password to something longer than 8 characters.
Friday, March 28, 2008
Why Crisis Core - Final Fantasy VII disappoints me
Man was I glad when my Crisis Core package arrived. I've been already playing this game since Wednesday and have played 7:30 hours until now.
Crisis Core, in contrast to Final Fantasy VII, does not have tactical battles. In fact, they're the direct opposite: They're random. Really random. Well, of course entering a battle was always random for Final Fantasy VII, but in Crisis Core even your special attacks, materia upgrade and Level-Ups are random! Who on earth had that stupid idea? There's a slot-machine-like thing called DMW (Digital Mind Wave - wtf?) in the upper left corner which spins while you beat your enemies. It spins pictures of characters and numbers. When the pictures match on the first and last slot, the "Limit Verge" appears and depending on the outcome of the middle slot you'll execute a Limit Attack.
Everything here is absolutely not influenced by you in any way. You can't tell the slots when to stop, you can't do nothing. Depending on the outcome of the numbers of the Limit Verge you or your materia might level up if the numbers come out right. Theoretically this means that you can gain two levels in twenty seconds or gain no level at all in 5 hours. More fighting doesn't necessarily increase your level either. Well, obvisouly Squeenix was smart enough not to make it as random as a true random number generator, but it's still unpredictable.
The Limit Attacks are somewhat strange, too. Sometimes there are some FMV sequences that tell a part of the story -- right while you're battling totally unrelated enemies or you are on a mission or something, before the attack begins. I don't understand this at all, it makes no sense to me.
You don't have weapons with materia slots, either. In fact, you don't even have different weapons! Instead you have a fixed number of materia slots where you can put your materia, which sometimes increases when finding special items or so. At least you have two Accessorie-slots in the beginning... but again, no weapons. This actually pisses me off most. There are no connections between materia-slot, no slots with doubled materia-exp-increase, no new weapons that do more damage, nothing.
And then there's Material Fusion. You can fuse any two materia together to gain a new one. The outcome, however, is always sooo teeny-weeny better than the originals that it almost never brings you a significant advantage. Plus, you can't predict the outcome at all and sometimes you basically just lose one of the materia, while the other stays the same. Absolutely useless.
Then there's the difficulty of the game. Being a hardcore-gamer I picked the Hard Mode over the Normal Mode. It lasted 30 minutes and I nearly threw my PSP through the room, out of desperation. I died multiple times on the first hard enemy, and the bad thing about that was that there's 5 minute sequence that YOU CAN'T SKIP before that battle. Oh jesus how I hate this! That was the reason why I didn't finish God of War, too, by the way. Un-skippable sequences are the most sinful thing a game-developer can ever do. (By the way: In Crisis Core you can ALWAYS interrupt the game by pressing Start. This somewhat makes up for not being able to skip sequences... but only somewhat.
So I decided to start from the beginning in the Normal Mode. This was a good decision, because the game basically becomes child's play after that. It's actually so easy that it's making it boring at times. Most of the time, when hitting the enemy, it's pushed back and gives you time for the next slash. This makes matches where you don't get a scratch on more than common.
The mission system is used for leveling and resembles Monster Hunter in many ways. Because you're more often in areas without enemies than you were in Final Fantasy VII, it's harder to run around and level up as I often did in the original. The missions kick in here, which you can enter on every savepoint. Pick a mission by category and difficulty, enter it, beat it, get a reward, go on to the next mission. Those are always in the same environments, like the various levels in Monster Hunter. Missions are actually a bit less boring than running around on the field to fight the same monsters over and over again. That's what I did in Final Fantasy VII for hours... or well, actually even for days and weeks. :-)
Oh and here's the moooooost disappointing thing ever: You don't have a party! You're always running around alone as Zack and you can't switch party members! That's so unbelievably boring!
There are good things about the game anyways and it's quiet fun to play, but I must say that I would have more fun if I put FFVII on my PSP again and played that for the nth time. It's just so much more tactical and muuuuch deeper than Crisis Core. Crisis Core seems to be meant for the occasional gamer and not the typical Final Fantasy RPG fan. It's more an action game with a good story than an RPG if you ask me. I hope that there are at least 60 hours play-time in that game, but I'm not too sure about that yet... I'm looking forward to find out more as the story continues, maybe I'll write some positive aspects of the game after I've finished it.
That being said, the game is still much fun. But again, it's not as much fun as Final Fantasy VII was.