Claudiu Persoiu

Blog-ul lui Claudiu Persoiu


Guide to motivating programmers OR How to provide coders with a real challenge

without comments

motivationIT is probably one of the most dynamic fields in the job market and people are a very important yet limited resource.

And yet people come and go quite often, and most of them are complaining about the lack of motivation.

This problem will end now with this simple guide for motivating programmers and not only them!

Programmers need challenging problems, they keep saying all the time that they need more challenges, don’t they?

Give your coder a true challenge! Make him get specifications from a client that doesn’t know what he wants, let him struggle, you could even try leaving him do this by himself, let him feel the adrenaline of a true challenge!

It must be noted that a programmer is nothing more than a repressed Project Manager, give him a chance to express!

However, you should not stop with that, because there is no greater challenge than to work on multiple assignments at the same time. A good idea for raising complexity is to offer him the chance to work on multiple projects in parallel. Give him the opportunity to have his mind busy with different things, diversity is always good, isn’t it?

A little secret for exploring diversity at its fullest is for him to have different roles on different projects, maybe have him alternate a project that requires management with one that requires maintenance. It’s a shame to not have enough diversity!

Is he writing a lot of code? You have to do something about it! When a programmer is focused working on something, keep in mind that he’s actually desperately crying for attention. You have to do something to break this vicious circle, it’s your duty as a manager to save him!

You have to find a way to interrupt him: try with a few meeting, they always help. If he is looking eager to get out of a meeting, it’s just a sign that he wants to get into the next one!

In time, you’ll see that the better a developer is at writing code, the more he’ll wish not to have time for it anymore. However, he’s not going to tell you this, or, even if he does, it’s because he really doesn’t know what he truly desires.

And eventually, if he likes to write code so much, maybe you should take it to the next level and get him to test it on his own. After all, if he wrote it, who would know better how to test it?
There is one more thing to mention in the context of a challenge. When a programmer is coming to an interview, he will always say “I want to learn new things”. How do you apply in real life this desire? Simple, you have to make him work on something that he doesn’t know anything about! This way you will present him with something that’s at the same time new and challenging. Is he a PHP programmer? Good for him, now give him a Java project! Is he a Java programmer? Nothing could be simpler, give him something to do in Objective-C! Maybe sometimes it will be hard to find new technologies the are completely unfamiliar to him, but a programmer’s happiness is not an easy thing to obtain!

Try not to fall in the trap of offering salaries that are correlated with the position he applied for. Don’t worry, the salary is confidential, nobody talks about it. Especially not when he recommends a friend, he will definitely not inquire about the salary that was offered to said friend, if confidential. It would be a lack of professional ethics to try to find out, you really don’t have to worry about it.

And speaking of interviews, maybe you think that hiring processes should lead to meaningful results and qualified candidates. You couldn’t be more wrong, because what do you truly need? Like I’ve said before: Diversity! Not long ago I’ve read an article about some chinese companies hiring beautiful women to make the work environment more enjoyable and stimulating. You have to always find ways to integrate the new tendencies, and if the only open positions that you have are for technical jobs, you have to work with what you have. Maybe you think hiring based on looks can be problematic sometimes, especially when the jobs are technical. In this cases you have to realise that motivation has to be designed at a large scale. Yes, maybe some teams will require more time to adapt to this kind of new team members, however if that person has done something worth mentioning in any way, it means you’ve done a great job!

Let’s not forget about trainings and conferences. When did you last talk with a programmer saying that he doesn’t want to go to trainings or specialised conferences?

Motivation has to be maintained like any other desire. There are two components to it: wishing for something, and not least, not getting the something that is desired. If you wish for something it’s because you don’t have it yet, right?

If you didn’t already understand, the solution is simple: don’t let him have the something that he wants, so that he will be perpetually motivated to work hard in order to get it. He wants a training? Organise the training then make sure you are sending there the persons that are the least interested in it. He will see that he has a chance, but it wasn’t his turn right now.

Maybe this will sometimes be a challenge for management, but with a lot of carefulness it can be made possible! Keep the desire alive!

Another advice in regards to trainings: to keep the desire alive it is useful to send him to trainings in which he isn’t interested, but in which somebody else is interested. This way you will always have employees interested in trainings and having trainings, and also motivated!

