Dec 31 2008

Refactor for C++ – addendum

Category: Programming, toolsMaciek Talaska @ 6:01 pm

A few days ago I have written a short note in which I have enclosed some of my thoughts about freely available Visual Studio 2005/2008 plugin for C++ developers (DevExpress Refactor for C++). I have pointed out that Refactor had some problems with simple refactorings in one of my projects. The simplified code snippet I have provided is not good enough to help understand the problem (the snippet seems to be too simple, and it is impossible to encounter the issue I was writing about). I have spent some of my spare time to find the code that caused problems and try to analyze it and provide a code snippet that illustrates the issue. The following code is very close to the one that I have checked to be error-prone:

// forward declaration    					//(1)
void functionEx( );    						//(2)
typedef void( *void_function_pointer)(void);			//(3)

class SimpleClass
{
private:
	void (*function_pointer)( );				//(4)
	void_function_pointer func_ptr;

	void SetCallBack( void (*function_pointer)(void) )
	{
		this->function_pointer = function_pointer;	//(5)
	}

public:
	void function( )
	{
		printf("\n");
	}

	void Prepare( )
	{
		SetCallBack( functionEx );
	}

	void Invoke( )
	{
		function_pointer();
	}

};

SimpleClass *externalObject;

void functionEx( )
{
	externalObject->function();				//(6)
}

int _tmain(int argc, _TCHAR* argv[])
{
	externalObject = new SimpleClass();
	externalObject->Prepare();				//(7)
	externalObject->Invoke();				//(8)

	return 0;
}

First three lines (marked with (1), (2) and (3)) are just simple forward declarations of global function and pointer to the function that takes no arguments and does not return anything (’procedure’ in some languages). Declared function pointer is used inside SimpleClass (4) and SetCallBack assigns argument value (function pointer) to variable inside SimpleClass (5). Global function ‘functionEx’ (6) does nothing more than calling ‘function’ from object of type ‘SimpleClass’. Where’s the problem here? It seems everything is simple, right? Right. But it is the simplified version of the code I have after I manually renamed function names. The code I was working on was not object-oriented at all – at the beginning. Let’s imagine, that the name of global function is not ‘functionEx’ but ‘function’. Code does not compile. Ok. Lets use Refactor C++ to rename the name of the global ‘function’ to anything that will be different than the name of the method inside SimpleClass. The problem is, Refactor tries to rename things that shouldn’t be renamed, and skip those, we would like to have renamed. Moving cursor to ‘Prepare’ function, selecting ‘function’ (remember, we do not have any ‘functionEx’ in our code!) makes something strange: refactor tries to rename ‘function’ but… it renames the name of the method inside SimpleClass instead of the global function. And now imagine, that the code is a bit more complex, that there are a couple of files inside the projects – headers and .cpp files… This ‘unwanted’ refactoring makes more harm than good (in this case). You may say, that it is because of the code, that looks the way it does… I do not think so. I would expect refactoring tool to be much more ‘intelligent’, but still it is better to have anything (even not the state-of-the-art refactoring tool) than to be forced to make all editing by hand.

I was very interested if the mentioned earlier Whole Tomato’s Visual Assist X will be intelligent enough to cope with renaming the ‘function’. Well, Visual Assist X provides its own mechanism for renaming (not so well integrated with Visual Studio editor as in case of Refactor for C++) and it is much easier to perform renaming, because Visual Assist X shows what actions it is going to perform (and you may uncheck those, you don’t want to happen). Visual Assist X by default wanted to rename the method inside SimpleClass – just like Refactor for C++. So it seems that there is no perfect solution, and one has to be very careful while refactoring anything that contains any non standard pieces of code. Just be aware that something like the issue I have described above may happen, and that’s it.

Happy coding in 2009 :)

Tags: , , , ,


Dec 30 2008

So… what’s the Green paper thing?

Category: booksMaciek Talaska @ 9:56 pm

