il codice sorgente, a sinistra e la resa grafica, a destra

Codice e resa graficaCode and graphical rendering

conviene conoscere il codice sorgente?

icona per espandere il menu interno

Chiunque usi il computer in modo consapevole sa che una cosa è il codice sorgente, altra cosa è la sua resa grafica. Il computer lavora essenzialmente con del codice sorgente, ossia con del testo, delle righe di testo, che il computer è in grado di interpretare

  • o come dei comandi da eseguire
  • o come dei dati da rendere graficamente.

1) casi in cui non serve conoscere il codice sorgente

Il codice sorgente che sta alla base del sistema operativo e degli applicativi di un computer è incomprensibile a un comune mortale, né occorre più di tanto preoccuparsene. Potremmo in effetti vivere benissimo, se non siamo degli informatici, senza capirne un fico secco.

Ma il codice sorgente che sta alla base di certi dati può invece, e anzi dovrebbe, interessare chi voglia fare un uso consapevole del computer (come pure di qualsiasi dispositivo digitale). Non di qualsiasi dato è opportuno familiarizzare col codice sorgente: certamente non di quello delle immagini, o dei files audio, o dei video. Si tratta di “geroglifici” assolutamente incomprensibili a un comune mortale, che si può benissimo lasciar manipolare dai programmi, dagli applicativi specifici destinati a tale funzione. Eccone un esempio. Le righe qui sotto un frammento di codice sorgente di un file immagine:

Anyone who uses a computer consciously knows that source code is one thing; its graphical rendering is quite another. The computer essentially works with source code, that is, with text, lines of text, which the computer is able to interpret

  • either as commands to be executed
  • or as data to be rendered graphically.

1) Cases where you don't need to know the source code.

The source code underlying a computer's operating system and applications is incomprehensible to an ordinary mortal, nor do we need to worry about it much. We could in fact live just fine, if we are not computer scientists, without understanding a fig about it.

But the source code behind certain data can instead, and indeed should, be of interest to those who want to make informed use of computers (as well as any digital device). Not of any data is it appropriate to familiarize oneself with the source code: certainly not of that of images, or audio files, or videos. These are "hieroglyphics" absolutely incomprehensible to an ordinary mortal, which one can very well allow to be manipulated by programs, by specific applications intended for that function. Here is an example. The lines below a fragment of source code of an image file:

pA±!®6%D0ÿŠDÅ#J¬>6†‹«ï;Æ?FÄóìh²Çߌ•l)9ŒBH’¢àƒbTC\iæ÷÷hx5žìŽÅ¶dàÖÁÔ¹ä\vq‡Ž!suKdãðtõata¨g¢i~¡'}‰P߁¡zç·ÔÜmÂ`e{@•lâE°š—i®v+§½½w d6ê4ú'sédý:Z!X>“1ùёE:xŽi ™å[™]óAM&p(VÍa@€©%ÀËÆ<»’ՇŽ‡ÙáîjY2ñ2ûôÞ÷â›,üQr Cºžók0æˆéËiý…ø} Üág¡gGtê^‘%§å;oŽ†=|,¤WS”û©Äi¼wr€

2) casi in cui serve eccezionalmente conoscere il codice sorgenteCases where you exceptionally need to know the source code

Diverso è il caso dei files di carattere più propriamente testuale: fogli calcolo, database e, soprattutto, documenti. I fogli di calcolo e i database sono normalmente manipolati e salvati in formati graficamente avanzati (come xls, o mdb, o odb o simili); tuttavia essi nel loro scheletro contenutistico possono essere “ridotti” a puro testo, senza formattazione grafica. E in questo caso, come csv (questa è l'estensione che caratterizza dei database o dei fogli di calcoli nel loro puro scheletro testuale, scarnificati di ogni venustà grafica) essi possono essere visualizzati e manipolati. Il che talora può salvare delle situazioni altrimenti senza via d'uscita. Ecco un esempio di codice sorgente di un file csv, ricavato dalla esportazione di una tabella di database:

Different is the case with files of a more properly textual nature: spreadsheets, databases and, above all, documents. Spreadsheets and databases are normally manipulated and saved in graphically advanced formats (such as xls, or mdb, or odb or the like); however, they in their content skeleton can be "reduced" to pure text, without graphical formatting. And in this case, as csv (this is the extension that characterizes databases or spreadsheets in their pure textual skeleton, stripped of all graphical venusty) they can be viewed and manipulated. Which can sometimes save otherwise dead-end situations. Here is an example of source code for a csv file, derived from the export of a database table (Italian text):

"rivista","sigla","luogo","editore"
"Angelicum","Ang","Roma",NULL
"Annales de philosophie chrétienne","APC",NULL,NULL
"Bullettin de Littérature écclesiastique","BLE",NULL,NULL
"Concilium","Conc","Brescia",NULL
"Ephemerides theologicae lovanienses","ETL","Louvain",NULL
"Gregorianum","Gre","Roma",NULL

3) casi in cui il codice sorgente può servire anche nell'ordinario utilizzoCases in which source code may also serve in ordinary use.

Tuttavia è con i documenti (di testo, come quelli con estensione .docx) che la familiarità con codice sorgente diventa importante non solo in casi eccezionali, come per fogli di calcolo e database, ma tendenzialmente nell'uso quotidiano e ordinario.

Un documento di testo, manipolato con un applicativo di videoscrittura, può essere salvato in un formato graficamente avanzato e ricco, e in quel caso agire sul suo codice sorgente risulta piuttosto arduo. Ecco un esempio di alcune righe di codice sorgente di un file “word” (odt):

However, it is with documents (text documents, such as those with the .docx extension) that familiarity with source code becomes important not only in exceptional cases, such as for spreadsheets and databases, but tends to be in ordinary, everyday use.

A text document, manipulated with a word processing application, may be saved in a graphically advanced and rich format, and in that case acting on its source code is rather arduous. Here is an example of a few lines of source code for a "word" (odt) file:

<?xml version="1.0" encoding="UTF-8"?><office:body><office:text><office:forms form:automatic-focus="false" form:apply-design-mode="false"/><text:sequence-decls><text:sequence-decl text:display-outline-level="0" text:name="Illustration"/><text:sequence-decl text:display-outline-level="0" text:name="Table"/><text:sequence-decl text:display-outline-level="0" text:name="Text"/><text:sequence-decl text:display-outline-level="0" text:name="Drawing"/><text:sequence-decl text:display-outline-level="0" text:name="Figure"/></text:sequence-decls><text:h text:style-name="Heading_20_1" text:outline-level="1"><text:title>Tesi di filosofia politica</text:title></text:h><text:list text:style-name="L1"><text:list-item><text:p text:style-name="P1">La democrazia è il sistema costituzional<text:span text:style-name="T8">e</text:span> “meno imperfetto”.</text:p></text:list-item></text:list>

Come si vede non è un file binario, ma un file testuale (sia pure compresso con altri files testuali “zippati” in un unico file), la cui manipolazione però richiederebbe una attenzione e un dispendio di energia assolutamente sproporzionati, e che vengono risparmiati da una sua manipolazione grafica. Tramite un programma come OpenOffice.

Tuttavia ci sono casi in cui (per un documento di testo) un formato testuale avanzato è indispensabile, e altri in cui non lo è. Vediamo

Il formato avanzato è insostituibile se

  • devo usare dei campi, ad esempio per connettere il documento con un database, o con un altro documento, in modo che la modifica fatta nel documento collegato o nel database collegato, sia visibile nel documento su cui sto lavorando. Questo è l'elemento più insostituibile.

è solo parzialmente sostituibile se

  • devo inserire note a piè di pagina automaticamente numerate 1,
  • devo usare delle tabelle, la cui resa grafica potrebbe risultare meno efficace,
  • aggiungere dei metadata
  • devo condividere il documento con un altro (collega, o editore, ad esempio), che non saprebbe come manipolare/visualizzare il mio documento. Ma in questo caso si può sempre esportare dal formato più semplice (poi vediamo quale) a quello avanzato

Vediamo il caso di una tabella, resa con un programma di manipolazione del codice markdown:

As can be seen, it is not a binary file, but a text file (albeit compressed with other text files "zipped" into a single file), the manipulation of which, however, would require an absolutely disproportionate amount of attention and energy, and which are saved by its graphical manipulation. Through a program such as OpenOffice.

However, there are cases where (for a text document) an advanced text format is indispensable, and others where it is not. See

The advanced format is irreplaceable if

  • I need to use fields, for example to connect the document with a database, or with another document, so that the change made in the linked document or linked database, is visible in the document I am working on. This is the most irreplaceable element.

Is only partially replaceable if

  • I have to insert footnotes automatically numbered 1
  • ,
  • I have to use tables, the graphical rendering of which may be less effective,
  • add metadata
  • I have to share the document with someone else (colleague, or editor, for example), who would not know how to manipulate/view my document. But in this case you can always export from the simplest format (then let's see which one) to the advanced format

Let's look at the case of a table, rendered with a markdown code manipulation program:

bluredyellow
157245
281237
964627

Non è male, ma mancano, o meglio sono poco intuitive alcune funzioni di manipolazione avanzata che potrei avere con Word o con OpenOffice.

Non è invece necessario avere un formato avanzato, ma può bastare un formato semplice (vicino al codice sorgente, e dal codice sorgente continuamente “a portata di mano”) come il markdown, per

  • avere un testo formattato (con titoli di vario livello, o grassetto/corsivo/sottolineato, o blocchi di citazione)

Vedremo in una pagina successiva il formato più indicato per lavorare con il codice sorgente su documenti.

It is not bad, but it lacks, or rather is unintuitive to some advanced manipulation functions that I could have with Word or OpenOffice.

On the other hand, it is not necessary to have an advanced format, but a simple format (close to the source code, and from the source code continuously "at hand") such as markdown may suffice, to

  • have a formatted text (with headings of various levels, or bold/cursive/underlined, or citation blocks)

We will see on a later page the most suitable format for working with source code on documents.

4) casi in cui occorre sapere usare il codice sorgenteCases where you need to know how to use source code.