When he is working he shouldn’t be able to see the usefulness of his work, it is very important. If he will see it, how can he be motivated still? It’s like climbing a mountain, no climber is motivated to go on if he knows how high he already is. You must be careful not to let him know where he is standing: keep those statistics and progress reports well hidden, because if he gets to have a feeling of ending, of target reached, of goal achieved, how would it be a true challenge then?

And don’t forget to not show him trust, he must build it for himself. You should provide him with a target and then keep it just a target. Indeed, a target achieved provokes pleasure and the satisfaction of a job well done, but is that what you want to show? Think about it, each time you congratulate him for his work will he be more motivated? Why try to stimulate him to improve when you can stimulate him to reach a target that he can’t. Don’t show him you trust him, let him struggle, let him feel the challenge.

In Romania we have a saying: “the known road is the shortest”. Regardless, some try to automate rudimentary tasks. Basically they are trying to eliminate the known road. Actually, if you prevent him from automating processes you are helping him remain busy, to have a busy mind, and a busy mind is an active mind!

And, secondly, with this approach you are helping him maintain his work place. Maybe he doesn’t realise it, but he will lose his purpose when he will remove exactly the tasks which, eventually, he knew so well, because he made them so many times… Programmer or not, he mustn’t be replaced by a robot!

Thirdly, it’s the satisfaction you get of walking the known road – don’t let him divert from it, because, it’s so well known that it should be finished quickly enough.

And never forget that you must teach him the importance of management. He must see that you can help him, that you are the key to his success and happiness. To show this it is very important to trust yourself. Try to organise a party and don’t invite him. Nothing says more “I could’ve been there” than not being there.

Another way is to organise a business trip in an exotic location. Don’t worry, it’s not important to actually have something to do there. While you’re there, don’t forget to have fun, it is very important for him to know that you’re enjoying yourself. When it gets though, you have to remember that you’re not doing this for you, you are doing your best to have fun for his and his imagination’s benefit!

Maybe some suggestions will not work for everybody, but you have to combine as many of them as possible to have a real success and keep your programmers truly motivated!

Don’t try to identify this utopian world, because any resemblance with the daily reality is purely coincidental.

Written by Claudiu Persoiu

4 April 2016 at 9:39 PM

Posted in Diverse

Tagged with ,

PHP6, just another story… (PHP6 and the books)

without comments

It’s finally over, the war has ended. PHP7 was released, and PHP6 will remain only a legend, a story of the version that never was.

After a while I don’t think anybody expected it to be released anymore. Afterall, it’s been almost 10 years, out of the entire lifetime of 20 years for PHP.

But how can such a highly anticipated version never show up?

Let’s begin from the start, when, almost 10 years ago, PHP was becoming a “serious” language. After the PHP5 version, the object module was finally having specific visibility for methods and properties, objects were no longer copied, but sent by reference. These changes triggered a multitude of object oriented frameworks, which were now also targeting the enterprise environment, not only small websites.

In all this context there was a problem, internationalisation.

This is how PHP6 appeared, it should have used natively Unicode, more specifically UTF-16. This way everything would have been processed in a unique and international format.

The project was started and maintained by Andrei Zmievski. Maybe today not many people know much about Andrei, but 10 years ago he was very popular for projects like Smarty and PHP-GTK.

After a few years the project got stuck, and then PHP5.3 appeared. Even though it was bringing important changes, it wasn’t a major version because there was still hope that one day there will be a PHP6.

There were however some people full of hope! And even more, they were ready to cash in on this bright hope!

Either authors or editors, they knew one thing when it came to books (especially technical ones) that they have two properties: a target audience and a period of relevance.

Let’s analyse the results.

PHP_6_and_MySQL_5_for_Dynamic_Web_Sites_Visual_QuickPro_GuidePHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition) (Peachpit Press – 2008) – Larry Ullman

Larry wrote several books, including: “PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)” and of course “PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide”.
Coincidentally, I had the opportunity to flick through all three books, but not in chronological order, I just randomly started with “PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)”. What is interesting is the striking resemblance, basically a 6 was added to the title and the rest is almost the same.

In general, all books from Visual QuickPro Guide collection are targeting beginners, and from an edition to the next things don’t change too much, they are only adjusted.

