Claudiu Persoiu

Blog-ul lui Claudiu Persoiu


Archive for the ‘hack’ tag

Collecting Hack

without comments

Stamp-Collection

Something I didn’t approach in my last blog is collections. Hack comes with a variety of collections for organizing data.

Data structures represent a fundamental part of a programming language, because they will determine the information flow in the application.

PHP up to version 5 had a single type for data collections, called “array”. This data type can have three uses: arrayhash table, or a combination of the two.

To facilitate the construction of new structures, a number of  iteratori were introduced in PHP 5. Unfortunately, the resulting structures had the purpose of accessing objects in a similar fashion with arrays.

Not until PHP 5.3 data structures like  SplStack and many others that are truly different were introduced.

However, structures like vectors and tuples were never natively introduced. They can be built, but it is neither simple, nor intuitive.

HHVM’s Hack comes with a different approach, a series of  native collections that are ready to be used.

Collection types

The list of collections is:

  • Vector – indexed list of items,
  • Map – dictionary type hash table,
  • Set – list of items that only stores unique values
  • Pair – a particular vector case that only has two elements.

Vector, Map, and Set also have immutable (read-only) equivalents. These are:  ImmVectorImmMap and ImmSet. The purpose of these data types is to expose the information for reading purposes and not allow modifications. An immutable collection can be directly generated using the constructor, or using the methods: toImmVector, toImmMap and respectively toImmSet.

Even more, there are a series of abstract classes to help easily implement similar structures:

 

Vector

The advantage of a vector is that it will always have the keys in sequence and the order of the elements is not going to change. When it comes to arrays, there isn’t any simple way to check if it should behave as a hash table or as a vector. For vectors, unlike for hash tables, the key value is not relevant, only the sequence and the number of elements are important.

Let’s take an example:

<?hh

function listVector($vector) {
     echo 'Listing array: ' . PHP_EOL;
     for($i = 0; $i < count($vector); $i++) {
          echo $i . ' - ' . $vector[$i] . PHP_EOL;
     }
}

$array = array(1, 2, 3);

listVector($array);

// eliminating an element from the array
unset($array[1]);

listVector($array);

The result will be:

Listing array:
0 - 1
1 - 2
2 - 3
Listing array:
0 - 1

Notice: Undefined index: 1 in ../vector.hh on line 6
1 -

The reason is very simple: count returns the real number of elements, but the index is not guaranteed sequential. When the second element of the array was removed, the number of elements was reduced by one, but the index with value 1 was no longer set and the last index is equal to the size of the array, so it will never be reached.

Let’s take the same example but using a vector:

<?hh
… 
$vector = Vector{1, 2, 3}; 

listVector($vector); 

// eliminating an element from the vector
$vector->removeKey(1); 

listVector($vector);

Like we anticipated, the result is:

Listing array:
0 - 1
1 - 2
2 - 3
Listing array:
0 - 1
1 - 3

It is worth mentioning that “unset” can not be used, because it is not a key to be eliminated, but the element itself, and the next value in the vector will take its’ place.

Another important thing to mention is that when an index doesn’t exist, an exception of the type “OutOfBoundsException” will be thrown.

Some examples that will trigger the exception above:

<?hh 

$vector = Vector{1,2,3,4}; 

// it will work because the key with value 1 exists 
$vector->set(1, 2);

// it will not work because the key with value 4 doesn't exist yet
$vector->set(4, 5);

// it will not work for the same reason as above
$vector[4] = 5;

// for addition only method that don't provide the key work
$vector[] = 5;

// or
array_push($vector, 5);

For accessing elements, the “OutOfBoundsException” problem remains the same. For instance, if the index 10 doesn’t exist:

var_dump($vector[$unsetKey]);

Another more special case is when the element doesn’t exist, but the method “get” is used:

var_dump($vector->get($unsetKey));

The example above will not generate an error, but the result will be “null” when the key doesn’t exist. I find this strange, because an element with the value null can exist in the vector, and the result will be the same.

To avoid the confusion between undefined elements and elements that are null, there is a special method to check if the key exists:

var_dump($vector->containsKey($unsetKey));

Removing elements from the vector is done with:

$vector->remove($key);

Or to remove the last element:

$vector->pop();

Map

In a hash table, unlike a vector, the order of the elements is not very relevant, but the key-value association is very important. For this reason, a Map is also called a “dictionary”, because you can easily get from a key to a value, since they are “mapped”, hence the name “Map”.

The HHVM implementation will also retain the order in which the elements were introduced.

In PHP, the equivalent of a Map is an associative array.

Unlike Vector, Map needs a key that will permanently be bind with the element, even if new values are added or removed from the collection.

The functions array_push or array_shift will not work for Map, because a key is not sent and the key-value association would not be controlled:

<?hh 

$map = Map{0 => 'a', 1 => 'b', 3 => 'c'};

array_push($map, 'd');

array_unshift($map, 'e');

var_dump($map);

Will generate the following result:

Warning: Invalid operand type was used: array_push expects array(s) or collection(s) in ../map.hh on line 5

Warning: array_unshift() expects parameter 1 to be an array, Vector, or Set in ../map.hh on line 7
object(HH\Map)#1 (3) {
  [0]=>
  string(1) "a"
  [1]=>
  string(1) "b"
  [3]=>
  string(1) "c"
}

As you can see, the elements were not added and each of the cases generated a Warning.

The actual insert can be done using:

<?hh 

$map = Map{0 => 'a', 1 => 'b', 3 => 'c'};

// adding an element using the array syntax
$map['new'] = 'd';

// adding an element using the method provided by the structure
$map->set('newer', 'e');

var_dump($map);

The result will be:

object(HH\Map)#1 (5) {
  [0]=>
  string(1) "a"
  [1]=>
  string(1) "b"
  [3]=>
  string(1) "c"
  ["new"]=>
  string(1) "d"
  ["newer"]=>
  string(1) "e"
}

Unlike Vector, because the element is closely linked with the key, unset is a viable method for removing an element:

unset($map[$key]);

The structure also has a method for removing the element with a particular key:

$map->remove($key);

For this case, none of the options will generate an error, if the key is not set.

The “OutOfBoundsException” exception is also found here for keys that are not defined, and just like for Vectors, there is a method to test if the key exists:

$map->contains($key);

Similarly to Vector, there is a method that will return true if the key exists and null if not:

$map->get($key);

To make sure that a “OutOfBoundsException” will not be raised, a loop over a Map should not be done using “for” , but rather “foreach”.

Because the vector’s method “pop” does not use a key, it isn’t present in the Map structure.

Set

Set has the purpose of keeping the values unique. For this structure, the values are restricted to the scalar types: string and integer.

The interface for this structure is much simpler than Vector and Map, because the purpose is a lot more limited.

For Sets the key can not be accessed, but it is relevant in a special way.

Let’s take an example to illustrate this:

<?hh
$set = Set{'a', 'b', 'c'}; 

foreach($set as $key => $val) {
     echo $key . ' - ' . $val . PHP_EOL;
}

The result will be:

a - a
b - b
c - c

The key and the value are identical, a clever way to keep unicity.

However, the process is transparent, fact that allows adding elements without a need for a key:

<?hh

$set = Set{'a', 'b', 'c'};

array_push($set, 'd');

array_unshift($set, 'e');

$set[] = 'f';

var_dump($set);

There will be a result similar to the one from vectors:

object(HH\Set)#1 (6) {
  string(1) "e"
  string(1) "a"
  string(1) "b"
  string(1) "c"
  string(1) "d"
  string(1) "f"
}

Even though new values can be added using the “[]” operator, they can’t be referenced using this operator:

<?hh

$set = Set{'a', 'b', 'c'};

echo $set['a'];

It will generate the following error:

Fatal error: Uncaught exception 'RuntimeException' with message '[] operator not supported for accessing elements of Sets' in ../set.hh:5
Stack trace:
#0 {main}

For removing elements only the native method (remove) and methods that don’t require a key can be used:

<?hh 

$set = Set{'a', 'b', 'c', 'd'}; 

array_pop($set); 

array_shift($set); 

$set->remove('b');

var_dump($set);

The result will be:

object(HH\Set)#1 (1) {
  string(1) "c"
}

Unlike Vector and Map, the “remove” method will receive the value to be removed, not the key.

For Set there isn’t any access key for elements, therefore about all we can do is to check if an element exists, using “contains”:

$set->contains($value);

The method will return a bool showing if the element exists or not.

Pair

A pair is a collection with two elements. It can’t have more or fewer. Just like in Vectors, the elements are indexed using a key that in this particular case can have only two values 0 and 1.

There aren’t a lot of things to be said about this data structure, because the elements can not be removed, added or replaced. This is the reason why it doesn’t have an immutable equvelent, because the structure itself is not flexible:

<?hh 

$pair = Pair{'a', 'b'}; 

foreach($pair as $key => $val) {
     echo $key . ' - ' . $val . PHP_EOL;
}

The result will be:

0 - a
1 - b

A very simple structure for a very simple purpose.

Common ground

Almost all structures presented above have few common methods and behaviors. Almost all, because Set and especially Pair are more restrictive through their nature and lack some features which Vector and Map have.

Filter

It’s a filtering function that comes from functional programming. The purpose is to filter a data structure and to generate a new one of the same type. The exception is Pair, because of the number of elements restriction. The equivalent in PHP is array_filter.

Vector and Map have two methods: filter and filterWithKey. These methods take an argument of type “callable”, in other words a function:

<?hh 

$vector = Vector{'a', 'b', 'c', 'd', 'e'}; 

// eliminate the element with value 'a' 
$result = $vector->filter($val ==> $val != 'a');

// eliminate every other element using the key
$result2 = $vector->filterWithKey(($key, $val) ==> ($key % 2) == 0);

var_dump($vector);
var_dump($result);
var_dump($result2);

The result will be:

object(HH\Vector)#1 (5) {
  [0]=>
  string(1) "a"
  [1]=>
  string(1) "b"
  [2]=>
  string(1) "c"
  [3]=>
  string(1) "d"
  [4]=>
  string(1) "e"
}
object(HH\Vector)#3 (4) {
  [0]=>
  string(1) "b"
  [1]=>
  string(1) "c"
  [2]=>
  string(1) "d"
  [3]=>
  string(1) "e"
}
object(HH\Vector)#5 (3) {
  [0]=>
  string(1) "a"
  [1]=>
  string(1) "c"
  [2]=>
  string(1) "e"
}

As you’ve noticed, the result of the “callable” function is treated as a bool and according to this the elements are added to the resulting structure.

Map has an identical behavior with Vector, the only difference is in the nature of the keys.

Something interesting is that a collection can also be immutable, because the operation doesn’t modify the original structure, but the it will also have the type of the original structure:

<?hh 

$vector = Vector{'a', 'b', 'c'}; 

$vector = $vector->toImmVector();

// eliminate the element with value 'a'
$result = $vector->filter($val ==> $val != 'a');

var_dump($vector);
var_dump($result);

The result will be:

object(HH\ImmVector)#2 (3) {
  [0]=>
  string(1) "a"
  [1]=>
  string(1) "b"
  [2]=>
  string(1) "c"
}
object(HH\ImmVector)#4 (2) {
  [0]=>
  string(1) "b"
  [1]=>
  string(1) "c"
}

 

Pair also has the same functions as Vector and Map, but the behavior is not identical, because of the fact that Pair can only have 2 elements, no less, no more. For this reason, when a Pair is filtered, the result will be ImmVector, a similar structure with Pair but with a variable number of elements:

<?hh 

$pair = Pair{'a', 'b'}; 

// eliminate the element with value 'a'
$result = $pair->filter($val ==> $val != 'a'); var_dump($result);

The resulting structure will be:

object(HH\ImmVector)#3 (1) {
  [0]=>
  string(1) "b"
}

Set only has the “filter” method, because, as was demonstrated earlier, the keys are identical with the values. If it had had a method with keys, it would have worked the same.

Map

Another function coming from functional languages is “Map”. This aims to modify the values of a structure using a function, the resulting structure having the type of the source. In PHP, the equivalent is array_map.

Similarly with filter, Vector and Map have the common methods: “map” and “mapWithKey”. In this case also, they take a “callable” as an argument:

<?hh 

$vector = Vector {'a', 'b', 'c'}; 

$result = $vector->map($val ==> $val . $val);

$result2 = $vector->mapWithKey(($key, $val) ==> str_repeat($val, 1 + $key));

var_dump($vector);
var_dump($result);
var_dump($result2);

The result will be:

object(HH\Vector)#1 (3) {
  [0]=>
  string(1) "a"
  [1]=>
  string(1) "b"
  [2]=>
  string(1) "c"
}
object(HH\Vector)#3 (3) {
  [0]=>
  string(2) "aa"
  [1]=>
  string(2) "bb"
  [2]=>
  string(2) "cc"
}
object(HH\Vector)#5 (3) {
  [0]=>
  string(1) "a"
  [1]=>
  string(2) "bb"
  [2]=>
  string(3) "ccc"
}

The result of the “callable” function is the new value of the element in the structure.

Just like with “filter”, an immutable collection will result in a new immutable collection.

Also similar with “filter” is the fact that the “map” function applied to a Pair will result in an ImmVector:

<?hh 

$pair = Pair{'a', 'b'}; 

$result = $pair->map($val ==> $val . $val);

var_dump($result);

Will result in:

object(HH\ImmVector)#3 (2) {
  [0]=>
  string(2) "aa"
  [1]=>
  string(2) "bb"
}

Conversion

Some of the elements can be converted to different types:

from \ ro Vector Map Set Pair Array
Vector x x x x
Map x x x x
Set x x x
Pair x x x x
Array x x x x

There are several structural restrictions to the table above:

1. Any structure that is getting converted to Set must only contain scalar values of type int and string:

(Map{})->add(Pair {'a', new stdClass()})
    ->toSet();

Will generate the error:

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Only integer values and string values may be used with Sets' in …

2. When a Map is converted to any other structure, except array, it will loose the keys in most cases.

The conversion from an array to other structures is done using:

$vector = new Vector ($array);

Beside Pair, all structures above have a single parameter that implements Traversable for the constructor.

Conclusions

Hack brings a new perspective over the most popular data type in PHP. Facebook’s reason is a simple one, optimization. If you have a consistent behavior, that particular structure can be optimized. In PHP that’s not exactly possible, because of the fact that an array in PHP can be any type of collection.

From the data structure point of view, I find it interesting to have this kind of data types. In frameworks, there are usually structures that emulate the behavior of the collections introduced by Hack. For instance in an ORM, a collection of objects is usually represented as a vector, because the purpose is to iterate over its’ values. An object that represents the values of the fields from a table will be a Map like structure, because the value of the field is closely related to the field name.

I find it very interesting not only that now we have this structures, but also that we have the interfaces to implement new ones.

I hope Hack will influence PHP to bring purpose specific structures into the language.

Written by Claudiu Persoiu

30 May 2014 at 11:50 AM

Posted in PHP

Tagged with , , , , , , ,

Hack programming language, the PHP apocalypse?

without comments

you-have-been-hacked

Introduction

About a month ago, Facebook released  the Hack programming language.

Since then, apocalyptic articles related to this language and to how it will replace PHP have appeared everywhere. The title of this article was inspired by  “Will Hack Kill PHP?“.

What is even more strange to me is that it was followed by a wave of negative assessments related to PHP, apparently Hack “fixes” the previously mentioned language. In my opinion, the language has to be “broken” in the first place to be “fixed”.

Off-course PHP has many drawbacks, like any other programming language, but there must be a good reason why it is the most popular language for the Web. After all, Facebook used it for a long time, and now it is not replaced, they are improving it… aren’t they?

One thing is for certain, it is probably one of the least inspired names. When you search for “Facebook hack” you will find anything else but this programming language…