Sapere usare il codice sorgente è necessario in almeno due campi

  • per gestire siti web, e in genere dati in formato html
  • per programmare degli script da usare sul computer

siti web e dati in html

Se uno vuole gestire in modo responsabile un sito web, non dovrebbe affidarsi (solo) a CMS, come WordPress: occorre sapere che cosa si sta facendo. E solo lavorando sul codice sorgente lo si può.

Quindi è bene conoscere come funziona il codice sorgente: l'html, i fogli di stile (css), i javascript, il linguaggio php e simili.

Oltretutto l'html sta anche alla base del formato epub: chi sa usare il codice sorgente per costruire pagine web, sa anche come modificare un file epub, che poi potrà leggere sull'e-reader.

Non c'è da spaventarsi: ecco l'aspetto di una porzione di codice sorgente di questa pagina:

Knowing how to use source code is necessary in at least two areas

  • to manage Web sites, and generally data in html format
  • to program scripts for use on the computer

websites and data in html

If one wants to responsibly manage a website, one should not rely (only) on CMSs, such as WordPress: one needs to know what one is doing. And only by working on the source code can one do that.

So it is good to know how the source code works: the html, style sheets (css), javascript, php language and the like.

Moreover, html is also the basis of the epub format: those who know how to use source code to build web pages also know how to edit an epub file, which they can then read on the e-reader.

No need to panic: here is what a portion of the source code for this page looks like

<p>Sapere usare il codice sorgente è necessario in almeno due campi</p> <ul> <li>per gestire <b>siti web</b>, e in genere dati in <b>formato html</b></li> <li>per programmare degli <b>script</b> da usare sul computer</li> </ul> <h3>siti web e dati in html</h3> <p>Se uno vuole gestire in modo responsabile un sito web, non dovrebbe affidarsi (solo) a CMS, come WordPress: occorre sapere che cosa si sta facendo. E solo lavorando sul codice sorgente lo si può.</p>

Come vedete: niente di drammatico!

Certo, non è tutto così facile. Ma non è detto che uno debba fare tutto fin da subito. Si può, se non si è informatici di professione, imparare col tempo. A seconda delle necessità che via via si presentano.

As you can see: nothing dramatic!

Of course, it is not all that easy. But one does not necessarily have to do everything right from the start. One can, if one is not a computer scientist by profession, learn over time. Depending on the needs that gradually arise.

Scripts

Soprattutto in Linux, programmare degli scripts è un modo per personalizzare il computer e fargli fare esattamente quello che si desidera. Tipico caso: la sincronizzazione tra diversi dispositivi.

Certo, esistono anche degli applicativi tuttofare, ma, a parte il fatto di poter essere a pagamento, non è detto che facciano esattamente ciò di cui voi avete bisogno.

Conoscere il codice sorgente vi permette di crearvi dei vostri scripts, per seguire automaticamente operazioni di routine.

Especially in Linux, programming scripts is a way to customize your computer and make it do exactly what you want it to do. Typical case: synchronization between different devices.

Of course, there are also all-purpose applications, but aside from the fact that they can be for a fee, they may not necessarily do exactly what you need.

Knowing the source code allows you to create your own scripts, to automatically follow routine operations.

come si visualizza il codice sorgenteHow to view source code

Il modo più semplice è aprire un file con un editor di testo (nel caso di Linux: Kwrite o Kate, in Windows: qualcosa come notepad), oppure, nel caso di una pagina web, tasto destro del mouse -> visualizza sorgente pagina (o qualcosa di simile). Quest'ultima cosa la potete fare anche voi, ora.

The easiest way is to open a file with a text editor (with Linux: Kwrite or Kate, in Windows: something like notepad), or, in the case of a web page, right-click -> view page source (or something similar). You can do the latter now, too.

concludendoto sum up

Nell'esperienza ordinaria comunque i due usi più frequenti in cui potreste usare con profitto del codice sorgente sono la videoscrittura e la gestione del codice html (per siti web o manipolazione di epubs).

In ordinary experience however, the two most frequent uses in which you might profitably use source code are word processing and html code management (for Web sites or epubs manipulation).

Vediamo in una pagina successiva il primo caso, la videoscrittura e il codice markdownLet's look at the first case, word processing and markdown code, on a specific page.

1 tuttavia esistono programma di testo semplice che sanno fare anche questo. Zettlr, con cui sto scrivendo, lo fa however, there are plain text programs that can do this as well. Zettlr, which I am writing with, does.