Professional_PHP6_Wrox_Programmer_to_ProgrammerProfessional PHP6 (Wrox 2009) – Ed Lecky-Thompson, Steven D. Nowicki (Thomas Myer)

It’s interesting that in the cover image there are three authors, but on Amazon.com and on Wrox there are only two names, that’s why I wanted to single Thomas Myer out.

This makes me wonder if Thomas Myer purposely asked to be removed or were there other factors at play? It’s strange to have your name on the book but not in the author listing of the publisher’s website.

Not coincidentally there is also a “Professional PHP5” – Ed Lecky-Thompson, Heow Eide-Goodman, Steven D. Nowicki, Alec Cove.

PHP_6_MySQL_Programming_for_the_Absolute_BeginnerPHP 6/MySQL Programming for the Absolute Beginner (Cengage Learning PTR – 2008) – Andrew B. Harris

It’s truly a strange book, there isn’t a PHP5 equivalent, and even more, on the writter’s website there isn’t any other PHP book.

Could there be a reason for that? In Larry Ullman’s case it’s just another covered subject, additional audiences targeted, but in this case it’s just strange, a single author, a single PHP book for a ghost version, published in 2008.

PHP_6_Fast_and_Easy_Web_DevelopmentPHP 6 Fast and Easy Web Development (Cengage Learning PTR – 2008) – Matt Telles, Julie C. Meloni

It wasn’t very difficult to also find: “PHP Fast & Easy Web Development” – Julie C. Meloni.

What is strange about this book is that Matt Telles doesn’t have any other PHP books, even though he wrote some for Python, C# and C++.

Something tells me he was brought in just to adjust the original book for the new context. I thought it was just a personal supposition, but upon searching on Google I found he is also Technical Reviewer for “PHP 6/MySQL Programming for the Absolute Beginner (Cengage Learning PTR)”, book that I covered above.

Beginning_PHP_6_Apache_MySQL_6_Web_DevelopmentBeginning PHP 6, Apache, MySQL 6 Web Development (Wrox – 2009) – Timothy Boronczyk, Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz

The original book was obviously: “Beginning PHP, Apache, MySQL Web Development” – Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner.

Michael K. Glass and Gary Mailer got out and in their place Timothy Boronczyk went in.

PHP was a very fashionable language in that period, and PHP6 was very awaited.

But how can something like this be? How can there be some many books from important publishers for a programming language that never existed? The answer is simple: greed.

There are two possible explanations: either the author tried to seize the market with a new version, or the publisher wanted to force it, in the hope of coining the market. Probably the hope was that when PHP6 was coming out, they would have already have the books ready for shipping.

This was another reason for not to rename PHP NG version into PHP6, it would have meant that a PHP version would have come out with a series of books already published, and what’s more, they were published for several years already.

I bet that when the vote between PHP6 and PHP7 was happening there were some very hopeful editors.

And now I wish you all, a pleasant reading!

Written by Claudiu Persoiu

22 February 2016 at 9:11 PM

Posted in PHP

Tagged with ,

Yet another PHP 20 blog…

with 2 comments

PHP 20 party

20 years ago, Rasmus Lerdorf announced a new tool called PHP.

My first encounter with PHP was in 2004, eager to make my HTML pages more dynamic. Somebody recommended PHP because it was very easy to use.

Because the installation seemed pretty complicated, I’ve used PHP Triad. In a few minutes I was ready to begin my experiments and I was fascinated by the instant feedback.

Back then, I was a student and my courses were based on Pascal and C/C++. I didn’t like Pascal because it was already outdated and C had a very complicated memory management system and instead of concentrating on the logical thinking I had to focus on allocating resources.

This new language, to me, had a syntax similar to C, but without the headache of resource management. Eliminating this impediment, I got to develop my logical thinking and even to become a better overall programmer, not only in PHP.

In that period, PHP wasn’t considered by many a “serious” programming language, more like one for beginners. At one of my first interviews, the employer told me on a nagging tone: “PHP is a toy, join us and you’ll learn real programming and something serious, like FoxPro!”. That was one of the moments that made me decide to become a PHP programmer.

11 years later, I can still say that PHP is the language closest to my heart, and I probably wouldn’t have had a career as a programmer without it.