A few months ago I discovered Manning. You may already know about it, but for those who didn’t – Manning is publishing company. The publish books. IT books. So what? There are many other publishing companies around, so why write about Manning? Well, there is something different about Manning. They not only allow you to download sample chapters and table of content for all their books, and they do not only have interesting MEA Programme (Manning Early Access Programm – go and check it out on their site), but the give something else for free. Green papers. What is green paper? Sample chapter are not as convenient form of making your mind about book, as possibility to read a few pages from here and there – as you would act in any real bookshop. Green paper is a small document about the subject the book is written about. It helps you decide if the subject is really what you’ve been looking for, or not. The greatest thing about green papers is that even if the book turns out not to be the one, you gained some knowledge, right? And there isn’t anything like ‘unnecessary’ knowledge. (You’ll find green papers with all other free content inside ‘Free Content Center’ section – on the main side of their web site)

* * *

And I were to write about Manning’s December 2008 daily ebook giveaway and discount, but… I forgot ;/ Anyway, there is still a chance to win a free ebook, and after registering you should get a special discount offer (35% off for purchasing anything at Manning till the end of 2008).

Tags:


Dec 25 2008

All developers are equal, but some are more equal…

Category: ProgrammingMaciek Talaska @ 12:48 am

Microsoft Visual C++ from Visual C# developer perspective…

After a while developing apps only using .NET (mainly C#) I felt a need to get a deep dive into C++ programming (DirectX). First impressions? It seems that VS is completely different (much harder) to use if you are C++ developer. There are many things that do not work as good as when using C#. First problem is that Intellisense for C++ is much poorer. You got to deal with .ncb files (sometimes the only solution is to delete .ncb file in your project and then… surprisingly IntelliSense gets back from grave).

Worth noting is that DevXpress (Microsoft partner) released another great plugin for Visual Studio without charging for it: Refactor for C++ (the plugin is mentioned also on MSDN site: http://msdn.microsoft.com/en-us/visualc/bb737896.aspx). It is definitely something you should give a try (and I bet you won’t stop using it). Don’t be fooled by installer – the latest version DOES work with Visual Studio 2008 (and not only 2005 as you could think from what is being displayed during installation). Having Refactor for C++ is much better than not having any opportunity to refactor code, but… there are many things that any Visual C# developer is used to, and think of as a ‘must be’ feature of Visual Studio IDE. The refactorings offered by DevExpress’ product are really simple, do not expect possibility to move function body between header / cpp file, extracting parts of a function to another one does not work as I expected, and even simple renaming caused me some problems. Let’s take under consideration following piece of code:

// forward declaration
void RenamedFunction( );

class SimpleClass
{
public:
    void function( )
    {
        printf("<SimpleClass/>n");
    }
};

SimpleClass *externalObject;

void RenamedFunction( )
{
    externalObject->function();
}

As you can see Function is a global function name, and also a name of the SimpleClass. I had similar situation in my code. I wanted to rename Function, and what happend? Well… Refactor renamed it, but… it also renamed the name of the method (SimpleClass->Function became SimpleClass->NewName). I have fixed function names in several places, and created a new project to test if it is safe to rename functions using Refactor for C++ but I couldn’t get the same behaviour – so maybe it really WAS my fault ;) Well… I have checked it in my project… and yes, it still renames the global function AND method inside SimpleClass… I wonder why this bug does not occur in the sample I have provided above… I’ll try to investigate this issue further on.

Most of the things I am missing in Visual Studio IDE itself and Refactor for C++ are available through great plugin by Whole Tomato Software – Visual Assist X. I am sure, you have heard of its biggest opponent – Resharper from JetBrains, so why should be interested in Visual Assist X? The answer is simple, if you never ever use any other language than C#/VB.NET – you have two options: Visual Assist X or Resharper – they both increase coding speed and make you being less afraid even if there are some complicated refactorings to be made. And if sometimes you use C++ as your development language (especially unmanaged)…Visual Assist X is the only option available.

The last thing that made me mad was… VS seems to ‘lost’ support for .hlsl / fx files (pixel/vertex/geometry shaders written in HLSL / Cg). It is kind of a strange, because I remember that it worked long, long time ago (around August 2005 – Visual Studio 2005 Beta with DirectX SDK from August 2005 as far as I can remember). Why doesn’t it work now? It is hard to say. I don’t even know if it’s an issue of VS2008/2005 or just something was broken inside DirectX SDK (I am currently using November 2008). It is funny how quick one became used to something that was a ‘wow’ feature not so long ago :) I missed syntax highlighting in effect / hlsl files so much, that I started looking for some alternative or plugin for VS or some .xsd file (with definition of shader key words) at least… And I found one – Intellishade.Net. It is great that someone gives for free something I thought Microsoft offers :)

