Sep 07

Short post #1

Wow, it was almost 4 months since my last post. But don’t worry I’m keeping on mind Marek’s first comment of the first post on this blog ;) I won’t let this blog die :p There are few drafts in my dashboard and with a little fortune I’ll post them in the future :) This post is just a short note to keep “Hello World” alive.

There was a really interesting conference in San Francisco yesterday. Rasmus Lerdorf talked about PHP and its future. Unfortunately there are several hundred kilometers between me and San Francisco and I couldn’t attend this interesting meeting.

Luckily a friend of mine sent me a link to presentation from the conference. It begins with slides about the past and few good points why PHP became so popular (which is somehow connected to topic of one of my drafts mentioned before). Then things Rasmus keeps on mind in 2011. I’m really glad node.js + PHP is mentioned there.

Few slides about performance and I’m sad that I couldn’t listen more about it live. And then slides about PHP 5.3 — I’m shocked: closures in PHP?!

< ?php
$data = array(3,2,8,5,6,1,7,4,9);
usort($data, 
             function($a,$b) { 
                 if($a%2==$b%2) return $a>$b;
                 return ($a%2) ? 1 : -1;
             }
     );
foreach($data as $v) echo "$v ";
?> 
< ?php
$getClosure = function($v) {
    return function() use($v) {
        echo "Hello World: $v!\n";
    };
};

$closure = $getClosure(2);
$closure();
?>

And look at this strange ternary operator use:

< ?php
echo true ?: 'Hello';
echo false ?: 'World';
?>

Finally, after few other features in PHP 5.3 author presents us news from PHP 5.4 world:

  • Short array syntax:
< ?php
$a = [1, 2, 3];
$b = ['foo' => 'orange', 'bar' => 'apple'];
?>
  • FAD which means Function Array Dereferencing:
< ?php
function fruits() {
  return array('apple', 'banana', 'orange');
}
echo fruits()[0]; // Outputs: apple
?>
  • And more about/for closures:
< ?php
class Foo {
  private $prop = "bar";
  public function getPrinter() {
    return function() { echo ucfirst($this->prop); };
  }
}

$a = new Foo;
$func = $a->getPrinter();
$func(); // Outputs: Bar
?>

It recalls me JavaScript so much that I don’t know what to say ;) Is it a good move or bad? One thing which comes to my mind is that with this possibilities and new features PHP programmers should really know the language they use. And not to make mistakes will be more equal to know good patterns.

But there are also more positive changes for me: JSON improvements and UTF-8 as a default encoding.

Feel welcome to visit the slides’ page and to comment!

Permanent link to this article: https://blog.lukaszewski.it/2011/09/07/short-post-1/

May 13

Server-side JavaScript and 3rd devmeeting

Have you ever heard about JavaScript? Of course you have! And maybe you didn’t like it as much as I didn’t around 5 years ago. I didn’t like it mostly because it was really hard to debug. But after Firefox and its plug-in Firebug appeared it started to be a lot easier. Not mentioning here Google Chrome and its Inspector. And nowadays even IE has something built-in like Firebug for Firefox! :)

Why am I writing it? Because today I know JavaScript is AWESOME! It is still mostly used as a presentation language on many websites (to make them more interactive) and still I understand theoretically closures. But anyway, I want to know it better because there are also more and more browser and mobile games written in JavaScript. Some polish tech-portals even went a step further and they predicted in this decade JavaScript would get really popular. And it will be the first cross-platform language and new leader among programming languages, they’ve written.

However, I’m a newbie and I don’t have much experience in writing in JavaScript, so things are pretty slow till I got them done. Tomorrow is another devmeeting which I’m going to attend to and I needed to have NodeJs and RingoJs installed on my laptop. As I remembered well, last time I took me few hours and I didn’t install NodeJs finally. I got a pizza, some beer, girls went out today and I was ready for the battle. But guess what?

$ python 
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)

(OK, their recommendation is equal or higher than 2.4)

$ mkdir ~/local/nodejs-test/
$ cd ~/local/nodejs-test/
$ sudo apt-get install python-software-properties
...
$ sudo add-apt-repository ppa:jerome-etienne/neoip
...
$ sudo apt-get update
..
$ sudo apt-get install nodejs
...
$ npm install express

And that’s it! Can you imagine that? Last time I’ve been trying to build and install NodeJS for hours and I didn’t make it out. Today it took me several minutes. I tested my installation with example code on the main page of node.js. This is another important thing in “world of JavaScript”. One: NodeJS as jQuery Mobile and other JavaScript projects have a great community. Two: NodeJS is still a beta version and it’s been used several times at production environments of several projects as I’ve read.

How was it with RingoJS? It was even easier (at last with my Ubuntu). I’ve just run .deb file downloaded from page of RingoJS. It’s been installed in /usr/share/ringojs/. I’ve just ran the demo and it worked! :) Again — several minutes.

$ ringo /usr/share/ringojs/apps/demo/main.js
0    [main] INFO  ringo.webapp.daemon  - init
1951 [main] INFO  ringo.webapp.daemon  - start
1953 [main] INFO  org.eclipse.jetty.util.log  - jetty-7.1.6.v20100715
2127 [main] INFO  org.eclipse.jetty.util.log  - Started SelectChannelConnector@0.0.0.0:8080
2127 [main] INFO  ringo.httpserver  - Server on http://localhost:8080 started.

Conclusion: using JavaScript and tools related to it is getting really easy. The community connected to this language seems as a really nice bunch of geeks who are doing their work as fast and good as it’s possible. Everything looks like JavaScript will get more popularity in next few years because it’s not only client-side language, anymore. And all of that pure facts leads me to learn this awesome language better and try to start few projects based on it.

And I’ll try to post something about workshop/devmeeting which I’ll attend to, tomorrow.

Cheers,
Andrew.

Permanent link to this article: https://blog.lukaszewski.it/2011/05/13/server-side-javascript-and-devmeeting/

Apr 12

Hello world!

Welcome to my blog!

I can’t believe myself, I’ve started to write a blog. But more funny thing is that’s my second blog in two years period! But the other one is not on-line anymore. And it was a little bit different: nothing interesting posted. There was just first post which explained my idea of having a blog and my lack of time to manage it back then.

Yea, back then I worked hard on my thesis. And I assured my readers (if any :p) I’d start putting more posts here when I graduated. And it became a fact. I’ve graduated and I’m really thinking about writing about (usually programming) problems and other things that are happening in my life. Maybe it’ll help someone but it’s also good for me: if I handle a problem I’ll describe it here. Therefore if the problem occurs again I’ll be able to check my blog, find out I fought against it some time ago and read how to solve it one more time (if I wouldn’t remember). So, the idea of having this blog is similar to other IT guys who have blogs (for example: Marek Pietrzak and his “drawer” :)).

I’ve got few ideas of articles I’d like to post here but I won’t share it with you know. Just stay tuned and wait for another post!

Cheers,

Andrew.

Ps. I’m still improving my English skills so any comments about my typos/mistakes are most welcome! Thanks Marek for finding few of them :)

Permanent link to this article: https://blog.lukaszewski.it/2011/04/12/hello-world-3/

» Newer posts