English (UK)

Come molti prima di me, anch'io inizierò a pubblicare alcuni snippets che ho conservato durante la mia attività di sviluppatore dotnet. Spero possano esservi di aiuto nella vostra attività di scrittura del codice.

Like many before me, I begin to publish some snippets that I kept in my dotnet development activities. I hope its can help you in your writing code activities.

Recentemente ho fatto un'analisi sui 3d game engine, i motori di gestione di giochi 3d. Come sempre ho posto l'attenzione sulle soluzioni open source e free. Questa volta ho voluto vedere cosa esiste nel mondo dotNET. Un motore open source molto interessante è irrLicht. In realtà è scritto in C++, ma esiste un wrapper per dotNET abbastanza completo. irrLicht è corredato da una serie di software satellite molto utili, quali irrEdit, un editor di mappe e scene 3d davvero completo. Nel sito ufficiale di irrLicht, oltre ad una vasta biblioteca di tutorial sull'uso, ci sono i link a vari prodotti basati sul motore. Vale la pena dare un'occhiata. Inoltre esiste un sito dedicato a irrlicht in italiano all'indirizzo http://irrlichtitalia.altervista.org Restando in Microsoft, XNA è, se vogliamo, lo stato dell'arte. bisogna però scrivere molto a mano per realizzare un'applicazione finita. Anche qui l'open source viene in soccorso. RealmForge è un game engine veramente potente basato su XNA e CSharp che consente di sviluppare giochi un po' come irrlicht. Purtroppo RealmForge non viene più sviluppato. E' stato acquisito ed è diventato un prodotto commerciale: Visual3D.NET. La soluzione è davvero notevole. In maniera molto semplice si ha la possibilità di imbastire tutto lo scheletro del gioco, riservando alla scrittura in Visual Studio o MonoDevelop solo le logiche del gioco. Visual3D.NET si può scaricare in versione Beta gratuitamente oppure nella versione completa a pagamento. Purtroppo la documentazione relativa a Visual3D.NET è scarsa, comunque qualcosa nel sito c'è. Da provare sicuramente. Recently I did an analysis on 3d game engine, the engine to management 3d games. As always I put attention on open source and free solutions. This time I wanted to see what exists in the dotNET world. An open source engine very interesting is irrLicht. It's written in C++, but there is a complete wrapper for dotNET. irrLicht is accompanied by a series of satellite software very useful, such irrEdit, an editor maps and scenes 3d really complete. In the  irrLicht official site, as well as a wide tutorial library, there are links to various products based on the engine. It should worth taking a look. There is also a site dedicated to Italian http://irrlichtitalia.altervista.org Remaining in Microsoft, XNA is, if you like, the state of the art. But we need to write a lot of hand part. Here open source is to the rescue. RealmForge is a really powerful game engine based on XNA and CSharp that makes it possible to develop games a little 'how irrlicht. Unfortunately RealmForge is no longer being developed. It 'been acquired and has become a commercial product: Visual3D.NET. The solution is truly remarkable. In a very simple one has the possibility of baste the whole skeleton of the game, reserving to writing in Visual Studio or MonoDevelop only the logic of the game. Visual3D.NET can download for free Beta version or full payment. Unfortunately, the documentation relating to Visual3D.NET is low, something the site there is.

Se abbiamo appena installato OpenOffice sul nostro computer e siamo degli utenti smaliziati potrebbe venirci subito la voglia di creare delle macro. Il primo impatto, soprattutto se veniamo dal mondo Microsoft è tragico. OpenOffice non supporta VBA e quindi non siamo in grado di scrivere macro come fatto fino ad oggi.

Questo a dire il vero risponde solo in parte a verità, perché Sun e Novell stanno lavorando al supporto a VBA per OpenOffice. Finora esistevano un plug-in di Novell per gestire le macro VBA di Excel anche in Calc e un tool di Sun per importare le macro di Ms Office in OpenOffice. Il primo passo di questa nuova iniziativa sarà quello di convertire il codice Java del MacroMigrationWizard di Sun in codice C++ (utilizzato da Novell e OpenOffice), seguito dal raffinamento del codice già esistente; ovviamente l’obiettivo finale è quello di includere i plugin nelle future release di OpenOffice.

In ogni caso a tutt'oggi VBA non gira su OpenOffice. Come possiamo fare allora?

Esistono già parecchie risorse in rete a riguardo.

Metto qui un paio di link utili.

Un ottimo esempio completo spiegato dalla A alla Z anche con le immagini lo potete trovare qui: http://www.comunecampagnano.it/gnu/biblioteca/index.htm Vale la pena dare un'occhiata.