What was your first interaction with PHP?

Written by Claudiu Persoiu

8 July 2015 at 3:02 PM

Posted in PHP

Tagged with

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 , ,

PHP 5.6 awesomeness!

with 2 comments

The year has just started and a new PHP version is preparing for release. At the time when I’m writing this blog, it is in alpha 2. It can be downloaded from here: snaps.php.net.

There is a series of interesting features, but today I’ll approach only 3 of them: constant scalar expressions, variadic functions and arguments unpacking.

Constant scalar expressions

This first feature is also the only one that didn’t have an equivalent before this version. And, when I say equivalent, I mean only for classes.

Until now, constants defined using the keyword “const” didn’t allow any type of expression, only a scalar value could be used, ex:

const INT_CONST = 1;

const STRING_CONST = "string";

const HEREDOC_CONST = <<<'EOT'
nowdoc
EOT;

Of course, there is also the more interesting version, which allows setting constants with dynamic values:

define('DYN_CONST', $variable);

The bad part is that this type of constants are not available for a class, because for a class only const can be used.

This means that now we can use:

const ONE = 1;
const TWO = ONE * 2;
const STR = "string of one and two :" . ONE . TWO;

And if it’s not enough, there is always:

define('FLAG', true);

const EXP = FLAG ? ONE : TWO;

Basically, we can set dynamically a value for a class constant! For instance, you can set like this in a constant the environment type for the user, dev or prod.

Variadic functions

This is the feature that I like the most, even though there is an equivalent for it in the older versions.

Currently, if you want to create a function with a variable number of parameters, you can:

function variableParameters () {
     $params = func_get_args();
     foreach ($params as $parameter) {
          echo $parameter . PHP_EOL;
     }
}

variableParameters(1);
variableParameters(1, 2);
variableParameters(1, 2, 3);

There are several problems, more or less obvious, with an approach like this:
1. From the function signature it is not clear that it accepts more parameters, on the contrary, it seems that it doesn’t take any;
2. func_get_args can be called anywhere in the function. If it’s on the first line, the purpose will be obvious, if it’s on line 20, it’s hard to spot and may generate confusion.

An alternative is to add a number of parameters, but this is not a good indication of the varying behavior.

And here is the new approach:

function variableParameters (...$params) {
     foreach ($params as $parameter) {
          echo $parameter . PHP_EOL;
     }
}

In this new version, it’s clear what is happening with the function parameters. You don’t have to figure out if and how many parameters the function can take, it is clear that the number varies!

Usually, when I’m looking for a function, I look for the definition in the IDE before checking out the documentation, especially when there is little or no documentation.

Arguments unpacking

The problem that is approached here is: there is a function with multiple parameters and they are sent in a dynamic fashion.

As I was saying previously, there are alternative ways to solve this problem. Let’s use the function from the previous example:

function variableParameters () {
     $params = func_get_args();
     foreach ($params as $parameter) {
          echo $parameter . PHP_EOL;
     }
}

And let’s say there is a variable number of parameters, moreover they are stored in an array. We don’t have a lot of options to pass them:

$params = ['param1', 'param2', 'param3'];

call_user_func_array("variableParameters", $params);

The result will be:

param1
param2
param3

In PHP 5.6 we can use those 3 points, similarly to the way they were used in the example from “Variadic functions”, but the other way around. Instead of the parameters that are received by the functions, they are the parameters being sent to it:

variadicParameters(...$params);

Maybe for this type of example it is not very clear, but if there is a fixed number of parameters for the function and a fixed number of parameters that are sent:

function twoParams($a, $b) {
     echo $a . $b . PHP_EOL;
}
$params = ["Hello", "PHP 5.6!"];

twoParams(...$params);

Even though it’s not something that couldn’t be done in the previous versions, now it’s more elegant.

And to conclude, the two examples:

function variableParameters (...$params) {
     foreach ($params as $parameter) {
          echo $parameter . PHP_EOL;
     }
}

variableParamerers(...["cool", "parameter", "unpacking"]);

I think with these small changes, PHP is making the transition from “the PHP way” to “the best way”, taking from other languages.

Written by Claudiu Persoiu

22 February 2014 at 10:17 PM

Posted in PHP

Tagged with ,

