Posts tagged website
Posted using ShareThis
Firstly, as you can see this is my first post made as a direct result of using the ShareThis bookmarklet, which is pretty neat as it actually worked
Secondly and more importantly, I wanted to flag this up on my blog as it's something that quite often gets missed in PHP which is actually a very powerful tool.
As the author of the post above mentions, array_map() can be a useful function when sanitizing user data, but it has so many more uses too when dealing with the transformation of a data-set.
Basically a call such as $new_data = array_map('process_data', $old_data); will allow you to transform each element in the $old_data array to a new element in the $new_data array via the function called process_data.
What's more you can manipulate multiple data-sets in this way too by specifying multiple arrays, so long as process_data() can take in the arguments.
For example lets say we have process_data($item1, $item2, $item3) which manipulates $item1, $item2, $item3 to produce a single result.
If we need to perform this calculation on a bulk set of data we can do
$new_data = array_map('process_data', $array_of_item1, $array_of_item2, $array_of_item3);
I still see people performing these transformations, calculations, whatever, using for, foreach and while loops which can be prone to failure under certain conditions, and are probably less efficient code than simply making this call.
So why don't more people use it?Â I don't know, but maybe this post will help raise awareness!
refactormycode.com is a fledgling website setup as a project by French CanadianÂ Ruby Developer Marc-AndrÃ© Cournoyer and basically it's like a coding forum without the usual forum junk, style and obfuscation of content (forums for me are always a pain to use because of the tiers of information you have to go through).
It's a great looking website covering all the current major programming languages (at least when thinking of the web) and the idea behind it, though simple, seems to work really well.
Basically, you have some code that works, but you want to make it better, more efficient, or just tidier. So, you post your code sample and other people suggest changes. It's kind of like yahoo answers for developers or the comments foot of the PHP manual.
The code to be refactored, so far in the PHP section at least, has been of a reasonable standard i.e. that of at least intermediate developers, which is great as these services can tend to get flooded by newbies who don't know their $i++ from their ++$i :p and rapidly lose interest for me.
So far there are only a few PHP samples on there to comment on but I think, as the site begins to grow, there will be a wealth of well developed and critiqued code that serves as good examples or directly useable functionality.
So far I can't really fault it, other than making the "Best" link clearer by calling it "Best Refactorors"Â or something similar, and providing some closed, or accepted answer(s) type functionality to stop a thread getting out of hand (it could be that this exists already but I just haven't seen it yet). Maybe even an option to download each refactoring as a plain text file could be useful.
So, to round up, as you can probably tell, I love this site and you can see my standing in the community in the foot of this page! Keep up the great work Marc and I hope your site develops in the way it deserves and gets the recognition it should!
According to the paper today some experiments were done at Chicago university to see how people describe things without words.
This was more in the sense of gesticulating/sign language, so speakers of different languages trying to convey stuff to each other, or if you can't speak even in your native language, how do you get your point across.
Results were that all languages do it in a similar way i.e. description of the subject then object then verb - I suppose an example could be Fire -> wood -> light
If this is the case then it's more of an underlying human behaviour as opposed to a language or culture specific trait.
I don't know if a similar argument may also apply to conveying information on a web page, but it's an interesting thought to bare in mind, since it's still interactive non-verbal communication (in contrast to a magazine or a book for example)