CSS Variables

So finally we have variables in CSS. The spec was written by Daniel Glazman and David Hyatt and WebKit has already implemented it.

Adding variables to CSS has probably been one of the most requested features. And although some people still seem to be against the whole idea, now we finally have them implemented.

Of course you can now wonder of how long it would take for IE to finally implement it. Given that IE8 already passes Acid2, then maybe it won't even be that long to wait, but even after that you still have to wait for years for all the older browser version to fall out of mainstream use.

But this doesn't really bother me that much, because at the meantime we can implement CSS variables on the server side, like some have already done. Of course, this was already possible and done with all kinds of different ways like mixing CSS with PHP or coming up with some nifty new CSS syntax. But the pile of all those different approaches was a big mess - now there is a standard, that everyone can implement. Even better: once CSS variables are available in your browser of choice, you can easily do most of your development without having server-side transformation of your CSS files, and only use the help of scripts when testing in older browsers and when finally releasing to the public.

I at least, welcome CSS variables.

Kirjutatud 5. juulil 2008. Avalda oma arvamust.

PHP Arrays: the Good, the Bad, the Future

The Good

The single best thing about PHP (the language) is the implementation of arrays. In all other similar languages (Perl, Python, Ruby, JavaScript) you always have to make decision:

In PHP you never have to make this decision -- you just always create an array and depending on how you use it, it will behave as associative array or as sequential array.

If there is anything worth copying from PHP by other languages, then this unification of normal and associative arrays is ceartanly one of those things.

Of course it's not all fun and joy as arrays in PHP eat quite a bit of memory. But from the ease-of-use perspective for the programmer, PHP arrays are pretty damn good.

The Bad

But although PHP arrays have all those great properties, they are still pain in the ass to use.

Let's look at an example. This is how you declare an array in Perl, Python, Ruby, JavaScript, ML, Haskell and probably in many other languages:

[[1, 2, 3], [4, 5, 6], [7, 8, 9]]

This is how you do the same in C++ and Java:

{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}

And from the historical perspective, here is the same in ALGOL:

((1, 2, 3), (4, 5, 6), (7, 8, 9))

And here we have Lisp, which is famous for it's lack of syntax, but with pretty good semantic sugar for arrays:

'((1 2 3) (4 5 6) (7 8 9))

Compare all these to "the PHP way" of doing things:

array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))

How in the hell did they came up with this syntax???

Probably like Larry Wall put it:

I thought of a way to do it so it must be right.

The Future

So is there any hope for this clumsy syntax to change in the future? PHP6 maybe?

Well, I guess no. There was a proposal for alternative short syntax for arrays, but it was voted down.

Like they say on the gate to PHP:

Abandon all hope, ye who enter here.

Kirjutatud 27. juunil 2008. Kommentaarid (2)

Pisike kaardirakendus

Sai tehtud väike JavaScripti-põhine kaardirakendus. Näite puhul on salvestamise võimalus välja lülitatud. Huvilised saavad aga ka kogu rakenduse lähtekoodi alla laadida.

Olingi juba ammu soovinud JavaScriptiga midagi huvitavat teha, kuid senimaani polnud tekkind otsest vajadust midagi teha. Nüüd aga sattus ette üks ülesanne, mille puhul paistis just JavaScriptiga lahendus kõige loomulikum.

Tegelikult seisis ülesande kirjelduses vaid, et tuleb koostada veebirakendus, kus saab lisada/muuta/eemaldada linnu ja nende vahekauguseid; kuid mina muidugi otsustasin natukene üle pingutada.

Tehnilisest küljest

Esimesena tekkis kohe küsimus, kuidas oleks võimalik JavaScriptiga kaardile paigutatud kahe linna vahele sirgjoont tõmmata. Õnneks viis guugeldamine mind üsna ruttu täpselt mulle vajaliku JavaScriptiga joonte joonistamise õpetuse juurde.

Kõige suurem häda lahendatud, sai prototype appi võetud ning kogu vajalik kood valmis kirjutatud. Prototype rokib!

PHP-le andmete edastamiseks sai otsustatud XML-i kasuks. PHP5 SimpleXML klass tegi selle töötlemise lihtsaimast-lihtsamaks. Andmebaasiga suhtluseks mõistagi PEARi MDB2.

Andmete kasutajale väljastamiseks tuli aga mängu Smarty. Ma üldiselt olen igasuguste mõttetute mallimootorite vastu, aga Smarty on kõrgemast klassist.

Rakendust on testitud Opera, Firefoxi, Konquerori, IE7 ja IE6-ga. Viimases näeb natuke nigelam välja, kuna IE6 ei toeta CSS-i :hover pseudoklassi teistel elementidel peale a.

Natuke sai tehtud ka kasutatavuse testimist oma korterikaaslase peal, misjärel sai nuppudele lisatud abitekstid ja mõningaid käitumisi muudetud.

Ilma JavaScripti ja CSS-ta brauserites saab küll nimekirja linnadest ja nende vahekaugustest näha, aga muutmine pole võimalik.

Lõpetuseks

Kindlasti on kuskil ka selline programm olemas, või siis annaks midagi märksa vingemat ehitada näiteks google maps’i peale, aga teinekord on tore ka ise jalgratast leiutada. Eriti kui selle käigus midagi uut õpib.

Kirjutatud 3. juunil 2007. Avalda oma arvamust.

Trinoloogialeht

Eesti Trinoloogide Maja. Eesti trinoloogiahuviliste avalik kogunemiskoht. info@triin.net

Peamenüü

Viimased artiklid

RSS, RSS kommentaarid, XHTML, CSS, AA