giovedì 26 giugno 2008

Finally Ganymede

Width CDT 5.0, the best c++ IDE on Linux


After install all Ganymede milestone versions and all release candidate finally Ganymede is here.
On this post I try to summarize all previous post about this new version of Eclipse and CDT, I never see an IDE like this for Linux.

Uninstall previous version


It is not necessary to uninstall previous version, you can also have two different version of Eclipse, just use two different directory (as I told on the post "Install Eclipse Ganymede RC2 (with CDT 5.0)").
You can follow my post "Uninstall Eclipse" for see how to remove Eclipse. I have installed on my machine Eclipse Europa and Eclipse Ganymede RC4 so I remove all using:
sudo rm /usr/share/applications/eclipse-ganymede-rc4.desktop
sudo rm /usr/bin/eclipse-ganymede-rc4
sudo rm -rf /opt/eclipse-ganymede-rc4/

sudo rm /usr/share/applications/eclipse.desktop
sudo rm /usr/bin/eclipse
sudo rm -rf /opt/eclipse/


Now we do not have Eclipse installed on our machine...inhale slowly and don't panic.

The only part we not remove is the .eclipse directory in the home, where are stored user settings. If you want to clear all you need to remove also this directory.

Install Ganymede


For Eclipse installation I prefer to download it from the Web instead of use Ubuntu repositories, we need to wait too much time for see the new version debianized on repositories.
Download the Eclipse package for your platform from the Eclipse download page.
Usually, as you know, I install Eclipse in the /opt/ directory, this seems to me the clean way, but you can also extract the archive and double-click on the eclipse icon.
I already told on how to install Eclipse in the /opt/ directory on my most readed post "Using Eclipse for your gtkmm project (new version)".
Open a Terminal and first we need to extract the archive and move it on the right place. I download the archive on my Public directory, the first row move on the download directory.
user@ubuntu710desktop:~$ cd Public/
user@ubuntu710desktop:~/Public$ tar xzf eclipse-cpp-ganymede-linux-gtk.tar.gz
user@ubuntu710desktop:~/Public$ sudo mv eclipse /opt/eclipse
[sudo] password for user:
user@ubuntu710desktop:~/Public$ cd /opt/
user@ubuntu710desktop:/opt$ sudo chown -R root:root eclipse
user@ubuntu710desktop:/opt$ sudo chmod -R +r eclipse
user@ubuntu710desktop:/opt$ sudo chmod +x `sudo find eclipse -type d`
user@ubuntu710desktop:/opt$


Now we can create the launcher in the /bin/ directory:
user@ubuntu710desktop:/opt$ sudo touch /usr/bin/eclipse
user@ubuntu710desktop:/opt$ sudo chmod 755 /usr/bin/eclipse
user@ubuntu710desktop:/opt$ sudo gedit /usr/bin/eclipse


The last command run gedit (you can use your preferred text editor), we need to paste this text on the file:
#!/bin/sh
#export MOZILLA_FIVE_HOME="/usr/lib/mozilla/"
export ECLIPSE_HOME="/opt/eclipse"

$ECLIPSE_HOME/eclipse $*

save the file and close gedit.
Now we can add the Gnome menu entry (I use gedit):
user@ubuntu710desktop:/opt$ sudo gedit /usr/share/applications/eclipse.desktop


we can paste this text:
[Desktop Entry]
Encoding=UTF-8
Name=Eclipse
Comment=Eclipse IDE
Exec=eclipse
Icon=/opt/eclipse/icon.xpm
Terminal=false
Type=Application
Categories=GNOME;Application;Development;
StartupNotify=true

save the file and close gedit.

Running Eclipse


Now on the Gnome menu we can see the Eclipse entry:

Unfortunately we don't have the eclipse icon so on the menu we have an anonymous icon. On gnome-look you can find an Eclipse icon (here), if you want to use this icon type the correct name on the "Icon=" line.
So we can run Eclipse, the splash screen of Ganymede is darker:

and, as usual, when we install a new version we need to select a workspace:

Features


On the CDT Wiki site we can find the page "New in CDT 5.0" with the list of all new features.
The first feature I notice was the spell cecking, enabled by default.
I already write a post on the new features when I try the RC2 "Install Eclipse Ganymede RC2 (with CDT 5.0)", but since I join the Ganymede Around the World contest, I need to rewrite my impression.

Spell checking


At first sight I notice the spell checking feature (enabled by default) for strings and comments. I read that this plugin already exist on the previous Eclipse version, but this feature impress me. If you make a mistake writing a comment the unknown word become underlined in red and if you move the mouse pointer over the wrong word a tooltip display availabe fixes.


Doxygen integration


A good news is the doxygen integration in the editor. If you enable this option for the project when you start a function documentation using "/*!", when you press [enter] Eclipse automatically add all the doxygen tags for the current function, insert a "@param" tag for each function parameter and the "@return" tag if the function does not return void.

And if you want to write the documentation for an enum, always using "/*!" before the enum declaration, when we press [enter] Eclipse automatically put the documentation for each enum member:

The documentation plugin suggest us also the list of tags when we press [ctrl+space].

Refactoring


While on previous CDT version we have only the "Rename" refactoring, now we can:

  • Generate Getter Setters

  • Hide Method

  • Implement Method

  • Extract Constant

  • Extract Function


When we select a refactoring Eclipse display a preview window before apply changes on the code.

Generate Getter and Setters


This refactoring simplify the class attribute writing. If we declare a private variable:
int value_;

and then right-click on this and select from the menu "Refactor->Generate Getters and Setters", with a wizard (or assistant) Eclipse automatically write the two functions for get and set this variable:
    int getValue() const
{
return value_;
}

void setValue(int value_)
{
this->value_ = value_;
}

The const get function and the void set function. From the wizard dialog we can choose also if we want to create only the getter or both.

Hide Method


This refactoring "move" a public function in the private section of the class. If we declare a public function:
class BaseClass
{
public:
BaseClass();
virtual ~BaseClass();

int getValue() const
{
return value_;
}

void setValue(int value_)
{
this->value_ = value_;
}

void myMethod(int arg);

private:
int value_;
};

When we right-click on desired function and select from the menu "Refactor->Hide method" we get:
class BaseClass
{
public:
BaseClass();
virtual ~BaseClass();

int getValue() const
{
return value_;
}

void setValue(int value_)
{
this->value_ = value_;
}

private:
int value_;
void myMethod(int arg);
};

If we have not a private section on the class Eclipse automatically add this section.


Implement Method


This is for me the more useful refactoring. If we declare a function in the header file:
    void myMethod(int arg);

when we right-click on the function and select from the menu "Refactor->Implement Method", Eclipse automatically declare the function in the implementation file.
void BaseClass::myMethod(int arg)
{
}

Usually I write the implementation with a sophisticated [ctrl-c] [ctrl-v], but I am waiting for this refactoring from long time.

Extract Constant


This is a more sophisticated refactoring. If we write bad code and spread constant value on the code, like this:
void BaseClass::myMethod(int arg)
{
arg += 100;
}

void BaseClass::myMethod2(int arg)
{
arg += 100;
}

when we right-click on one occurrence of the value we want to declare as constant, select from the menu "Refactor->Extract constant", we are prompted to enter the constant name and to choose the visibilty, and finally we get:
namespace 
{
const int Step_ = 100;
}

...

void BaseClass::myMethod(int arg)
{
arg += Step_;
}

void BaseClass::myMethod2(int arg)
{
arg += Step_;
}

More convenient than search and replace.

Extract Function


This is the most complicated refactoring. We can use this refactoring when we have a piece of code in a function and we need to extract only this lines and create a new function. This is not simply move some lines, if this piece of code reference a variable declared is some other place this means we need an argument on the new function. Suppose we have this function:
void BaseClass::myMethod(int arg)
{
int b = arg + 10;

arg = b;
}