Qualche altro esempio di codice sorgente di macro complessa si trova su questo libretto da 190 Kb in formato PDF http://www.pitonyak.org/AndrewFontMacro.pdf

La rete poi è piena zeppa di risorse per l'utilizzo di particolari comandi macro. Una veloce ricerca su google.com darà senza dubbio ottimi risultati!

Tratto da programmazione.it scritto da Antonino Salvatore Cutrì

OpenTK è una libreria di sviluppo per la piattaforma Microsoft .NET e la sua controparte open source Mono, che semplifica la realizzazione di giochi con grafica 3D mettendo a disposizione dei wrapper ad alto e a basso livello attorno alle API OpenGL e OpenAL.

Oltre a rappresentare uno strato software che rende meno complicato lo sviluppo di applicazioni 3D, la libreria contiene altre interessanti funzionalità come: la gestione semplificata dei contesti OpenGL attraverso un sistema di finestre modulare compatibile con le piattaforme Linux e Windows (la versione nativa per Mac OS X è pianificata); l’iIntegrazione con le System.Window.Forms per la realizzazione di interfacce utenti potenti all'interno delle applicazioni OpenGL; un sistema di build semplificato e un timer ad alte prestazioni.

La OpenTK per funzionare richiede la versione 2.0 di .NET, oppure la release 1.2 di Mono ed è rilasciata sotto la licenza open source MIT, che ne permette l'uso per la realizzazione di prodotti commerciali e non. I linguaggi supportati sono C# e VB.NET; per usarla è sufficiente avere il compilatore .NET e un normale editor di testo, anche se ovviamente è consigliato l'uso di IDE completi come Visual Studio o le alternative open source SharpDevelop oppure MonoDevelop.

Tratto da programmazione.it scritto da Antonino Salvatore Cutrì 

Scott Guthrie, General Manager del .NET Framework presso la Microsoft Developer Division, ha annunciato che dopo aver analizzato i feedback ricevuti sia dai clienti che dalla comunità di sviluppatori, l’azienda ha deciso di rilasciare il codice sorgente di riferimento del suo .Net Framework sotto la Microsoft Reference License.

Essa può essere considerata come una specie di licenza open source a "sola lettura", infatti il codice coperto da questa licenza può solo essere visionato, ma ne è impedita qualunque modifica o ridistribuzione. Ad ogni modo con questa mossa, che fa parte degli sforzi di Microsoft mirati a fornire la massima trasparenza sulle sue tecnologie, gli sviluppatori avranno la possibilità non solo di conoscere in maniera più approfondita la piattaforma .NET, potendone studiare finalmente la composizione interna, ma grazie ad una funzionalità integrata nel futuro Visual Studio 2008, sarà possibile anche effettuare il debugging delle applicazioni passando in maniera trasparente dal proprio sorgente a quello del .NET Framework per vedere esattamente cosa succede e come si comportano le API di Microsoft.

Scott Guthrie ha inoltre aggiunto che il piano iniziale di Microsoft prevede il rilascio del codice sorgente delle seguenti tecnologie completamente commentato: NET Base Class Library (System, System.IO, System.Collections, System.Configuration, System.Threading, System.Net, ecc.);

  • ADO.NET (System.Data);
  • ASP.NET (System.Web);
  • Windows Forms (System.Windows.Forms);
  • Windows Presentation Foundation (System.Windows).

A questi seguiranno altri package più avanti nel corso del prossimo anno. L'accesso al sorgente del .NET Framework inoltre servirà a rassicurare gli sviluppatori, che si sentiranno sicuramente più garantiti avendo la possibilità di visionare il codice delle tecnologie che utilizzano, senza contare che questa mossa del colosso di Redmond ha anche una valenza educativa visto che permette non solo di vedere come è stato scritto il codice del frame work, ma anche di imparare le tecniche di programmazione usate all'interno di Microsoft ed impiegarle nei propri progetti. Il rilascio del codice sorgente con la possibilità di visionarlo o scaricarlo sarà permesso più avanti durante il corso dell'anno, quando verranno rese disponibili le release definitive del .NET Framework 3.5 e di Visual Studio 2008.

Tratto da programmazione.it scritto da Davide Panceri

John O'Conner mostra in un articolo sul sito ufficiale di Sun Microsystems come usare le caratteristiche di Java SE 6 per la creazione di applicazioni estensibili, in grado cioé di aggiornarsi con nuove funzionalità senza bisogno di modificare alla radice l'applicazione originaria, ad esempio riscrivendo e ricompilando il codice sorgente.