After all this, I am really curious what has been said on one of the PDC 2008 sessions concerning new Visual Studio (I think the title of the session was: “VC10 is the new VC6″). I really hope that there will be enough encouragement from all C++ developers, so that MS creates a lot more convenient and powerful IDE for VC++ developers. There is still need for the good C++ IDE for Windows, and I think it is much behind Visual C#. C++ is not dead, and it seems that it won’t be for a long time.

Tags: , , , , , , ,


Dec 24 2008

Migration: from Blogger to WordPress

Category: BloggingMaciek Talaska @ 1:50 am

For last couple of weeks I was preparing to move my blog to WordPress powered blog. At the very beginning I thought It would be not possible to move my actual content, but it became easier than I have imagined. The first thing to notice is that my original blog was hosted by Google (at their blogspot service). And moving blog content from blogspot (blogger) was the hardest part. First of all, you should be aware, that WordPress as a platform supports import and export. It is able to import content from different sources (as shown in the picture).

image

The export is available as .xml file (that could be later easily imported to another WordPress blog). Back to migration… The first thing to do is to log in to your google/blogspot account. Then, choose import (blogger) and you will get redirected to your google/blogger account with information that there was a demand to authenticate. You should agree, and all your posts, comments (categories too!) are being transferred into your WordPress blog. But… that’s not exactly the case I had to go through :) The hosting I am currently using does not support SSL, and Google does not allow authenticating if request is not made over SSL. But there is another way to go. You may simply create a ‘temporary’ blog on WordPress.com. They support SSL, so there is no problem in getting all your blogger account content. The next thing is to export imported content, and import it in any WordPress blog (it may actually take a while, and there’s been some problems with huge blogs – containing 2000+ notes – but in this case, the solution is to divide xml file into a few smaller ones). The whole process is quite simple, and it didn’t take me more than half an hour to go through it. Nice thing worth notice is that you will be asked if you want to have an account created (account with the name that all posts in blogger was signed by), so after the import you should be ready to post :) ah… another thing, as you may expect, categories are being imported without problem, and they are being automatically assigned to posts during import. Worried about drafts? They get imported too (as drafts, of course :)

Great piece of software, great features, great blog engine. Nothing more to add.

Tags: , ,


Dec 15 2008

Usability & User experience

Category: UI designMaciek Talaska @ 11:30 pm

A few days ago I wrote a short note about the importance of GUI. But GUI alone – the set of graphical widgets, that present information and allow to perform actions – is not everything one should consider when creating application. The second, very important thing while designing application is to focus on how this application will be used, make it as easy as possible, create interface that will be easy (so easy, that users will not have to read documentation just to get to know how to perform some tasks, that application is capable of performing), interface that will not be annoying (avoid forcing user to click in many places to perform one action) and many more. Wikipedia’s definition of usability is: "Usability is a term used to denote the ease with which people can employ a particular tool or other human-made object in order to achieve a particular goal. Usability can also refer to the methods of measuring usability and the study of the principles behind an object’s perceived efficiency or elegance." So, I think, there is no need, to explain further what ‘usability’ (in terms of designing software) is. Let’s face some real-world examples:

Control Panel link in Start Menu (Windows 95)

Windows 95 GUI was fresh, and gave much better user experience than the old GUI designed for Windows 3.x. Although there were a lot of small ‘bugs’ or things that were possible (not at the first sight) but were not easy to achieve. One of them, was creating a menu (link) to control panel in Start Menu. It was possible. The only things one should do, was to find proper key in Windows Registry (well, not the key, but it’s GUID was to be found), and create a folder, which name was GUID itself. This kind of folder pointed directly to the content of Control Panel. The same trick worked for other special folders. Anyway, the thing is, that some of my friend, that were proud Mac owners at the time, claimed, that it ’stupid’. Stupid, because it so hard to do, and Mac allows to do such things just using drag & drop technique.

Fonts in cmd.exe

When you look a little bit closer to cmd.exe (or command line console – if you prefer) you realize, that this ugly bitmap font (the default one) hasn’t changed for a long, long time. It is default font, and it looks the same (or rather: is as much ugly) in Vista and in Windows 95. Can’t it be changed? Of course, it can. And again, it could be made by digging and changing Windows Registry.

Where does my tab-close button go? (Mozilla Firefox)

Firefox was one of the first browsers that incorporated tabbed browsing – something that many of us can not imagine surfing without. But there is some strange behaviour of Firefox, when it comes to tab-closing button. If you have only few tabs open – it is always placed on every tab (on the right side on the tab title). But what happens, when user opens more, and more tabs? Well… the button disappears! Simply, none of the tabs has it. Why? I don’t know. What’s the solution? Ctrl+T for new tab, in the address bar type famous "about:config", browser.tabs.closeButtons’ value should be 1 (to show tab closing button for all tabs), and browser.tabs.tabClipWidth’s value should be way smaller than default 140 (this value is the minimal width of the tab title, if its smaller, tab close button is being not displayed).

Did you expect that there is still so many to do in the field of user experience, usability? Is there anything that software designer could do, to make their applications better? Of course! In the first two examples the changes are obvious. In the first case, managing special folders should be the same as ‘normal’ folders, so copying them, linking to them should be possible – there is even better solution: a wizard that will let anyone personalize its start menu (similar to what it is being done right now in Windows XP and Vista, but it could be a bit more user friendly, IMO).

I am wondering, what is so hard in making ‘Courier New’ or ‘Lucida Console’ (both of them are TrueType fonts) the default font for cmd.exe? Those fonts look a lot better than default bitmap font (which is so ugly, that I wonder how anyone can actually work with console that has this font set).

And the last issue… I assume that the worst thing in the case of ‘disappearing tab close button’ is that it is silent. You’re just surfing the web, opening more, and more pages, maybe close your browser, and restart it the very next day… and there is a moment, that you realize the buttons are gone. And it’s so strange, because ‘they were always present, on all the tabs’, right? So first of all, I think that Firefox should warn user (but not with standard message box dialog that nobody ever reads) that tab closing buttons will not be displayed anymore (as long, as tabs are so narrow). I think, this message box, should have some animation showing that the button is being ‘kicked off’ from tab titles (it’s not hard to do, just a small gif containing about 8 frames of animation will do). The message box (or dialog box – better) could provide a smart wizard, that will let user choose how the browser should behave. That’s it. I think, it would be much better, and less confusing for many people.

Usability could be taught on example, there are dozens of applications around, and it is sometimes a good idea to think if they work the way users expect, or users are just used to applications’ design? How many clicks does it take to perform a simple action? And how many different ways exist that allow to perform a specified task? Are all the ways obvious? Does user need to go over and over to some kind of menus to change some properties during work? Are the most common tasks and options grouped? How? Are messages easy to understand to anybody (not only some techie guys)? There’s definitely more question that software designer focused on GUI and usability should ask while (re)designing.

At the very end I would like to point that there are some books that should be interesting for people who think that designing GUI and usability is not just a waste of time and resources. First book I think is worth reading is "User Interface Design for Programmers" by Joel Spolsky (it is also worth to take a look at his blog). The other book I think is worth reading is "Why Software Sucks And What You Can Do About It" by David S. Platt (there is a sample chapter available on David’s book page). Have you ever thought that there is no point in thinking about some small parts of the application? David presents great example: the message that user gets when they want to close application and their work was not saved. Is the standard message easy to understand to anyone? It definitely should, right? There is a thin line between sticking to standard solutions used in GUI design we see in modern apps, and the need of improving user experience. If nobody at Microsoft thought that problem of Office was in its poor GUI – Ribbon would never appeared. The same thing is with context menus: why options (entries, whatever) are being placed one under another? Is it really comfortable? Or was it the most simple solution (rendering rectangle is the simplest what you can actually do in graphic environment). I’ve seen lately some proposals to change standard context menus to
circles (all the options are equally available in terms of ‘mouse distance’). There’s a lot more to think about. I just hope that modern apps are going to be more and more easy to use (so they make us all more productive, and we’ll all have more time to relax and enjoy our lives).