we want to extract the first line and create a new function. We select the line and from the menu we select "Refactor->Extract function". On the refactoring dialog we have to set the new function name, we can also see the arguments required by the new function. For my example the new function require the arg integer parameter. The refactored code is:
int BaseClass::addStep(int & arg)
{
int b = arg + 10;
return b;
}

void BaseClass::myMethod(int arg)
{
int b = addStep(arg);

arg = b;
}

I try this refactoring on different contexts and it always generate the correct function.

10 commenti:

  1. Complimenti per la vittoria al "Ganymede Around the World Contest" :-)

    Ottimo post.
    ciao
    Marco

    RispondiElimina
  2. Congratulations on winning the Ganymede Around the World Contest. I'm one of the developer of the refactorings and a now a CDT committer. This is a great post and probably the best documetation of the CDT refactorings available at the moment. Great job.

    RispondiElimina
  3. Truly a great post
    Thanks a lot

    RispondiElimina
  4. if I try to launch from the applications menu eclipse opened with user privileges and so it doesnt do software update and it gives error while closing it. If I open it with this command sudo ./eclipse everything goes smoothly.
    There must me something wrong with permissions. I did what all u write. everything seems ok 755 and root permissions but anyway it doesn't work with menu launch

    RispondiElimina
  5. With user privileges you can not update eclipse, that is correct. You need to run eclipse as root using sudo ./eclipse, you are ok.

    Before run eclipse as root is better to close any opened project. After update eclipse you can restart it as normal user.

    The problem when update Eclipse as root is that if you by mistake perform some operation on the workspace some file change ownership.
    Try to watch on the .eclipse directory on your home or on the .metadata directory on the workspace.

    RispondiElimina
  6. I found this site using [url=http://google.com]google.com[/url] And i want to thank you for your work. You have done really very good site. Great work, great site! Thank you!

    Sorry for offtopic

    RispondiElimina
  7. Who knows where to download XRumer 5.0 Palladium?
    Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!

    RispondiElimina
  8. Davidson garment is a quintessential Harley abercrombie Outlet davidson item, especially if you feature ones Harley decked abercrombie and fitch over. Featuring the whole distinctive line of leather abercrombie sale jackets, t-shirts, buckles, hats, belts, boots abercrombie & fitch and helmets, feeling of guilt reason this is abercrombie not to accessorize to max.A decent buy Harley enthusiast will abercrombie uk go in closet and grab a Harley t-shirt, leather jacket and boots. But, abercrombie london does your closet contain present accessory considering all abercrombie and Fitch Polo of? The Harley helmet. With out them your road abercrombie Polos trip could end in disaster.

    RispondiElimina
  9. Doing the same thing for thomas sabo diamonds is going to cost you thomas sabo sale an arm and a leg as the colored diamonds thomas sabo jewellery are hard to come by. thomas sabo charms The deposit and jewelry boxes you have, thomas sabo online as well as desk and cabinets, vehicle doors and windows, sabo jewellery home and store front doors can all get ruined. thomas sabo charms sale Using a skilled locksmith you'll cheap thomas sabo charms be able to have the assurance that you get the best work that will be done right and guaranteed.All to often, discount thomas sabo charms instead of finding an automotive locksmith, thomas sabo charms clearance Washington DC residents try to take matters in to their own hands.

    RispondiElimina
  10. Diese süße und fröhliche Kollektion thomas sabo charm umfasst Bands in den Formen der Diademe und Kronen mit thomas sabo anhänger Steinen, Burgen, Zauberstäbe, thomas sabo charms reduziert Glas Pantoffeln und Prinzessinnen selbst! thomas sabo charms günstig Und sie kommen in einer Vielzahl von noblen thomas sabo anhänger günstig und girly Farben: rosa, weiß, lila, thomas sabo anhänger billig blau und gold. Alle Mädchen wollen in einigen thomas sabo 2010 zu investieren und dann kann es losgehen dass Handelssystem und thomas sabo reduziert Sie erhalten alle Prinzessinnen euch sein! Und für Sie gibt es die thomas sabo shop Jungs Silly Bandz-Sea Creatures-Bereich.

    RispondiElimina