About Hack

Hack is running on HHVM. HHVM is Facebook’s try to optimize the PHP language with Just In Time complication, the latest approach in optimization of the language. Basically, Facebook is trying to reduce their costs by optimizing the language interpreter, and now with a new language all together. After all, if we think about Facebook’s infrastructure, it’s normal for them to do this, even a relatively minor optimization will lead to a consistent cost reduction.

Initially, I thought it was an “improved” version, but it seems like it is another language altogether, basically it’s a PHP with something extra!

A small tutorial of the language is at: http://hacklang.org/tutorial/.

The tutorial doesn’t cover all the features of the language, more details are at: http://docs.hhvm.com/manual/en/hacklangref.php.

Practically, about all the features that differ in Hack from PHP are optional. You can almost write PHP and it will work. Contrarily to expectations, not even specifying the type of the input/output of the variables is not required.

Because after all it’s a different programming language altogether, I’m not going to go into much details on all the new features. That is more the purpose of a book, not an article.

I only want to point out a few features that I found interesting.

Typechecker

Strangely, at least at the begging, at runtime the type of the result, even though it is sent, is not necessarily interpreted.

Let’s take an example:

<?hh 

function a($a): void {
     return true;
}

echo a('a');

This example will have the output… 1.

Basically, at runtime only the input type is checked, not the output one.

To run the Typechecker in the current directory, an empty file must be added:

$ touch .hhconfig

Then run:

$ hh_client

As you can see, the data types are checked in a separate step beside runtime.

At the manual execution of the Typechecker, it will find all the inconstancies. The purpose is for it to identify the problems before the runtime, for instance when you edit a file, not when the app is actually running.

The Typechecker output is:

../test.php:4:9,12: Invalid return type
../test.php:3:17,20: This is void
../test.php:4:9,12: It is incompatible with a bool

Unfortunately, there is still a lot of work to be done with this feature. If we try to validate only at runtime, using “type hinting” like in PHP, the function becomes:

function a(int $a): void {
     return true;
}

echo a('a');

The output of the Typechecker is not changed, but upon execution the result will be:

Fatal error: Argument 1 passed to a() must be an instance of int, string given in ../test2.php on line 5

Basically, the Typechecker is doing what the type hinting is not and the the latter is now also receiving scalar type arguments.

Even if the only change was to add scalar arguments checking, I would have still considered it an important improvement.

Lambda operator

It is a syntax that is more popular with the functional languages.

An example:

<?hh 

$sqr = $x ==> $x * $x;

echo $sqr(5) . PHP_EOL;

Off course the result will be 25.

I find it a very interesting and clear way to represent small logic.

In the new syntax, a function can also return another function:

$add = $x ==> $y ==> $x + $y;

$result = $add(1);

echo $result(2) . PHP_EOL;

The result will be 3.

If a variable from inside a lambda expression doesn’t exist in the scope of the function definition, then it will be retrieved from the environment in which the expression was declared:

// variable in the current scope
$z = 5;

$addZ = $x ==> $x + $z;
// change the variable in from current scope
$z = 6;

// perform the add
echo $addZ(1) . PHP_EOL;

The result will be… 6!

The equivalent in PHP is:

$addZ = function ($x) use ($z) {
     return $x + $z;
}

The value of $z will be retrieved for the environment where the function was defined, not as a reference to the variable.

Off course that’s not the case when the variable from the outside of the function is an object, in this case it will be passed by reference:

<?hh 

class a {         
     public function __construct(public string $x) {}         
     public function __toString() { 
          return $this->x; 
     }
}

// variable in the current scope
$z = new a('Claudiu');

$addZ = $x ==> $x . ' ' . $z . '!';

// change the variable that will be used for concatenation
$z->x = 'World';

// run the concatenation
echo $addZ('Hello') . PHP_EOL;

The output will be:

Hello World!

Shapes

Again, a syntax more popular with the functional programming languages. The purpose is to validate a more specific type of structure than an array.

The reason is very good, validate simple data structures. The structures that are getting checked should contain the elements defined in the shape.