Nope PHP 6 is not here… but how about 2013?

without comments

This is a retrospective of the year that has just ended.

In case anybody is still wandering, no, PHP 6 didn’t come out and it will probably not come out any time soon.

Why is it relevant? Since I started this blog, at the end of each year I had a post related to PHP 6 and the fact that it wasn’t released. In 2008 it was a popular question, but nobody is wondering  about that anymore, and so I will close this subject now. Let’s return to the year that has just ended.

Close to the middle of the year, the version PHP 5.5 was released, bringing features like: finally , generators and many other enhancements.

Like in 5.4, these are not defining features for the language. In this new version, there are functionalities that can be easily replaced, but if present, they are welcome.

Even though PHP is proving very dynamic lately, I think this year the main keywords were HTML5 and JavaScript.

HTML5 is seeing a lot of improvements and older components begin to have more momentum. The companies are beginning to invest in games that work in the browser using WebGL. Even older games are getting ported to the platform, using technologies like asm.js.

And, because I’ve brought games into the subject, it seems very interesting to me how only 5-7 years ago the games built with JavaScript were relatively simplistic, and now they can be compared with the ones from PCs and consoles.

I think the web revolution, which many were expecting, is taking shape. Finally the Web is a platform in the true meaning and JavaScript a language truly appreciated.

The success is due to all sides, it is not only about ECMA or only about browser manufactures, now it is truly dynamic. The Web revolution is in full blow!

When it comes to backend, the spotlight was on Node.js. It is becoming an important player on the market. New frameworks have appeared  and it isn’t a platform mainly used by hackers eager to explore new technologies anymore, but also by large companies, like PayPal, LinkedIn and Yahoo, adding a vote of confidence to it. I think Node.js is finding its place and a niche in the market, and, as a JavaScript fan, I can only be happy.

An advantage of Node.js is that you don’t have to take into consideration different JavaScript versions, like in the browser. It allows the use of the latest features from ECMA freely, an environment where you can develop JavaScript with not headaches.

Technically speaking, it was a very interesting year for web development.

Finally, I want to wish you all an extraordinary 2014!

Written by Claudiu Persoiu

19 January 2014 at 11:10 PM

Posted in Diverse

Tagged with , , ,

The epic code from the movies

without comments

In movies where hackers appear, source code appears flowing in rivers on the screen. Looks important, seems like there is a computer genius that is preparing to revolutionaries something.

Ever wandered what that epic code from the movie is? John Graham-Cumming has done a collection of movies and the source code used in them: http://moviecode.tumblr.com/.

Written by Claudiu Persoiu

5 January 2014 at 12:07 PM

Posted in Diverse

Appcelerator Titanium – few impressions

without comments

Note: Titanium and PhoneGap are a couple of platforms for developing hybrid applications for mobile. These platforms are not written in the programming language that is native to the phone, but they can be distributed on a verity of mobile platforms.

Recently I’ve published on Github the newest and most extraordinary quizzing platform, named Just-Quizzing. I’ve build it for personal use, but because a few colleagues found it useful, I made it public.

In the initial version, for publishing the application to my Android phone, I used SL4A. I needed a way to use the application when I was on the move and didn’t have Internet access. Unfortunately it didn’t have automatic update for the quizzes. I’ve hoped that with time SL4A will have a clearer path, but the platform lost its initial momentum and I decided to write a mobile app.

I had to choose between PhoneGap and Titanium. In the past I’ve used PhoneGap because the app size was too big in Titanium, but I wanted to give it another go. In 2011, when I first wrote about Titanium, the initial app size was about 4M. Today it doesn’t seem that big, even though it isn’t small.

The perspective will be mostly about Android, even though the app was built to work also on iPhone.

I used SDK 3.1.3, without the Alloy framework.

Alloy has it’s own learning curb and I wanted to avoid it. The prupose of the application was to be a portable version for the quizzes from the server and I didn’t want to make a big time investment.

The total development time was a little more than a week.

First impression

Things don’t work as you expect them to, there isn’t a lot of flexibility. From the total allocated time, more then a quarter I was trying to do a “flyout menu”, like in applications such as: Facebook, Google Plus and Youtube. It was a total disaster! The only options that seemed to work were using an external module or using Alloy widgets.