Tags: , ,


Dec 11 2008

FreeMind alternative, really?

Category: toolsMaciek Talaska @ 11:03 am

For quite a long time I have been using FreeMind as a mind mapping software for day-to-day basis. I am used to it, but its ugly user interface (and especially those ugly fonts!) keeps me searching for replacement from time to time. Recently I spent another hour searching for alternative. I have found XMind. XMind was a commercial only application before, but now a free version is also available. The differences between PRO and free versions are not crucial for me, and I didn’t even thought about spending money on the PRO version (you may check detailed feature comparison). Anyway, lets start testing it. First impression? Whoa! It is beautiful! Ctrl+Shift+Esc… and hm… XMind allocates about 60MB at the very beginning. A bit too much I think… (and I didn’t start working! I just run the app!) A few more clicks (importing my mind map created in FreeMind) and… yup, definitely it is eye-catching. Fonts on the mind map are very well antialiased, all the shapes looks very nice, same as connecting lines. The whole structure is very clean, icons are big enough to notice them at the first sight. Mind map is actually colored but it does not look like a fireworks during fiesta – no need to be worry about it ;) The impression while using are, although, mixed. The app looks great, but sometimes user does not have good experience of application’s responsiveness… what am I talking about? I have tested both apps (XMind and FreeMind – just for comparison) with the same mind map (created originally using FreeMind). This mind map consists of 76 object (including the ‘root’ one). The maximum depth is 6 levels. As you see it was not very complicated. And while using XMind I had the feeling that my quite new cpu (2.6GHz Core2Duo) is lacking some power… yes ;) Collapsing / expanding and moving whole mind map (even if big part of it was already collapsed – so not visible) was quite slow. Much better impression is being made while scrolling with scrollbars than “dragging workspace” (right-click & drag). There are two panes that I think should be incorporated into FreeMind: outline and properties. Outline is special view that lists all objects on workspace in hierarchy. It would be great if clicking on anything in outline made it active in main view… It does not work that way at the moment (it is very strange, because one expects that). Properties pane is used to quickly change properties of workspace and how it is being rendered. It allows changing outlook of workbook (workspace), user may change default shape, default type of connector lines and font. Properties pane makes a lot of work easier and allows to quickly change whole outlook of current workbook (workspace) in very convenient way (it is very easy to see how the structure will look if one uses different font or connector lines type). A few minutes passed, time to see how much memory does XMind consume… 180MB. Well… it is way too much. Working with XMind is easy. One do not have to search through help to find how something should be done. User interface is really well designed, there are dozens of predefined shortcuts, so most of the work could be done without touching mouse. It may be a power of being used to, but I think that +/- (XMind) for collapsing / expanding is worse than just hitting space bar. But customizing XMind’s shortcuts is really easy, and there is always a possibility to revert all changes and restore default settings. XMind allows using one of predefined themes – bunch of predefined colors and properties, that change the way your scheme looks like. Another couple of minutes… and XMind uses about 290MB (hey, and some said that Vista’s memory consumption is huge, so how do you call that?). The best thing about XMind is that is not only a mind mapping software. It allows creating many different types of structures: fishbones, spreadsheet, organizational, tree and logic charts (and mind maps of course ;) There are a few more things that XMind has to offer: markers, notes, creating relationships, boundaries (creating a special shape around selected objects) and a few more.

