Skip to content

Commit

Permalink
tradotto capitolo 12
Browse files Browse the repository at this point in the history
  • Loading branch information
giatorta committed Mar 2, 2012
1 parent f7d93dc commit 0648d76
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 102 deletions.
14 changes: 5 additions & 9 deletions translations/italian/chapter_12.pod 100644 → 100755
Expand Up @@ -2,14 +2,10 @@

=head0 Cosa Manca

Perl5 non è perfetto, almeno nei suoi comportamenti di default. Alcune
opzioni sono disponibili nel linguaggio, molte altre si possono trovare su
CPAN. I programmatori Perl esperti hanno ciascuno la propria idea di come
dovrebbe comportarsi un Perl 5 ideale e spesso utilizzano le proprie
configurazioni in maniera molto efficace.

I neofiti posono non sapere come essere aiutati da Perl a scrivere meglio
i programmi. C'è una manciata di moduli base che vi renderanno molto più
produttivi.
Perl5 non è perfetto, ma è malleabile--in parte perchè non esiste un'unica
configurazione ideale per ogni programmatore e ogni obiettivo. Alcuni comportamenti
utili sono disponibili nelle librerie distribuite con Perl. Altri sono disponibili su CPAN.
La vostra efficacia come programmatore Perl dipende da quanto sapete avvantaggiarvi di queste
aggiunte.

L<missing_defaults>
167 changes: 74 additions & 93 deletions translations/italian/missing_defaults.pod 100644 → 100755
@@ -1,117 +1,99 @@
=head1 Missing Defaults
=head1 Default Mancanti

Z<missing_defaults>

Perl 5's design process in 1993 and 1994 tried to anticipate new directions for
the language, but it's impossible to predict the future. Perl 5 added many
great new features, but it also kept compatibility with the previous seven
years of Perl 1 through Perl 4. Sixteen years later, the best way to write
clean, maintainable, powerful, and succinct Perl 5 code is very different from
Perl 5.000. The default behaviors sometimes get in the way; fortunately,
better behaviors are available.
La progettazione di Perl 5 ha tentato di anticipare le nuove direzioni del linguaggio,
ma era altrettanto impossibile predire il futuro nel 1994 come lo è nel 2011. Perl 5
ha espanso il linguaggio, ma è rimasto compatibile con Perl 1 del 1987.

X<C<Task::Kensho>>
Il miglior codice Perl 5 scritto nel 2011 è molto diverso dal miglior codice Perl 5 scritto nel
1994 e dal miglior codice Perl 1 scritto nel 1987.

The CPAN (L<cpan>) contains many modules and pragmas designed to make your work
simpler, more correct, and more enjoyableN<See C<Task::Kensho> to start.>. As
you improve as a Perl programmer, you will have many opportunities to use (and
even to create) such code in the right circumstances. For now, use these
pragmas and modules regularly in your own code.
X<CPAN; C<Task::Kensho>>

=head2 The strict Pragma
Sebbene Perl 5 sia distribuito con una ricca libreria, essa non è onnicomprensiva.
Molti dei migliori moduli Perl 5 sono distribuiti su CPAN (L<cpan>) anzichè insieme
a Perl. La meta-distribuzione C<Task::Kensho> include svariate altre
distribuzioni che rappresentano il meglio che CPAN abbia da offrire. Dateci un'occhiata
come prima cosa ogni volta che dovete risolvere un problema.

X<C<strict>>
X<pragmas; C<strict>>

The C<strict> pragma (L<pragmas>) allows you to forbid (or re-enable) various
language constructs which offer power but also the potential for accidental
abuse.

C<strict> provides three features: forbidding symbolic references, requiring
variable declarations, and forbidding the use of undeclared barewords
(L<barewords>). While the occasional use of symbolic references is necessary
to manipulate symbol tables (barring the use of helper modules, such as
C<Moose>), the use of a variable as a variable name offers the possibility of
subtle errors of action at a distance--or, worse, the possibility of
poorly-validated user input manipulating internal-only data for malicious
purposes.