It seems like when converting relative coordinates, where the user touched the current element, to the general coordinates on the screen there is a big discrepancy and it is impossible to do a sliding menu effect in a decent manner. In the end I totally abandoned this effect.

The speed is not that good when it comes to rendering elements. To be honest, I was expecting a better speed. There are some tricks that help, like pre-rendering the views before displaying them, but for this you must guess what the user will do next, which is not always possible.

Another thing that bothered me was that when the menu button is pressed on Android you can’t take a particular action, let’s say open the side menu that I’ve mentioned before. In PhoneGap for instance, no menu is opened, it must be built-using HTML from the ground up.

When Titanium came out, they were stating that you could develop once and distribute to multiple platforms. Now I was surprised to find that the approach had changed. In the Kitchen Sink, the application that showcases the features of the platform, each platform type initializes the application in it’s own file. One of the reasons is that the design is done dynamically if you are not using Alloy, not trough layout files.

One of the first things that I tried with Titanium was to see the size of a “Hello World” app. Packed, the application has about 8.5M, installed on the phone, it takes up about 16M. I don’t know what you think about that, but for me it is a lot! What is strange is that my final app occupies about 8.4M packed and installed about 16M, almost identical to the original application. The reason is simple, the images replaced by me are a few kb smaller, resulting in an application a little smaller than the one that I started with.

Why does a Titanium application take up so much space?

I had to do some searching before finding the answer. In 2011, when I first tried to research, I only found that all the libraries, needed or not, are packed inside and for this reason it takes up so much space. This wasn’t the cause! Meanwhile, I found the real reason. An application runs a “bridge” between Android and JavaScript. The source code is not “compiled”, as was the initial belief, but just interpreted.

The JavaScript code is interpreted using one of the available engines in the app (V8 and Rhino) and it calls other components that build the native graphing elements.

The issue is with the engines. They are quite big and are packed in every application. And, as if they weren’t large enough, there are 3 of them, each with its’ own purpose:

  • V8 – for newer Android version (after Gingerbread 2.3);
  • Rhino – for older Android versions (before Gingerbread 2.3);
  • x86 – for Intel processors.

These 3 engines occupy a total of 19M, unpacked on my computer. Thus, without eliminating some of them, we can’t get the app size to decrease.

One way Appcelerator is trying to tackle this size issue is to give up Rhino, breaking this way compatibility with older Android versions.

Community

There is a very active community. On the forums and Q/A platforms it’s full of questions and answers! I must admit that I was impressed in this aspect. Some questions are relatively old, even from 3 years ago.

Learning curb

For a week and almost a half, out of which almost a quarter I searched how to do a view moving effect, which in the end didn’t work, I must say it went pretty fast!

I must admit, I’ve played with it 3-4 years ago for a few days and I remembered a few things, like elements of type window, view and label.

The fact that I was able to find answers fast on questions about Stackoverflow, gathered in a few years, but also that the documentation is pretty well organized, helped a lot.

Also on Youtube there are some useful tutorials.

Development environment

In the first versions there wasn’t an IDE, the applications were written with an editor of choice, then packaged and tested using the platform.

Now there is an IDE based on Eclipse. The name is Titanium Studio. It has a pretty nice autocomplete, which helps in a lot of cases. It also has some drawbacks, like in my case sometimes the syntax highlight didn’t work, without any clue were the problem was. Also, project management seems a little strange and it had some issues with import and export of the projects.

There isn’t a default visual tool for editing elements in the page. Both Xcode and ADT allow for editing elements with drag & drop. It turns out there are tools for this, but they are not free.

Emulators are not very configurable. The good part is that you don’t have to worry, you select the operating system and display type and Titanium will automatically configure an emulator. The bad part is that I might wish for a clearer resource management.

Another disadvantage is that sometimes the application will crash before the emulator starts and if you try again it will try to start a new emulator without any luck, case in which the emulator has to be closed. Run Project clean and try again, careful not to miss the moment when the screen can be unlocked, or the scenario will repeat.

For iPhone logs do not work when it comes to OS X Mavericks.

Good parts

It is easy to learn.

The documentation is well done and where something is not clear, surely somebody asked the question before.

There is a fairly large community.

The IDE is easy to use.