FreeMind is much smaller application than XMind. Working with FreeMind sometimes fools user: application behaves as if it was doing a lot of hard work, even if the only thing that is happening is just mouse cursor moving over objects. The (default?) behaviour of selecting object that mouse cursor is over gives user kind of a quirky feeling… the selection is not immediate, and it seems lto be a task very hard to achieve. There are a lot of useful shortcuts in FreeMind (and personally I think that they are much better designed than those in XMind). Creating and managing mind maps is easy, but one has to stop focusing on how ugly the app and mind maps created using it are… Being the opposition of XMind – FreeMind consumes only a fraction of memory that XMind does. At the beginning it allocates about 50MB, and if minimalized, this value drops to only few MBs. Sometimes (after using it for quite a while) it take about 20-30 MB more, but I didn’t see it allocating more than 100. The biggest issues with FreeMind are related to its poor GUI design and ugly outlook. The fonts look horrible and whole mind maps too (fonts are not antialiased, so as shapes and connecting lines). If you select all objects on mind map and try to change font – be aware that those object which are not visible (collapsed) will not have its properties changed – not really nice surprise after expanding.

So… Is XMind worth trying? Definitely yes. Am I going to give up using FreeMind? No. Two biggest issues are: memory consumption (it is hardly possible to use it as a background app with almost 300MB allocated by such a simple app) and lack of possibility to export created mind maps into FreeMind again. Mixing FreeMind (and especially its small resource allocation) and xmind (almost everything else ;) is the way to create the perfect mind mapping application.

So, just to sum everything up:

FreeMind:

Pros:

  • free
  • small
  • available for many platforms (written in Java)
  • small memory & resource consumption
  • shortcuts are very well designed, for most of the time one does not have to use the mouse at all

Cons:

  • ugly (especially fonts – not antialiased (even if one sets up antialiasing for all apps)
  • GUI is far from being convenient
  • responsiveness while selecting objects… one may sometimes feel some strange delays
  • still in BETA
  • if there are some objects hidden, hitting Ctrl+A (select all) and changing font (for example) does not have any effect on those objects that are collapsed… don’t like it.

Xmind:

Pros:

  • free
  • beautiful
  • creates very good looking mind maps / charts
  • it is much more than mind mapping software – it could be used for designing variety of things structures
  • outline view is definitely a big plus (or rather to say it will be a good thing if they improve it a bit)
  • properties view – very good idea
  • imports FreeMind’s and MindManager’s mind maps
  • able to store mind maps online (but hey, who really needs this kind of feature in the era of free online storage services?)
  • based on Eclipse, so it is easy to use to all those people used to Eclipse environment
  • available for many platforms: Windows, Mac, Linux…
  • portable version available (quite big, but it has java included, so it may be possible to
    use it on machine that does not have Java Runtime installed)

Cons:

  • huge, HUGE, AMAZING, ridiculous… memory consumption (it may be related to using Eclipse framework, which itself is memory hungry app, but… 300 MB?)
  • lacks export to FreeMind and /or MindManager (it seems that even PRO version is lacking this functionality)
  • slow (while moving mind map around, collapsing / expanding – even if animations are turned off)
  • selecting object on outline view does not select the same object on the main workspace, so outline is somewhat useless…
  • portable version is HUGE: ~110MB of free space is required
  • you have to register to download it (God bless GuerillaMail? ;)

Last minute news: at the time of finishing this note, XMind was allocating 450MB… no comments…

Tags: , , ,


Dec 07 2008

Color customization in CodeRush XPress

Category: Programming, toolsMaciek Talaska @ 8:30 pm

A while ago DevExpress introduced a new, totally free product for developers using Visual Studio – CodeRush XPress. I found it quite helpful, so it became one of the plugins I am using during my day to day developer activities. However, I was looking for possibility to change default colors (I have black background in my VS environment, so not all the colors are easy to notice), and couldn’t find one. Recently, I have found the solution on DevExpress site. It’s a pity, that one must be aware of this magic key combination, instead of being able to configure plugin behaviour from VS options menu. Anyway, after pressing Ctrl+Shift+Alt+O (easy to remember, right? all the modifier keys and ‘O’ as in Options ;) you will see an option dialog, with dozen of things to change (or better: ‘personalize’):

CodeRush XPress' option dialog.

Tags: , , , ,