- Extern Templates: using the extern keyword in front of template to prevent a template from being initialized in that translation unit.
- Initializer Lists: a new structure std::initializer_list<T> which can be used in a similar manner to C style struct initialization. This allows for syntax like: vector<int> v = { 1, 3, 5 };
- Range Based For: Say you have an array, and want to iterate through it all. A new usage of the for loop allows for this. for( int& x: myArray ) will iterate through the entire range of myArray and refer x to the current range element.
- Lambda Functions: This gets pretty cool! I'm not exactly sure how to explain it without a code sample, so here it is: std::for_each(someList.begin(), someList.end(), [&total](int x) {total += x}); What it basically does is create an anonymous ( excuse the Java lingo ) function where within the [] you can set the variable where the result of the function is to be stored. It just allows for exactly this sort of thing to be done, it's a great accompaniment to the STL algorithms. These lambda functions behave like friends to the class in which they are declared, so you have access to the member variables and functions.
- Constructor improvements: Ever had many constructors and needed to add a member variable to the class? You're liable to make mistakes and skip initialization lists for every var, and end up with an unitialized variable somewhere. Of course you could have a seperate init function, but thats obviously less efficient than using initilization lists ( since default constructors must be called anyway ). So, how about being able to call a constructor from another: SomeType(int newNumber) : number(newNumber) {} SomeType() : SomeType(42) {} Awesome!
- A Standard NULL: We've all been using NULL for a while. Now it's time to get used to nullptr. The great thing about nullptr is that it will work with overloading. Take for example two methods: doSomething( int bob ); doSomething( char* bob ); if i call doSomething( NULL ), what will get called? We'd hope the char* version of it gets called, but thats wrong, since NULL == 0, so the int version actually gets called. nullptr changes this.
- UTF-8,16 and 32 support for chars: char32_t* myUTFString = U"This is a UTF-32 string."
2008-10-30
C++0x and the final features!
2008-10-29
Apple and The App Lockdown
We've all heard about Apple not accepting apps because they're too similar to something they have or might introduce, but this is going to far. OSNews reports to my Google Reader that they have blocked Opera Mobile for the iPhone. They obviously don't care what people think of them. Or maybe they just realise that the only people who are going to care are in minority, just a bunch of geeks who rant about random stuff on the internet. But that's still no excuse. It's blatant anti-competitive behaviour.
Opera is much more functional than Safari, and renders most pages much better, and i guess that's exactly why they won't allow it. If they do, no one will use Safari anymore. So the solution, develop a better app, never! This seems to be the Apple way. Make everything really pretty and as unusable as possible. Leave out features, because you don't have a choice. Well my take is this, if i paid that much money for an iPhone ( which i haven't thankfully ), then i deserve to choose my browser. It's the same as network locking. By locking you down to a specific software set or a specific telecom network, they are practising anti-competitive behavior, and the authorities really should take action. But of course in the current climate, it seems that they are more likely to protect companies like Apple from consumers, than protect consumers from the big companies. If Apple weren't practicing anti-competitive behaviours like this, they wouldn't be in a huge legal battle with PsyStar.
Maybe one day the people will revolt and the authorities will stop protecting companies like Apple and Microsoft from angry customers. Sadly with the mentality of the masses, i don't see it happening any time soon.... just google "Celebrity iPhone"
UPDATE: Seems that Opera never did submit it to Apple, because they of the licensing issues ( probably
Windows 7 and it's brand new Kicker, i mean taskbar.
- Apple: Innovative dock, 3D effect, mouse over magnification, "Genie" minimize effect, great fonts for LCD screens. Proper transparency. Resizable ( Horiz and Vertically ).
- KDE 3: Completely skinnable, themable panel ( Kicker ). Different minimize effects, further extended by compiz. Proper transparency. Resizable ( Horiz and Vertically ).
- KDE 4: Completely skinnable, themable SVG panel. Different effects all built into window manager ( Compiz isn't required to make KDE 4 do some awesome stuff ). Proper transparency. Resizable ( Horiz and Vertically ). Ability to align to a given side of the screen ( as in, doesn't fill up the entire screen but expands from a given side ). The ability to have no panel. This sounds odd, but you can remove your panel and add the system tray and task manager to the desktop if u wish and either use the desktop shortcut key or window switching to do stuff. Why you ask. Asus EEE, 800x480 screen, a panel really takes up space.. and i dislike auto hide.
- Apple: Expose effect to compensate for the useless window switching. Expose is actually really useful, since it lays out all the windows for you on the screen, the only problem is that the mac is prone to instancing windows when you don't want them, so it becomes cluttered.
- KDE 3: Shade ability - something that is really useful, but seldom used. Shade causes your windows to collapse to just the title bar, nothing else. This is useful if you don't want it minimized, but just out of the way. With Compiz, wobbly windows, nice window snapping and some other really fancy effects, some of which are actually useful and pretty. Configure special features for certain apps, like whether to put an icon in systray, or startup geometry, or even whether it should always be on top.
- KDE 4: Shade ability. Wobbly windows and other fancy effects without Compiz. Same special features as KDE 3. Expose as with Apple except its there as an enhancement, not the only way to switch windows. True transparency. Ability to make entire windows transparent. The Desktop Effects give a series of great productivity tweaks to window management and include some really fancy effects.
- Apple: standard with widgets. Nothing really special about the apple desktop except it can support Mac OSX Dashboard widgets.
- KDE 3: standard with widgets. This desktop ( from 2001 origin ) has pretty much the same features as the Apple 2007 desktop. 3.5 series is as advanced as all the new commercial desktops. It supports super-karamba widgets and has the same basic features as Vista and Leopard.
- KDE 4: something completely different. The KDE 4 plasma team need to be commended for this. So it's a desktop with icons if you want. And folder views ( a new concept where you have a container on your desktop that shows the ( filtered ) contents of any folder you wish ). And if you have 2 folder views you can copy from one to another. And widgets. But what kind of widgets? Try almost all of them. KDE 4 plasma widgets ( obv ), KDE 3 Karamba widgets, Mac OSX Dashboard Widgets and Google Desktop Gadgets. It can also have any panel item as a desktop widget ( and vice verse ). In fact there is really very little you can't do with the KDE 4 desktop. It's about 2 years ahead of it's competition, and these guys do it for free.
- Apple: Fail fail fail. Leopard fails on an epic level here. Finding installed apps is like finding Yang Peiyi ( the poor girl that was deemed "too ugly" to sing ) on the stage at the Beijing Olympics. Spotlight tries to do the job for you, but just gets in the way, especially when you're used to Ctr+Space being a different keyboard shortcut.
- KDE 3: I was using KDE 3 with KickOff menu. And although a lot of people hated it ( again this change is bad mentallity that keeps dictators in power legally ), it was a huge improvement on the standard Windows 98 style menu. Just pop open the menu, type a few letters and choose your app. I went from old menu with a million "Quick Launch" icons, to new menu and no need for quick launch. The problem is that Quick Launch was mostly created cause menus failed. If the earlier menus were better, the masses of icons on peoples docks/panels/taskbars would be gone. And with Kickoff, i feel that this is actually happening. The menu is so easy to use, so there is no need for masses of icons.
- KDE 4: Seeing as KickOff was introduced into KDE 3 and was actually a great feature, they decided to build it into KDE 4. The pitch-forkers complained, so now you have a choice, but the primary menu is the KickOff style menu. And as with all things in KDE 4, this has been greatly improved.
2008-10-27
KDE and the apps that keep the dragon hot
- YaKuake: It's a Quake style drop down console. It has multiple tabs and a global shortcut key. It can basically do anything that Konsole can do, except that its always there and out of the way. Althought i am comfortable with the console, it isn't my primary means of working in Linux. I prefer graphical config tools, and only use the console when i must. And because of that, i need something that's accessible when i want it. I don't want a console that's always open ( i'm really fussy about the number of obsolete windows i keep open ). Now i just hit F12 and i have my last console session i was working on, and when that window loses focus, its gone till i need it again. It's a huge up for my programming productivity and hence one of the first things i install.
- Amarok: It's a music manager. And player. And streamer. And last.fm client. And mp3 player manager. And music store/discovery portal. It's pretty much everything you want for your music. At work ( Mac and Windows ) i use Songbird, which is good. And i feel Songbird is what iTunes tries to be. In the same way, i feel Amarok is what Songbird tries to be. It's got every feature from every music play you want, yet somehow the interface isn't cluttered at all. I installed the latest Amarok 2.0 beta recently and was amazed. Instant access to Shoutcast streams, LibriVox audio books and a few online music stores. The library management is amazing, and the smart playlists are awesome. Amarok is basically the Holy Grail of music apps.
- Kate: It's a text editor that wants to be an IDE. Being a simple text editor it's really fast. Quick start up time and low memory usage are not things you normally associate with syntax highlighting, session management, code folding, spellcheck and code completion. Give it a debugger and compiler and you have a decent IDE. Maybe i shouldn't say that too loud, the developers might get ideas. But seriously, it is powerful. Any HTML work myself or my wife does is in Kate. If i'm not actually doing serious code, but just want to view some source files, Kate is what i use. Sometimes i launch it as root to edit xorg.conf, and since Kate has highlight modes for x.org configs, WINE configs, .desktop files and all sorts of other Linux system files, doing stuff like this is much easier than my other alternative, VI. And on that note... Kate also has a VI input mode. As with Amarok, these interface designers are amazing, since it still seems as slimmed down as MousePad.
- GwenView: I normally don't care much for image viewers. Generally, if i can see the thumbnail in my file manager ( coming up next ;) thats ok. In the KDE 4.1 release i noticed a new image viewer, and from the start it impressed me. It doesn't take an hour to load like a lot of more complicated image viewers. In fact its pretty fast, again like Kate. Most of my usage of an app like this is to view the pictures i copy off my ( really useless ) phone. As you would expect from an average image viewer, you can rotate the pictures you're viewing. But this also has a pile more features. There is an entire plugin framework allowing for complicated effects to be applied in the same way Picasa might. But without the memory overhead and long startup. It also has some of the new KDE 4 nepomuk semantic desktop features, where you rate images. And yet still with a simple interface reminiscent of the clean feel of the old ACDSee 3.0 series. This theme of simple yet power seems to carry through, and the last item on my list is far from an exception...
- Dolphin: I couldn't give a grand enough introduction for this app. This is Finder + Explorer + Konqueror + Nautilus + Every good feature of every file manager i have every used. It can do Konqueror, Icons View + Tabs. It can do the bread crumbs we're used to from Nautilus and Finder. It does the columns view that Finder has, but it does it better. It's fast, intuitive, sleek and flexible. It's pretty much the ultimate file manager. I've heard Gnome advocates wow at it. Dolphin is what every filemanager should follow. Bread crumbs and KIO Slaves is an amazingly powerful combination. And what better place for such a well polished, feature packed tool than as the core file manager of your system. It's one of the things that made KDE 4.0 feel finished even though the desktop was still buggy. If i had to name any, i would say this is an app which defines what to expect from KDE 4. Speed, power, features and a great interface.
2008-10-24
Wine, it always tastes sweet!
Why people hate Wine:
- It discourages the development of Linux native apps
- It gives people a reason to want Win32 apps
- It opens up security risks
#pragma once
As promised, the next part of my coding in Linux guide. Last time i covered my choice of IDE, and now i'm gonna use it. My intent was to work with Open GL, and that will come in time, but after some research it seems that my blog is more popular amongst KDE users. So, this is the plan. A basic QT app, with Open GL included somewhere :)
In Codeblocks there are many project options. Making sure that you already have qt4-devel packages installed, create a new QT4 project. It'll probably ask for an Environment variable path. Define the Base to /usr and that should be it. Then Codeblocks will hopefully give you a main.cpp containing the basic QT setup. Running this app should give a simple window with a Quit button.QT reference/tutorials can be found here, its a great thing to keep open if u'r coding an app and your main aim isn't the UI. After all thats why i prefer QT, it lets me focus on my app and not have to deal with really disgusting UI code ( note GTK and Win32 ). In QT there are 2 constructs which you probably won't have seen outside of QT code:
- SIGNAL: a sort of event triggered, like clicked() or valueChanged() or anything you want.
- SLOT: a response for a signal.
To make use of the SIGNAL/SLOT features of QT, make your object inherit from QObject ( directly or indirectly ) and add Q_OBJECT right at the top of the class declaration ( just after the opening brace ). Then you have access to the slots and signals macros which can be used in an equivalent way to private and public. You also have access to the emit keyword, which allows your app to send a signal to whoever might be listening.
So, time to actually do something.In Codeblocks, create a new file, selecting a C++ header. Once you've given it a name ( and path ), you'll see that Codeblocks auto generates a header guard word! Note that although usage of #pragma once is pretty standard, it isn't actually in the C++ specification, so it doesn't have to work. Click All on this dialog to add you're new header to all build targets ( another thing i love about Codeblocks, build target config is really simple ). Create this, and create a cpp in a similar way. I made a basic QT app:
myApp.h
#ifndef MYAPP_H_INCLUDED #define MYAPP_H_INCLUDED #include; class myApp : public QObject { Q_OBJECT public: myApp( QObject* parent ); ~myApp(); public slots: void updateColor( int newValue ); signals: void colorChanged( int newValue ); private: unsigned int m_red; unsigned int m_green; unsigned int m_blue; }; #endif // MYAPP_H_INCLUDED
myApp.cpp
#include "myApp.h"Now this will not compile ( sadly ). Due to the way QT works, you need to perform a meta-object compilation, using the moc tool. If you look in your project's Build Options, under Pre/Post build steps, we can add custom commands. I added a script to my projects root folder ( called runMoc.sh ), and added the following to the custom commands:myApp::myApp( QObject* parent )
:
QObject( parent ) { printf("Creating myApp\n"); } myApp::~myApp() { printf("Killing myApp\n"); } void myApp::updateColor( int newValue ) { }
./runMoc.shThe contents of my script is:
#!/bin/sh grep -l Q_OBJECT *.h > files_to_moc cat files_to_moc | while read line do echo "Moc'ing file $line"; ext=h output=${line%h} moc $line -o "moc_$output""cpp" doneAlthough the details don't really matter, the script basically finds all .h files with Q_OBJECT in them and calls moc on them. Then the moc call generates a new cpp called moc_
2008-10-14
G1 and the struggle on Mac Mountain
The first of the android phones looms close, and what is there to show for it. We have an operating system with a lot of potential, open to developers ( sadly in Java ), and with ability to replace almost any application. And what does the HTC-Dream, er sorry, TMobile G1 have to say for itself?
- Proprietary ports, no 3.5mm headphone jack
- No A2DP for bluetooth ( Stereo bluetooth headset support )
- No MS outlook/Desktop sync
- 1 GB memory card ( note, the Sony Ericsson W900 avail 2005/2006 had a 2GB card )
- Virtually no truly custom apps, in the sense that HTC could have taken advantage of replacing some primary apps with amazing stuff
The advantage is the freedom of platform. As a software developer ( who dislikes Java ) i really appreciate the ability to write daemons, and apps that could replace my contacts/sms apps. I keep mentioning the Java issue. My reason for this is as that i am currently an iPhone developer, and altho i dislike the proprietary platform, the performance is amazing. The reason is not the hardware, since they're about the same. Java is the killer. iPhone development happens primarily in C++ or Objective-C (yuck). Both of those are on hardware, low resource languages. When i saw the android demo of a bouncing ball at 40fps ( which he was boasting about ), i laughed. With a full 3D scene, some 3D physics ( including sphere/trimesh collisions ), and about 3000 triangles, we're getting 30fps on the iPhone. 40fps for a 2D sprite is disgusting. I'd have been ashamed, to even admit i was only getting 40fps.
This all said, i'm still debating whether or not to get the G1, or if i should wait for Samsung, LG or Motorola to release their android models, and get an iPhone now? The G1 is only coming to my ( Netherlands ) shores in Q1 2009 ( along with Germany, Czech Repl, and Austria ), so it's a while to wait. Luckily US consumers get it this month ( 22 Oct ) and it's slated for launch in November in UK.
It's a really tough choice, because the iPhone is an amazing piece of hardware. Again i am very against proprietary formats, but the iPhone is really what they claim, and even though its closed, its the best phone around by a long shot.
Whatever happens, i'll have some interesting news on both iPhone and Android Games soon ;)
2008-10-12
Stackoverflow and the solutions we all seek
As a developer it can be _really_ frustrating looking for solutions to problems. Say you're working with a new library, and you know other people use it, but you have no clue how. This often applies when you're using C++ and get some hardcore C library, that would only make sense to people who have been coding in C in a basement somewhere for the last 10 years.
A common complaint that i have, and it seems i'm not alone, is that you can search for days and mostly get one of 3 things:
- nothing,
- a site with unanswered questions,
- or a site that asks you to sign up to view the answers.
Then i discovered stack overflow! It's a site that allows users to log in ( with any openID account if you have - blogger account is part of it ), and post a programming related question. Anyone can view this, whether you have an account or not. Now i hear what a lot of people will say, its all good to have a forum, but people will have to read it. Well, there are at least 2 people who work for the site that will look over the questions they can answer. But still, no 2 people can know everything right?
My trial of this site shows me that there is more than enough traffic to generate answers to questions. I've posted 3 questions so far, each one generating at least 3 answers within the first week, and getting over 50 user views. All of my questions have had pretty satisfactory answers, 2 of them telling me exactly ( including some code posts ), what i needed to know. The last one, my question was illdirected and badly phrased, and i still got a good answer to my question, even though it wasn't what i was looking for.
So if you're a developer, i really advise having a look, its a great site, and more knowledge never hurt anyone ( except a few organisations ).
Google Docs ftw!!!
It seems that google docs has an options to post from google docs to a given blog, including blogger!!! Since i really hate the blogger interface, and can never get a blog written through it, this is an official test to see if it works. Well done google for realising how much the blogger interface sucks
2008-10-08
#include
In the next few weeks i will be posting a series of blogs about development of applications on linux, 3D graphics, physics, networking and all of my discoveries as a developer. This should include some warnings, tips, tricks, and anything useful to developers who primarily use linux. This first post will focus on tools!
As a developer who has worked commercially in a Windows development environment, i have to admit, Visual Studio is good. Sadly ( although it would benefit Microsoft greatly ), VS is Windows specific. So what to do if you want to develop on a Linux OS? There are many environments out there, and in my opinion most of them suck. I want to be able to develop for anything, i like my graphics and physics based applications, but i don't want to be forced into writing a GUI. Sometimes i want to write a GUI, and something like GTK# really doesnt do it for me ( i much prefer QT ). I want code completion, my typing sucks. Although i've been coding for years, i'm still a bad typist. Makefiles are a pain, but if i want them, they must be accessible. At the same time i want to be able to just quickly create a project without having to worry about setting up makefiles and stuff like that. And Visual Studio solution support wouldn't hurt. And if anyone wants their IDE to be more like XCode, they've been working on a Mac too long and need a break.
My tests taught me this:
- Monodevelop, which now supports C/C++, crashed randomly, and is too specific to certain tasks. I don't like GTK#, and it took me four hours to create a checkered board on a gui in monodevelop. The C# support and Visual Studio solution importing is nice, although i am not a fan of C#, but for C/C++, the IDE is disappointing
- Anjuta is not fully featured. I tend to steer clear of GNOME based technologies ( excepting GIMP ), and although i gave this a try, it seems to be more geared to GNOME development, which makes sense. I want a general environment, which i feel Anjuta falls short of.
- KDevelop has some big advantages. The project support appeals to me, and the fact that is was simple to set up some stuff is also a big plus. It is geared toward KDE development, again this makes sense, and tends to be more specific. It is makefile driven, but the built in automake tools can remove the effort of setting up a makefile. However, being makefile driven still creates it's own problems, and can limit development time in this environment. Productivity is my main goal, i don't want to spend time setting up stuff, i would rather be coding.
- Eclipse is a big one. I will state here that i am not a fan of java or most things written in it. Speed matters to me, and i have never felt that a Java application or it's interface feels correct. Eclipse is no exception. It uses up way too much of my ram and feels like i have to fight it for the processor.
- Netbeans is for me the same as Eclipse. Slow and chunky. Altho it would be my second choice. Its C++ features are not bad, and altho it has a lot of polish, it lacks some nice little things.
- CodeBlocks is a cross platform ( Win/Lin/Mac ) C++ IDE. It is fast, feature packed and surprisingly visual studio compatible. It has a whole bunch of project templates, ranging from Ogre, openGL and irrlicht to QT4, GTK and wxWidgets. The reason i discovered Codeblocks was exactly this, i needed to make an Ogre project ( for a physics engine ), and this IDE was suggested. The latest version supports VS2005 and 2008 solution files, which is great for compatiblity. It supports ( minimally ) makefiles, which is good to know.
Being my choice, Codeblocks is what i will refer to for the rest of this series. You can get it from www.codeblocks.org and installation is pretty simple. Using openSUSE 11.0 linux, all i did was searched the Webpin software repo's and installed the latest version i could find.
If anyone has any other suggestions for IDE's, please do let me know, i'm always looking for new software to play with!
Next Week i will hopefully cover some basics of 3D graphics in openGL.