Requiring variable declarations helps to prevent typos in variable names and
encourages proper scoping of lexical variables. It's much easier to see the
intended scope of a lexical variable if all variables have C<my> or C<our>
declarations in the appropriate scope.

C<strict> has a lexical effect, based on the compile-time scope of its use.
You may disable certain features of C<strict> (within the smallest possible
scope, of course) with C<no strict>. See C<perldoc strict> for more details.

=head2 The warnings Pragma
Ciò detto, alcune direttive e moduli distribuiti con Perl sono indispensabili ad ogni
programmatore Perl serio.

The C<warnings> pragma (L<handling_warnings>) controls the reporting of various
classes of warnings in Perl 5, such as attempting to stringify the C<undef>
value or using the wrong type of operator on values. It also warns about the
use of deprecated features.
=head2 La direttiva strict

The most useful warnings explain that Perl had trouble understanding what you
meant and had to guess at the proper interpretation. Even though Perl often
guesses correctly, disambiguation on your part will ensure that your programs
run correctly.
X<C<strict>>
X<direttive; C<strict>>

The C<warnings> pragma has a lexical effect on the compile-time scope of its
use. You may disable some or all warnings with C<no warnings> (within the
smallest possible scope, of course). See C<perldoc perllexwarn> and C<perldoc
warnings> for more details.
La direttiva C<strict> (L<pragmas>) vi permette di disattivare (e ri-attivare) vari
costrutti potenti del linguaggio che si prestano ad abusi involontari.

=begin sidebar
C<strict> proibisce i riferimenti simbolici, richiede che le variabili siano dichiarate
(L<lexical_scope>) e proibisce l'uso di bareword non dichiarate
(L<barewords>). Anche se l'uso occasionale dei riferimenti simbolici può essere necessario per
manipolare le tabelle dei simboli (L<import>), l'uso di una variabile come nome di variabile
offre il fianco a errori sottili di azione a distanza--o, peggio ancora, alla
possibilità di manipolazione di strutture dati interne per fini illeciti
da parte di input utente scarsamente validato.

Combine C<use warnings> with C<use diagnostics>, and Perl 5 will display
expanded diagnostic messages for each warning present in your programs. These
expanded diagnostics come from C<perldoc perldiag>. This behavior is useful
when learning Perl, but it's less useful in code deployed to production,
because it can produce verbose error output.
Richiedere che le variabili siano dichiarate aiuta a rilevare erroti di battitura nei nomi delle variabili e
incoraggia la definizione di variabili lessicali negli con appropriati. È molto più facile capire qual è
lo scope che si intende associare a una variabile lessicale se tutte le variabili hanno dichiarazioni C<my> e C<our>
nello scope appropriato.

=end sidebar
C<strict> ha un effetto lessicale basato sullo scope durante la compilazione del suo uso
(L<import>) e della sua disattivazione (con C<no>). Vedete C<perldoc strict> per maggiori dettagli.

=head2 IO::Handle
=head2 La Direttiva warnings

Perl 5.6.0 added lexical filehandles. Previously, filehandles were all package
globals. This was occasionally messy and often confusing. Now that you can
write:
La direttiva C<warnings> (L<handling_warnings>) controlla la generazione delle varie classi di
warning in Perl 5, come il tentativo di convertire in stringa il valore C<undef>
o l'uso del tipo sbagliato di operatore su certi valori. Genera anche warning relativi
all'uso di funzionalità deprecate.

=begin programlisting
I warning più utili sono quelli che spiegano che Perl ha incontrato difficoltà a interpretare le vostre
intenzioni e ha dovuto tentare di indovinare l'interpretazione giusta. Sebbene spesso Perl ci
azzecchi, una disambiguazione da parte vostra garantisce che i vostri programmi
funzionino correttamente.