It’s easy to see what is possible to achieve with the Kitchen Sink app.

The app doesn’t look like a web page in a WebView!

Bad parts

The app size is quite big (16M on the phone).

The graphical elements are only a subset of the platform.

It isn’t very fast, because the code is interpreted and not compiled, to be able to interact directly with the OS.

There isn’t a visual editor.

There are some issues on integration with emulators, both for Android and iPhone.

Conclusion

If you are a JavaScript connoisseur and you need an application fast and also want to have native graphical elements, then probably Titanium is for you.

If you want performance, probably you need to look for something else.

I don’t have enough experience with the Android SDK to be able to build this application in the timeframe I had available, this was my compromise.

To be honest, I’m not sure wether PhoneGap was a better option or not, speaking for my case. Today there are a lot of JavaScript libraries out there built especially to emulate native graphical elements into a PhoneGap application. The difference is not necessarily visible and, in the end, maybe sometimes the app doesn’t really have to look like a standard app, maybe a completely different interface is more appropriate.

Written by Claudiu Persoiu

24 December 2013 at 1:13 PM

Posted in JavaScript

Tagged with , ,

Building a new generation of programmers in a consumers society

without comments

Motivated by Rober Martin’s article, Hoards Of Novices, I’ve decided to write an article on a similar subject.

I do not want to write about the need for employers to hire juniors, but about why these juniors are not up to the expectations and, in the end, what can be done to be better prepared.

The software market is continuously expanding. Software is the way we command a computer what to do. Today, devices around us have processors, software and applications, from phones, watches, TVs and up to washing machines and refrigerators. All these devices need programms and programmers to develop applications for them.

With this premises, we reach the Software crisis. It was concluded that we need to build software faster in order to solve this crisis. This was a popular subject in the ’60s, but in time it has become less important.

To solve this problem, high level languages and frameworks were built. High level languages made development and maintenance of an application much easier. This way, programmers are getting very far from the “metal” of the actual hardware, working with concepts much easier to deal with.

