Frohes neues Jahr!
Yay! =)
Yay! =)
Finally, I made it! Started the project in July, worked on it for several days, then suspended it, returned several days ago, gave it new name, spent several evenings and now – it’s production-ready.
About a half of year ago I started to look closer at the go language – it it quite simple and have concurrency as its killer-feature. But solving tutorial tasks is quite boring, so I decided to do a project using this language and its technologies. My first idea was a web-based game and I started to implement it with Revel as web-framework, GORM as ORM and Postgres as DB. I even made several pull requests to GORM to implement couple features that I required. But couple weeks later I understood that project progress moves too slow as I don’t have enough experience neither with go language nor with its tools to complete the project in appropriate time. So I decided to implement much simpler project first. And for me, the most simple web-project type is simple blog engine.
Atlassian manager who decided to remove markup mode from Confluence editor and leave only WYSIWYG mode hates programmers. That’s for sure!
There are lots of programming languages - some of them more popular, some less. But as I can see it - all languages were initially created to solve one problem (or set of problems) that existing languages solve it the wrong/complicated/any-other-word way (as new language creator sees it). Language creator(s) has its own opinion on the new language synthax, synthax sugar etc.
Time goes, some languages become popular, developer comunity grows, new people has their own vision on how things should be done right. E.g. all modern PHP frameworks move in Java-way - every new language release gets more OOP-stuff, two the most popualar PHP frameworks - Symfony2 and Zend Framework 2 - are huge monsters right now, implemented in the “right OOP way” with all its Interfaces, AbstractFactories, 3+ levels of inheritans, etc. Drupal, that has its own style, is moving to Symfony2 components in the next (8) version, and I can not say I really like it. We already have Java and C#/.NET - why do we need to make the same things in PHP? In several years PHP may bacome Java w/out strict typing and compillation.
Accidental rm -rf on wrong directory turns common evening into interesting one, shi…
PS: everything could be much worse =)
Now I do have favorite poem and it is in German. I’m learning German for about half of the year - very interesting language. And tonight I discovered Goethe poetry and a poem that I like very much. It is Erlkönig by Johann Wolfgang von Goethe:
Wer reitet so spät durch Nacht und Wind?
Es ist der Vater mit seinem Kind;
Er hat den Knaben wohl in dem Arm,
Er faßt ihn sicher, er hält ihn warm.
Mein Sohn, was birgst du so bang dein Gesicht? -
Siehst, Vater, du den Erlkönig nicht?
Den Erlenkönig mit Kron und Schweif? -
Mein Sohn, es ist ein Nebelstreif. -
"Du liebes Kind, komm, geh mit mir!
Gar schöne Spiele spiel ich mit dir;
Manch bunte Blumen sind an dem Strand,
Meine Mutter hat manch gülden Gewand."
Mein Vater, mein Vater, und hörest du nicht,
Was Erlenkönig mir leise verspricht? -
Sei ruhig, bleibe ruhig, mein Kind;
In dürren Blättern säuselt der Wind. -
"Willst, feiner Knabe, du mit mir gehn?
Meine Töchter sollen dich warten schön;
Meine Töchter führen den nächtlichen Reihn,
Und wiegen und tanzen und singen dich ein."
Mein Vater, mein Vater, und siehst du nicht dort
Erlkönigs Töchter am düstern Ort? -
Mein Sohn, mein Sohn, ich seh es genau:
Es scheinen die alten Weiden so grau. -
"Ich liebe dich, mich reizt deine schöne Gestalt;
Und bist du nicht willig, so brauch ich Gewalt."
Mein Vater, mein Vater, jetzt faßt er mich an!
Erlkönig hat mir ein Leids getan! -
Dem Vater grausets, er reitet geschwind,
Er hält in Armen das ächzende Kind,
Erreicht den Hof mit Mühe und Not;
In seinen Armen das Kind war tot.
English translation can be found here.
It was not surprise for me that latest stable, 11 for now, MS Internet Explorer does not support date input type. But I was shocked by the fact that the latest stable FireFox version, 25 for now, does not support it too! Actually, the only browser that does is Chromium. And of course browsers based on Chromium - Google Chrome and Opera.
In PHP DateTime::createFromFormat() method has one non-obvious behavior that I recendtly discovered. The best way to show is give quick and simple example.
$dateStr = '2013-11-07T16:48:98+0400';
$dt = DateTime::createFromFormat(DateTime::ISO8601, $dateStr);
var_dump($dt->format(DateTime::ISO8601));
My expectaion from evaluting this piece of code was false or null as seconds should be valid only for 00-59 range. But, as usually, reality (and PHP developers) has its own opinion. The output for this piece of code is string(24) "2013-11-07T16:49:38+0400".
So, what PHP does - it treats 98 seconds as 1 minute and 38 seconds, and minutes are added to the written in string format. Same applies to hours (2013-11-07T16:68:98+0400 => 2013-11-07T17:09:38+0400), etc.
HTTP queries in application/x-www-form-urlencoded encoding type is simple key/value list and in the most cases this is enough. But sometimes it’s required to send more complex data types. Lists are supported in Django HttpRequest out of the box, so foo=1&foo=2 can be received as list with request.get_list('foo'). But there is one more thing that makes web-developer life easier and that is supported in PHP by default - passing arrays.
Array in PHP is powerful type, that combines Python’s list and dict - keys can be both integer and string types, plus all types that can be casted to these (all but array and object). So query passed to PHP in the form foo[bar]=1&foo[baz]=2&foo[100]=3 will be available as array by $_REQUEST['foo']['bar'], $_REQUEST['foo']['baz'] and $_REQUEST['foo'][100].
Array is one of the most powerful and most used type in PHP. Actually this type combines functinality that other programming languages includes in different types. These types are linear array - list type in terms of Python or List interface in terms of Java and associative array - dict, or more likely OrderedDict, in terms of Python or HashMap in terms of Java.
But sometimes array behavior should be extended for better programmign experience, cleaner code and logic. For example, here is piece fo code that can be found in many projects: