Friday, September 30, 2011

Suppress "unused parameter" warnings

Here's a way to suppress the annoying "unused parameter" warning given by the following code:
void aFunction(int unusedParameter)
{
    // Do something but ignore the 'unusedParameter'
}

I use this define:
#define CHECKED_UNUSED(x) (void)x

And then I surround unused parameter with it, right after the opening bracket of the function (so I can easy find and modify the parameter if I start using it):
#define CHECKED_UNUSED(x) (void)x

void aFunction(int unusedParameter)
{
    CHECKED_UNUSED(unusedParameter);
}


I looked at the generated assembly before and after and it didn't change:
                  aFunction(int):
00000000004007d4:   push %rbp
00000000004007d5:   mov %rsp,%rbp
00000000004007d8:   mov %edi,-0x4(%rbp)
15                }
00000000004007db:   pop %rbp
00000000004007dc:   retq
18                {


Disclaimer: use it only after you carefully checked that you really not need to use that parameter.
Unused parameters (and all the warnings in general) could really lead to a bug (or simple misunderstandings) in your code.

Sunday, September 11, 2011

Gnome3 e GnomeShell. I miei due centesimi.

Uso Gnome3 e la Shell da quando è uscito dalla fase di testing in Arch Linux. Effettivamente l'inizio è stato un pò ostico perchè molte cose sono cambiate, ma successivamente ho apprezzato il design tutto sommato lineare e pulito: sembra fatto bene e, soprattutto, pensato bene.

Ok, la status-bar è stata pensata male e realizzata peggio, ma tutto il resto se la cava piuttosto bene, tranne che per l'aspetto "configurazione".

Su quel versante Gnome3 mostra molto il fianco; in particolare è davvero troppo poco configurabile (sembra un prodotto Apple) e le extensions sono ancora troppo poco diffuse e, spesso, realizzate male.
Ma ciò che mi spaventa di più è che la configurazione del sistema sembra essere stata realizzata in modo così spartano e semplice di proposito. Se così fosse allora Gnome avrebbe perso un'occasione di quelle d'oro. Diciamo solo che hanno tempo di recuperare e spero sinceramente che lo facciano. Per loro.

Vogliamo parlare poi di stabilità? Stabilissimo e anche molto reattivo. Anche qua traspare l'impressione di buona realizzazione e buon design iniziale e, come bonus, i crash e i difetti sono lontani da un ambiente pulito e funzionante giusto un "ALT+F2 r".


In definitiva sono molto soddisfatto e propenso a credere che successivi rilasci portino ulteriori miglioramenti anche sotto questo aspetto.

Vorrei infine porre l'accento ancora una volta sulle extensions, stavolta con una nota molto positiva: sono realizzabili in Javascript... cosa mai avrei potuto desiderare di più (se non un'Aston Martin la mattina di Natale).

Friday, September 2, 2011

Bug after updating to ruby 1.9.2 on Arch Linux

If you ever encountered the following error in your ArchLinux box:
$ gem install <your_gem_name_here>
/usr/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:62:in `installed_spec_directories':
  undefined method `path' for Gem:Module (NoMethodError)
from /usr/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:52:in `from_installed_gems'
from /usr/lib/ruby/site_ruby/1.9.1/rubygems.rb:914:in `source_index'
from /usr/lib/ruby/site_ruby/1.9.1/rubygems/gem_path_searcher.rb:83:in `init_gemspecs'
from /usr/lib/ruby/site_ruby/1.9.1/rubygems/gem_path_searcher.rb:13:in `initialize'
from /usr/lib/ruby/site_ruby/1.9.1/rubygems.rb:873:in `new'
from /usr/lib/ruby/site_ruby/1.9.1/rubygems.rb:873:in `searcher'
from /usr/lib/ruby/site_ruby/1.9.1/rubygems.rb:495:in `find_files'
from /usr/lib/ruby/site_ruby/1.9.1/rubygems.rb:1034:in `load_plugins'
from /usr/lib/ruby/site_ruby/1.9.1/rubygems/gem_runner.rb:84:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from /usr/bin/gem:9:in `<main>'
You can use these commands to solve the issue:
$ sudo pacman -U /var/cache/pacman/pkg/ruby-1.9.1_p429-1-x86_64.pkg.tar.xz
[or equivalent 1.9.1 version]
$ sudo gem update --system
$ sudo pacman -S ruby

[to return to the new ruby (1.9.2 in my case)]