<?hh 

// defining a structure
newtype Circle = shape('radius' => int);

// a function that will is using the type of the structure above
function areaCircle(Circle $param) {
     return M_PI * $param['radius'] * $param['radius'];
}

// a series of shapes that are using the structure
$circle = shape('radius' => 10);
$cilinder = shape('radius' => 10, 'height' => 15);

// a structure that should not work pass as Circle
$sqr = shape('side' => 10);

echo areaCircle($circle) . PHP_EOL;
echo areaCircle($cilinder) . PHP_EOL;
echo areaCircle($sqr) . PHP_EOL;

The output is:

314.15926535898
314.15926535898

Notice: Undefined index: radius in /home/brand/test.hh on line 6

Notice: Undefined index: radius in /home/brand/test.hh on line 6
0

A little disappointing, I was hoping that the parameter that doesn’t match the structure will trigger an error, but it passes.

Not even the Typechecker finds anything wrong.

The intention is very good, now we just have to wait for the working version.

Conclusion

Probably Hack will influence PHP, which is normal in the end, it happens all the time with programming languages.

Will it replace PHP? I don’t think so, probably there will be a lot of adopters for cost reduction or a better structuring of the code.

It is not very kely for this language to be successful in the following years other than for projects of medium and large sizes. For small projects usually shared hosting is used, and this generally doesn’t have the latest PHP version, it is even less likely for it to have the latest HHVM. This is probably one of the least interesting arguments, but in the end most of the websites on the web are of small and very small size, they make up the “mass”.

An easier approach to optimization is to only use HHVM. In theory, you don’t have to change anything and the results should be visible immediately! Practically HHVM is not 100% compatible with Zend Engine, but this problem is getting less of an issue with each version. One of the priorities for HHVM is to interpret the code the same way Zend Engine does, but to be much more efficient!

Written by Claudiu Persoiu

29 April 2014 at 10:15 PM

Posted in PHP

Tagged with , ,

Yahoo! Open Hack day Europe 2011 in Bucharest – review

without comments

After a couple of days of almost no sleep, about 6 Red Bulls and an app, Yahoo Open Hack Day Europe 2011 was over.

Initially I only wanted to go to tech talks. Later I though that I should go as hacker because I didn’t what to miss anything from the event, but not to present a project. Ultimately I was chosen to present the project.

Everything began at 7 am, when a colleague came to pick us up in time to have a cup of coffee before the event. We were 6 attendees so we thought that we can split into two teams.

At about 9 am we’ve arrived at Crystal Palace Ballrooms. We were greeted by the “crew” in green t-shits, who have guided us to the registration offices.

Once registered we started looking for a table in the room where all 6 of us can sit. In the room there were about 350 people who came for both hacking and tech talks.

In the middle of the room there was a table reserved for experts and Yahoo! staff. At some point a colleague tells me: “isn’t that Crockford?”. Indeed he was at the reserved table Douglas Crockford, along with many other important Yahoo! figures. I’ve rushed to get my book (JavaScript: The Good Parts) which I’ve brought specially for this event hoping to get an autograph.

Nervous, I approached his table: “Mr. Crockford?”, he saw the book and smiling he answered “Hey, my book!”. Nervously I gave him a pen and asked him to give me an autograph. I know it sounds ridiculous, but for me to meet someone of DC stature, about who I’ve only saw presentations at Google and Yahoo! and read his book, to meet face to face, to have the opportunity to ask for an autograph  and shake his hand was like meeting a famous actor.

I’ve returned to our table and I’ve bragged to everyone with my autograph, I thought that the first item on my agenda was achieved.

The tech talks began:

  • “Hacking 101” by Murray Rowan
  • YQL and other Y! APIs” by Jon Leblanc
  • YUI” by Luke Smith
  • node.js” by Reid Burke
  • “Introduction to Yahoo Messenger API” by Vivek V Aggarwal
  • “Server Sidedness” by Doug Crockford