In effetti, se si aggiungono nuove librerie ad un programma Java è possibile utilizzarle in modo relativamente semplice, accodando alla variabile classpath il percorso di installazione; Java 6 ha introdotto l'API ServiceLoader, che permette di definire un'interfaccia service provider, che viene successivamente implementata in file aggiunti all'applicazione in seguito.

Naturalmente i dettagli richiedono una lettura attenta dell'articolo, che presenta due esempi: il primo è un editor di testo a cui si può aggiungere poi un dizionario o un correttore ortografico nuovo, creato da altri sviluppatori o dagli utenti stessi del programma; l'altro esempio, molto noto, è l'IDE NetBeans, al quale si possono aggiungere svariati moduli a seconda del bisogno.

A quanto sembra, questo contributo di O'Conner potrebbe essere l'ultimo da dipendente Sun, stando almeno al post di SDN Program News del 27 settembre, che parla di tagli dovuti a riduzione dei costi per motivi di bilancio e altre amenità del genere.

Questo racconto tratto da Roumen è troppo bello per non riportarlo.

How to kill a dragon with various programming languages

This funny text comes from Ibon from the dream team who got it from a Spanish blog. There's a beautiful princess, prisoner in the highest tower of a castle, guarded by a mighty dragon, and a fearless knight must rescue her… This is how each language would manage to rescue the princess from the hands of the dragon

  • Java - Gets there, finds the dragon, develops a framework for dragon anihilation with multiple layers, writes several articles about the framework… But doesn't kill the dragon.
  • .NET - Gets there, sees the idea of the Java developer and copies it. Tries to kill the dragon, but the monster eats him.
  • C - Arrives, looks down at the dragon, pulls out his sword, beheads the dragon, finds the princess… And ignores her to see the last checkins of linux kernel cvs.
  • C++ - Creates a basic needle, and gathers funcionality until he has a complex sword that he can barely understand… He kills the dragon, but gets stuck crossing the bridge because of memory leaks.
  • COBOL - Arrives, sees the dragon and thinks that he is too old to kill a monster that big and rescuing the princess, so he leaves.
  • Pascal - He prepares for 10 years to create a dragon anihilation system… When the moment comes, he discovers the program can only take lizards as an entry.
  • VB - Builds a dragon destruction weapon based on several components, jumps to the back of the dragon and in the most critical time he discovers that the sword works only on rainy nights…
  • PL/SQL - Gets data from other dragon slayers, creates tables with n ternary complexity relations, tridimensional data, OLAP, takes 15 years to process the information… And by then, the princess became a lesbian.
  • Ruby - Arrives with massive fame, saying he is the best at anything and when he faces the dragon, he shows a lame motion picture of himself killing a dragon… The dragon eats him out of boredom.
  • Smalltalk - Arrives, analyzes the dragon and princess, turns around and leaves, they are way too inferior.
  • shell - Creates a very powerful dragon slaying weapon… But in the moment of truth, he can't remember how to use it.
  • shell(2)- The guy approaches the dragon with a two line script that kills, cuts, disembowels, impales, chops to pieces and packs the beast, but when he runs it the script grows, it fattens, irritates and puts alcohol in the fire of the dragon…
  • Assembler - He thinks he's doing the right and most efficient things… But he writes an A instead of a D and kills the princess to end up f***ing the dragon.
  • Fortran - Arrives and develops a 45-thousand-code-line-solution, kills the dragon, meets the princess… But she calls him a weakling and runs after the Java programmer who was elegant, and also rich.
  • FOX PRO - Develops a dragon killing system. It's gorgeous and works on the outside, but it's really patched inside, so when he runs the dragon anihilator, he realizes he forgot to index the DBFs.
  • PROCESS ANALYST - Approaches the dragon with two tons of documentation, develops the unified dragon-killing process, he develops a DFD to free the princess and marry her, convinces the dragon that it's the best for him and it won't hurt. When he executes the process, he estimates the effort and the damage he will cause with a plan signed by the Pope, Buddha and Michael Jackson. Then he buys a couple of nukes, 45 cannons, an aircraft carrier and hires 300 heavily armed men… When all he needed was the sword he was holding in his hand in the beginning…
  • CLIPPER: Sets up a routine that loads a codeblock array to insult the dragon, serenade the princess, load the sword in memory, beat the crap out of the dragon, clean the mess, prepare a raspberry milkshake for the princess, make love to her, take a bath, start the car, put it some gas and come back home. When he runs it, he gets a "Bound Error: Array Access" and the dragon eats him with fries.
  • Lisp, where the famous knight-errant, after speaking with numerous experts in dragon-killing, and modeling the knowledge they posess, he programs the system, and when he runs it he realizes he forgot a bracket (bender the offender).
  • HTML: Mounts a web on famous swords used to kill dragons, but he ignores the W3C standards. When he meets the dragon, he finds out the code isn't compatible with his browser, so he's left swordless. The dragon eats him as an appetizer.
  • Prolog: Thinks he needs a weapon to kill the dragon. Searches in a catalog for 182014 weapons. By the time the princess dies of her age, he's achieved to know how to make every weapon starting with A: Atomic Bombs, Anti-Air Weapons, Arches, Ammunition, Axes...
  • PHP: Creates a web page that when he executes it would eliminate the $dragon selecting from a weapons databese in MySQL over an Apache server. Nevertheless he forgot the WHERE in the DELETE query and kills the princess, the dragon, the peasants, the witch, the sorceror and the programmer himself.
  • JavaScript: The programmer tries to kill  the great green dragon that spits fire throug his mouth. He creates a script that will delete the dragon when he loads a webpage, to create seconds after, some damsels to throw him flowers and make clapping sounds. Unfortunately he didn't take into account the DOM structure of the lizard, also known as Mozilla, and the only thing he gets is to fill his console of errors and that the Book of Mozilla tells how he was devoured.
  • ActiveX: The programmers create a tunnel to enter the dragon's lair from the castle and run a program that will kil the dragon from a safe and prudential distance. The dragon discovers the tunnel, eats the workers who dug, the dragon slayers, and enslaves every servant in the castle. The castle becomes a dragon-breeding place, full of little dragons that the dragon sends in pop-ups to other castles. The untasty remains of the knights are put in cans of Spam and sent to other castles as well as a warning. (aquelquesiente)
  • Basic. He creates a weapon able to kill paper dragons, but no matter how they improve it, they discover it's not good enough to kill any dragon bigger than a baby poodle.
  • Matlab: They create a loop that calculates the trajectories to shoot a giant arrow at the dragon. The program works flawlessly. What they need now are the voluntaries caoable to launch tha arrow with the necessary strength and accuracy.
  • Videogame Programmer : Spends two years programming a state-of-the-art sword with shaders and all. When the time comes to kill the dragon, he finds that half the knights aren't strong enough to raise the sword. Then someone programs a patch that reveals the sex scenes with the princess and Hillary Clinton makes it a scandal.

