Rlieh

I'm getting older and need something to R'Lieh on

"Hello World" e il Web

In molti conosceranno la pagina di Wikipedia con la lista di tutte le implementazioni di quello che volgarmente è lo “stampare la stringa ‘Ciao, mondo!”

Come non citare la versione in Unlambda

`r“““““`.H.e.l.l.o. .w.o.r.l.di

linguaggio noto per la sua semplicità:

Mathematically, the core of the language can be described as an implementation of the lambda-calculus without the lambda operation, relying entirely on the K and S combinators. Hence the name “Unlambda”. It uses head (“eager”, “by value”, “strict”) evaluation. I cannot claim originality there. However, as far as I know, I am the first to have taken this theoretical concept and made it into an actual (deliberately obfuscated) programming language. I added a couple of functions (chosen for their obscurity) to the language so as to make output (and, in version 2, input) possible, or just to make things even more obscure (delay and call/cc are such).

E’ nota anche la pagina parodica in cui un varia l’età, l’esperienza e la mansione di chi scrive il codice

Successivamente ne è stata creata una versione relativa al web

Caso anomalo è però JavaScript, negli anni infatti non è stato modificato sostanzialmente il core del linguaggio (beh in qualcosa si ). La cosa più evidente da quello che si vede in questi esempi è il come il linguaggio sia usato diversamente (in un formato JSON-like sostanzialmente) dal passato.

2000


var myText = “Hello World”;
var _textNodeParent;
var docNodes = document.childNodes[1].lastChild.childNodes;
for(var j=0; jchildNodes.length; j++){
if(document.childNodes[j].lastChild){
for(var i=0; ilength; i++){
if(‘div’ == docNodes.item(i).nodeName.toLowerCase()){
if(‘layer_main’ == docNodes.item(i).id.toLowerCase()){
if (null != document.getElementById(‘bparent’)) { document.getElementById(‘bparent’).parentNode.removeChild(document.getElementById(‘bparent’));
}
_textNodeParent = document.
createElementNS(“http://www.w3.org/1999/xhtml”, “html:b”);
_textNodeParent.
id = ‘bparent’;
docNodes.
item(i).appendChild(_textNodeParent);
_textNodeParent.
appendChild(document.createTextNode(myText));
}
}
}
}
}

2008(oggi con Ext)

myVp = new Ext.Viewport({
layout:‘fit’,
autoHeight:true,
id:‘myVPid’,
items:[
new Ext.XTemplate(,
{text1}{text2}{text3},
).overwrite(Ext.get(‘layer_main’),{text1:‘Hello’,text2:‘ ‘,text3:‘World’})
]
});

Update chiarificante:

L’articolo json-for-the-masses di DustinDiaz spiega quali siano i benefici nell’utilizzare rispetto al tradizionale stile funzionale lo stile “ad oggetti” in JavaScript.

(On Functional Programming) The role of a function becomes globalized and yet becomes vague as to what its purpose is. Give it scope, then we’re in business

esempio funzionale:

var a = '';
var b = null;
var c = document.getElementById('c');
function init() {
// ...
}
function doThis() {
// ...
}
function doThat() {
// ...
}
function tweakThis() {
// ...
}
function runThat() {
// ...
}
function wrapThis() {
// ...
}
function stringifyThat() {
// ...
}
function calculateThis() {
// ...
}

window.onload = init;

No doubt we can fill in the gaps as to what this possibly might mean. The problem is that this may be okay for some small project where you’re the developer and the boss, but for any project of a respectably large size, you’ll find out that this is going to cause problems fast.

Esempio a oggetti

var behavior = {
a : '',
b : null,
c : Object,
init : function() {
// ...
this.c = document.getElementById('c');
},
doThis : function() {
// ...
},
doThat : function() {
// ...
},
tweakThis : function() {
// ...
}
}
var behavior2 = {
runThat : function() {
// ...
},
wrapThis : function() {
// ...
},
stringifyThat : function() {
// ...
},
calculateThis : function() {
// ...
}
}

Altro:

abdul

Abdul Alhazared, a.k.a. Al Azif, ha circa 1000 anni e gironzola su vari piani dell'esistenza. Dopo aver scritto il Necronomicon si è dedicato alla tecnologia e alla scienza, muovendosi di tanto in tanto in Europa.

2 pensieri su “"Hello World" e il Web

  1. Ma che razza di implementazioni Javascript sono?
    Ma siamo tanardi o che?

    E che cacchio:

    document.write(‘Hello World’);

    E che cacchio DOM:

    document.documentElement.appendChild(document.createTextNode(“Hello World”))

  2. Ext usa parecchio lo stile json.
    Le librerie esterne sono ormai tanto comuni che $ ha sostituito d’ufficio
    getElementById e la notazione ad oggetti ha soppiantato quella funzionale.
    Ora aggiorno il post per chiarire meglio il discorso.

Rispondi a Zingus J. Rinkle Annulla risposta

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.

Torna in alto