Node.js and YQL were the most fascinating talks for me, because I haven’t used neither of the technologies. I find node.js very interesting for JavaScript games, where communication is very dynamic and PHP is not very suitable. On the other hand, if I knew of YQL’s existence it would have helped me get rid of a lot of work so far.

After the tech talks the hacking started. Two of my colleagues were going to make an app to clean the page of anything but relevant content. The remaining four of us were a little puzzled because we had no ideas. What was certain is that we wanted to use node.js or YQL. We started installing node.js on our laptops and see what it can do. Somewhere along the way the idea came, a multi-player snake game which we called “Tequila Worms“. I had to make the UI because I had more expericence with JavaScript games. Initially I wanted to reuse the code base from my snake game. But there was a small problem, I didn’t have the original source code with me. On the other hand it was my first JavaScript game, so it wasn’t exactly “beautiful” written. At that point I decided to start from scratch using canvas.

I was very happy to work on an app without thinking at backwards compatibility.

At about 18:30 there was another talk by Douglas Crockford “The JSON Saga”. I saw this talk before on developer.yahoo.com so I thought is not going to be very exciting for me. But it turns out it was quite different. An interesting part was when one of the slides said “IE6 MUST DIE!”, a very good point, but then… “IE7 MUST DIE!”, then 8 and 9. At some point I was wondering why didn’t he simply write “IE MUST DIE!”.  The answer came on the next slide “IE10 MAY LIVE!”. IE10 is the only Microsoft browser that implements “ECMAScript 5: Strict Mode”.  The recorded talk can be found at: http://www.youtube.com/watch?v=NXiAKPTDXk.

After the talk I’ve asked Douglas Crockford to take a photo with me, one more reason for me to brag that I was to this event!

This talk was the last one until the end of the hackathon.

At about 19:30 it was the entertainment part, sorting algorithms on traditional romanian music:

After that was dinner and a very long night.

After several hours of intensive coding we made a visit to the games room, where waiting for us were: a XBOX,  a WII, a Ping-Pong table, Fuzzball table and a pool table. During the night we made serveral visits to the game room to relax and stretch after sitting too long on the purple bean bags.

Sometime after midnight the other team dropped the project because they got stuck in YUI, so only our team remained active.

After 3 am few colleagues began to fall asleep on the bean bags, but in my team sleep was not an option. To prevent me from sleeping I drank 2 or 3 RedBulls. The project was starting to take shape and I said to my self that I will not sleep before we have the first version running.

At about 5:30 am I blinked from a moment and felled asleep with my hands still on the keyboard, for about an hour. One of the most relaxing nap I ever took in my life.

In the morning a new espresso machine appeared to keep us alive for the remaining time, so we continued with new strength.

After getting to a working version it was more of a continuous playing with small brakes to fix the bugs that we found along the way. I think that it seemed fun enough that even Ted Drake came and had a game with us.

After 24h of hacking the end was announced and we had to go and register. I was going to present, I was overwhelmed by the moment. I took a number, set up my monitor and went to eat.

We has a little issue, the game was working fine using websockets over local network and we didn’t know how we were going to do the presentation. After some running around we managed to figure out the details but not the presentation. I realized I was in front of 300 people with no speech and with a game made literally over night. I finished very quickly and I can’t really remember what I said, the only things I could see was the spotlights in my eyes and I was so nervous that I thought I was going to faint. But I think everything turned out ok.

1.5h of presentations by 50 teams followed.

While the jury deliberated we went outside and had a brief conversation with Luke Smith, and a not so brief conversation with Reid Burke which during the night helped us with our project. We’ve started our conversation with Reid on node.js and ended with YUI and why is not very popular. I found out that Reid is only 22 years old and it’s been with Yahoo! for 3 years already. At some point we told Reid that we didn’t like YUI because it has such a different approach then jQuery, but he openly answered all of our questions explaining why they approach things this way. Maby if YUI would better highlight why there doing some things so different it would become a much popular framework.

During the awards Anil Patel (the event host) insisted that presenters should stay on the bean bags in front. And because the jury was getting late Anil told us some funny stories about what happend at other Yahoo! Open Hack events. And because the jury still wasn’t coming back from deliberation he sang us some Abba.