open my $fh, '>', $file or die "Can't write to '$file': $!\n";
La direttiva C<warnings> ha un effetto lessicale sullo scope durante la compilazione del suo uso o
disattivazione (con C<no>). Vedete C<perldoc perllexwarn> e C<perldoc
warnings> per maggiori dettagli.

=end programlisting
=begin tip Chiedere altro Aiuto

... the lexical filehandle in C<$fh> is easier to use. The implementation of
lexical filehandles creates objects; C<$fh> is an instance of C<IO::Handle>.
Unfortunately, even though C<$fh> is an object, you can't call methods on it
because nothing has loaded the C<IO::Handle> class.
Combinate C<use warnings> con C<use diagnostics> per ricevere messaggi diagnostici più estesi
per ogni warning presente nei vostri programmi. Questa diagnostica estesa
è documentata in C<perldoc perldiag>. Questo comportamento è particolarmente utile quando imparate Perl.
Disattivatelo prima di distribuire il vostro programma, perchè produce un output verboso
che potrebbe riempire i vostri file di log ed esporre troppe informazioni agli utenti.

This is occasionally painful when you want to flush the buffer of the
associated filehandle, for example. It could be as easy as:
=end tip

=begin programlisting
=head2 C<IO::File> and C<IO::Handle>

$fh->flush();
X<C<IO::File>>
X<C<IO::Handle>>

=end programlisting
Prima di Perl 5.14 i filehandle lessicali erano oggetti della classe C<IO::Handle>,
ma dovevate caricare esplicitamente C<IO::Handle> prima di poter chiamare dei metodi
su di essi. A partire da Perl 5.14, i filehandle lessicali sono istanze del modulo C<IO::File> che
Perl carica per voi.

... but only if your program somewhere contains C<use IO::Handle>. The
solution is to add this line to your programs so that lexical filehandles--the
objects as they are--behave as objects should behave.
Aggiungete C<IO::Handle> al codice da eseguire in Perl 5.12 o versioni precedenti se volete chiamare dei metodi
sui filehandle lessicali.

=head2 The autodie Pragma
=head2 La direttiva autodie

Z<autodie>
X<C<autodie> pragma>
X<pragmas; C<autodie>>
X<direttiva C<autodie>>
X<direttive; C<autodie>>

Perl 5's default error checking is parsimonious. If you're not careful to
check the return value of every C<open()> call, for example, you could try to
read from a closed filehandle--or worse, lose data as you try to write to one.
The C<autodie> pragma changes the default behavior. If you write:
Perl 5 lascia alla vostra responsabilità gestire (o ignorare) gli errori. Per esempio, se non fate attenzione
a controllare il valore di ritorno di ogni chiamata a C<open()> potreste
tentare di leggere da un filehandle chiuso--o, peggio ancora, perdere dati che tentate di
scriverci. La direttiva C<autodie> modifica questo comportamento di default. Se
scrivete:

=begin programlisting

Expand All @@ -121,11 +103,10 @@ The C<autodie> pragma changes the default behavior. If you write:

=end programlisting

... an unsuccessful C<open()> call will throw an exception via Perl 5's normal
exception mechanism. Given that the most appropriate approach to a failed
system call is throwing an exception, this pragma can remove a lot of
boilerplate code and allow you the peace of mind of knowing that you haven't
forgotten to check a return value.
... un fallimento della chiamata a C<open()> solleverà un'eccezione. Dato che la reazione più
appropriata al fallimento di una chiamata di sistema è quella di sollevare un'eccezione, questa
direttiva può rimuovere molto codice ripetitivo dal vostro programma e garantirvi la tranquillità
di sapere che non non avete dimenticato di controllare un valore di ritorno.

This pragma entered the Perl 5 core as of Perl 5.10.1. See C<perldoc autodie>
for more information.
Questa direttiva viene distribuita con Perl 5 a partire dalla versione 5.10.1. Vedete C<perldoc autodie>
per maggiori informazioni.

0 comments on commit 0648d76

Please sign in to comment.