In a world of high level languages (Java, C#, PHP, Python, JavaScript etc.) it is much easier and faster to create an application.

Yet, although developing an application is becoming easier, the quality of the developers is falling.

A consumer society

We need school for a better job.

Because the need for studies is a general need, the school itself is diluting. The educational principles haven’t had significant changes since education became available to everybody. The result of the learning process is the exam, in order to determine the level of knowledge. And even more, a mediocre result allows us to move forward, without prove that the required base is present.

Moving to the next level is done with a partial evaluation, you don’t have to know 100% of the information, just 50-60%. It is not exactly clear if there are important notions in the remaining 40-50%.

This educational problem is more or less a general problem and there are few those who try different approaches.

In general, I don’t consider school a defining system for determining the knowledge, especially today, when we have access to such a large volume of alternatives for it.

When students finish school, they don’t have all the required knowledge to actually work in the industry, which is not abnormal. School must offer a general basis. For instance, during my higher education I can remember at least 8-9 programming languages that we studied. There were actually more, but I didn’t keep a detailed evidence of them. It is clear that you can’t possibly know all these programming languages in order to become productive using them. On the other hand, you have an idea on how to approach them, which may help you to find the one you’ll like to study in thoroughness.

That’s the key, to study in thoroughness! For this we each have our approach, here you can find your own way, either courses, books, practical projects or all of them. By thoroughly studying a subject, the employers will not only accept you, but they will hunt you!

Often, the passion will totally replace the studies from school. I’ve met a lot of people which, even though they haven’t studied informatics in school, they are now professionals in it.

The good part is that a lot of people are studying from pleasure and I advise anyone who is reading these lines to search for pleasure in what they do. This is the best motivation.

Alternative education in a consumer society

Because the traditional learning techniques are no exactly sufficient, let’s talk about a few alternative methods:

  • books
  • courses
  • tutorials
  • articles/blogs

Books

Traditionally books are the best source of information (at least until the Internet became available). But there is no guaranty for the quality!

About 8-9 years ago I was trying to buy a JavaScript book. The selection wasn’t very big and so I tried to analyze each one.

In the end I was disappointed with my choice, because instead of teaching me JavaScript, the book was teaching how to make special effects on the page (very popular in that period).

In my particular case, I found the answer much later in a presentation by Douglas Crockford. He said that most JavaScript books are like that and he was recommending a single book, beside the book written by him, JavaScript: The Definitive Guide.

The reason is very simple, people tend to be more drawn by books that promise to teach a language or technology in a limited number of lessons or days. We want everything now, but studying takes time, you must understand the notions, not just a fast overview.

Generally, to determine the quality of a book you should look for reviews. These days it is very easy, I prefer Amazon.com and not only. This way you can determine if it is what you are looking for.

Sometimes a faster approach is useful, especially if you don’t have any previous experience on the subject, but generally this doesn’t offer a general perspective, only a gentile introduction.

Courses

There are a lot of courses, both in-class and on-line. Just like for the books, it is hard to determine the quality of the course.

Courses promise a lot, but a lot of the times they don’t treat the subjects in detail and in the end, even though you have the impression that you have learned a lot, when it comes to practice you realize that any variation from the course material is very difficult.

Just like for books, references are very important! Unfortunately, there aren’t as many reviews for course as there are for books.

Try to see what subjects the course is teaching and the detail of the approach. Sometimes, you can find more easily a reference for the teacher than for the course.

Tutorials

Especially on the Internet, there are a lot of tutorials that promise to teach a certain domain, but they only teach you how to create their example. In the end you can only create small variations of the initial example. Often, the creator of the tutorial has the best intentions, but it is hard to transfer information like this.

For the free ones it is very easy to determine if the approach is the right one for you and for your needs. Try to watch a few episodes and in the end see how much you’ve understood on how that particular component is working. If you can only replicate, maybe you need to search a little more.

The good part is that there are generally a lot of them to choose from. For instance, for a programming language you can first check the official reference to see what you should learn about, then in the tutorial you can see how many of the points from the reference were approached.

For the commercial ones it is a bit harder, because often you just have a small introspective preview, insufficient to form an opinion. For those particular cases you should search for reviews.

Blogs and articles

The good part here is that the time investment is relatively small. It is simpler to get a general idea.

The disadvantage is that some of the articles don’t update with time. You must make sure that the examples work on the version that you are using. From my own experience I can say that keeping an article up to date is hard an takes a lot of time. For instance some of the articles on this blog that still attract visitors are written a few years back and if I don’t use that particular technology anymore, I’m tempted not to keep them up to date.

How to learn better

Search for references and reviews for the materials that will require an investment in time and/or money: books, courses or tutorials.

When you’ve settled on a subject, try to see what materials others recommend. The Internet is full of materials of different levels of difficulty.

When you fell that you’ve mastered a subject, test your knowledge. Build an app, follow the subject on Q/A platforms or even write a tutorial for the others. You tend to understand much better a subject when you have to describe it to others.

Practice! It is very important to practice what you learn or you’ll forget much easier than you think. Contribute to open-source projects, try to do personal projects or try to adapt projects created by somebody else to your needs. Github is a very good tool for finding and publishing projects.

It is a bit harder at the beginning to understand somebody else’s code, but in the industry it is mandatory in order to be able to collaborate with others.

Learn new things all the time. Technology is changing, and so is the perspective over it. For instance, AJAX appeared in the late “90’s, but the perspective over it and how it can be used changed dramatically over the next few years, even though the technology itself didn’t change a lot during that time. The same for JavaScript, even though it appeared in the “90’s, only after 2000 it began to be considered an useful tool, previously it was mainly used for special effects on the page.

For a while, PHP was considered useful only for small projects. Today it is the language of choice for giants of the internet, like Facebook and Yahoo!. Along with the popularity, the best practices on the language itself changed for a better scalability and performance.

Conclusion

The educational system doesn’t offer the performance that employers are looking for. This creates a discrepancy between the expectations of the employers and those of the graduates, and this not restricted to informatics.

Unfortunately, the alternative materials sometimes also promise unrealistic things. Some study technologies and programming languages for months, while others promise results after only days or even hours.

Fortunately, we are living in an era dominated by information, and we can find not only materials, but also opinions about them.

Through better training, the changes of finding a job are rising considerably, resulting in satisfaction on both sides.

Written by Claudiu Persoiu

17 December 2013 at 11:18 PM

Posted in Diverse