Quando ci si avvicina a un nuovo linguaggio come Java, è normale commettere errori. Tuttavia, secondo David Reilly, autore dell'articolo "Top Ten Errors Java Programmers Make", ci sono errori più comuni che tendenzialmente vengono ripetuti nel tempo. Della stessa opinione anche Neal Ziring, come emerge dal suo articolo "Novice Java Programmers' Favourite Mistakes".

Da queste due fonti, a cui potrei aggiungere anche "Common Java Coding Errors", ritroviamo elementi realmente comuni. Potrebbe essere che tutti gli autori hanno poca fantasia, o che in realtà l'ideatore sia solo uno e gli altri hanno preso spunto; tuttavia sembra più plausibile pensare che i novizi si dimenticano sul serio che Java è zero-indexed e che l'operatore di uguaglianza è == e non =.

Non posso però biasimare chi commette "infrazioni" come la denominazione del file in modo differente rispetto al nome della classe (se pubblica): chi viene da altri linguaggi sottovaluta certe piccolezze, soprattutto se non ne comprende il senso. Distrazioni come un "tentato overriding" con nome del metodo da sovrascrivere sbagliato possono essere passate, ma non lo possono essere noncuranze come la scrittura di gestori di eccezioni vuoti tipiche dei "furbetti in erba".

Per altre questioni forse la causa sta nella superficialità di insegnamento; ad esempio il concetto banale di passaggio di valore e passaggio di riferimento può essere tanto semplice da indurre il "maestro" ad assumere un atteggiamento sbrigativo senza porre la giusta enfasi. Si può notare anche come certi errori derivino da una incompleta o comunque insufficiente conoscenza (pragmatica) della programmazione orientata agli oggetti; per fare un esempio, l'accesso a membri d'istanza in contesti statici non ha molto senso.

A mio parere è ora di aggiornare la lista, oggigiorno non c'è più un passaggio da linguaggi come Pascal o C a Java, per cui forse (spero) c'è un aggiustamento di rotta su più fronti. In ogni caso la lista è interessante o quantomeno simpatica.