Winners were announced:

After the awards we found out why it was so important to sit on the bean bags, presenters would take the bean bags home!

The after-party followed, but we were to tired, so after smoking a cigarette and drinking a cup of wine we ended our trip at Yahoo Open Hack Day Europe 2011!

As a conclusion, the accommodations were almost perfect, no detail was left to chance. I overheard a discussions that they even prepared umbrellas in case the weather would turn bad.

Written by Claudiu Persoiu

24 May 2011 at 9:03 PM

Yahoo! Open Hack Europe 2011 at Bucharest!

without comments

Yahoo! Open Hack Europe 2011 will be held in Bucharest! Between 14-15 May we are the lucky Europeans to host this event.

At this event there are two types of tickets: Tech Talk and Hacker. Those who choose Tech Talk will attend seminars and awarding only, while those who choose Hacker will stay overnight to work on the project they’ve chosen.

Important figures from the Yahoo! staff will be present, so in short is an event that you must not miss!

Written by Claudiu Persoiu

21 April 2011 at 7:23 PM

Posted in Diverse

Tagged with ,

Scurta istorie a hackerilor

without comments

Written by Claudiu Persoiu

8 December 2008 at 9:48 PM

Posted in Diverse

Tagged with

Ce este un hacker?

without comments

To hack or not to hack, that is the question!

Toti am auzit de termen, fie din ziare, tv, carti sau prieteni, fie de la pustiul din bloc care te mai ajuta cu calculatorul cand ai probleme.

Marea majoritate traiesc cu certitudinea ca un hacker este un personaj negativ care nu vrea decat sa atace calculatoare din diverse motive. De fapt si cei care studiaza problemele de securitate fac acelasi lucru. Exista chiar si un fel de cod de conduita in acest sector, o data ce a fost descoperita o gaura de securitate intr-un sistem, hackerul ar trebui sa-l anunte pe cel care detine sistemul de vulnerabilitate inainte de a face publica descoperirea.

Chiar si statele dezvoltate isi construiesct o armata de astfel de hackeri pentru a exploata vulnerabilitatile oponentilor.

Orice studiu de securitate serios se bazeaza practic pe munca unor hackeri, lucru care il face pe cel care studiaza securitatea si implicit cauta vulnerabilitati un hacker.

Dar mai exista si alte feluri de hackeri, de fapt un hacker cauta solutii, studiaza probleme in amanunt pentru a gasi noi oportunitati si de ce nu, pentru a inova. Calculatorul Apple I produs de Steve Wozniak s-a nascut dintr-un club de hackeri care de fapt in loc sa descopere vulnerabilitati nu faceau decat sa… descopere. Multi au incercat sa creeze lucruri noi folosind unelte disponibile, incepand de la programare in limbaje low-level si unelte hardware, pana la limbaje de mackup.

Yahoo! a avut de curand Open Hack Day 2008, acest eveniment pune in evidenta importanta pe care o poate avea un hacker intr-o astfel de companie. Un astfel de eveniment poate oferi atat o oportunitate pentru hackeri de a intelege mai bine servicile Yahoo!, cat si o oportunitate interesanta pentru companie de a vedea perspectiva si nevoile comunitatii de hackeri (da, o comunitate de hackeri se naste de multe ori din nevoi).

Din aceste doua imagini diferite pentru un hacker s-au nascut si doua viziuni diferite, daca in industrie un hacker cauta solutii in presa acesta cauta probleme.

Pana la urma fiecare programator are tendinta sa fie un hacker, fiecare dintre noi cauta la un moment dat solutii pentru probleme care nu au fost solutionate inca sau nu prezinta o solutie optima pentru o anumita problema.

Sa nu urati hackeri, din munca lor suntem azi unde suntem, iar din munca celor de azi se va construi viitorul. Nu trebuie sa discreditati o intreaga comunitate pentru problemele aduse de o mica parte din ei.

Written by Claudiu Persoiu

28 September 2008 at 11:55 AM

Posted in Diverse

Tagged with