Archives for category: On Codes

I got stumbled upon ( again ) Akelos, another PHP framework, but this time my short attention span seems didn’t work :D

Yeah, it seems mature and stable enough, and maybe because i’m in process of learning RoR now, that Akelos’ claim of being “port of RoR in PHP languange” make more sense than before.

Why am i interested in Akelos ? There are several other PHP frameworks that claim to be “inspired by” or “ports of RoR” namely CakePHP, CodeIgniter ( inspired ones ) and PHP on Trax ( port ).

I’ve been using CodeIgniter for a while and like it so far, because it has great documentation, lightweight, and easy to extend, although as many other PHP frameworks, it tends to get hairy if the developer gets too excited or plain too old fashioned to adhere to MVC concept. the lack of automation and claim of being small, lightweight freeform MVC framework in CodeIgniter is likely the cause of such failure to enforce MVC separation and reuseability ( or DRY ). I don’t blame the creator, actually i like CI very much because it cuts a significant portion of my work on particular project, make everything so fast, and above all, fun.

After i tried Akelos however, i got more excited, because it has the same ease of use of CI, at least in terms of requirements, like it works in PHP4 and PHP5, the package is easy to install, through SVN and downloadable package, and self contained, it doesn’t get stranded to PEAR ( like PHP on Trax ). Personally i don’t like PEAR because i’ve encounter too much trouble setting up on many different kind of machine ( Windows, Linux, and now OS X ).

With the bonus of Rails like automation, like generator, migration, etc. which doesn’t currently exist in CI, Akelos should be fun to work with, after all , it is a port of Rails. So i think i will take a closer look at it, maybe it could become a good learning tool on Rails concepts. I know PHP for a long time , then it’s a bit hard to switch lane to Ruby, learning RoR using Akelos should be a logical way to gradually move to pure RoR world.

Mind you, I’m not into language / framework war, for me it’s just another language and another framework. I use them accordingly depending on my particular needs, so i don’t scrap one for another, but i simply put them in my personal toolbox to use any of them as required.

The reason i don’t pick CakePHP is because it’s a whole different kind of framework although it has many of good features of RoR ( automation with bake, ORM, etc ). PHP on Trax, hmm, PEAR, so i think i’ll pass. I pass on other PHP frameworks too because they are PHP5 only, which is not good for the moment since my servers are still running PHP4, although they have great features too.

So, Akelos should be good enough now, although I don’t think it will match RoR fame, but it will become a fresh breath of air on PHP world, particularly in this moment where PHP gets mocked as inferior than Ruby or Python ( or other languages by fact ). Other thing is I actually like the modest attitude of Bermi Ferrer, Akelos’ creator. DHH is just simply irritating, but i still respect him as a great programmer.

I started to learn Ruby, o yeah !!

why ? because i can, that’s why… okay, okay, because i want to be able to use that oh so great and almighty Ruby on Rails, brother !

Actually, many have advised that you just need a handful of Ruby basic to be able to use Rails, but i think that will be equivalent of having a ten thousands French word traveller dictionary and then fly to Paris.

The bigger picture is that i’m sick and tired of all those “mine is better than yours” attitude when it comes to programming language. I believe that a programming language is no different with natural language. You use it because you need to communicate and furthermore, get things done.period.

I only believe that one language could do specific purpose better than others, but i never believe that there is one ultimate, do-it-all language. I also have preferences, mostly because i need to get things done quickly using language i deem fit for the right job. Hey, why should i write a servlet if all i need is just a simple contact form and mailer ? spare 10 minutes of your busy time and use php, that will do fine.

There’s a saying : “Good programmer learn one new programming language every year”. There’s nothing more i could agree with. My first language was BASIC, the version for IBM PC-XT, then Pascal as in Turbo Pascal, then a little bit of Assembler, because i think that will be cool if i can directly control PC hardware using it, which i then drop because it brought me more headaches than fun, then a little bit of C/C++, javascript, then PHP, which i find useful to make a living… I learn a bit on some more exotic language, like Scheme, Haskell, and even Erlang, and … it’s like learning Latin, what the hell was i thinking … I learn and then use Java by force, because i have projects that require it, which is okay, at least i can create nice software for my phone, then came Python, by which then i also learn the beauty aspect of a programming language, and now came Ruby, which is even more beautiful, because it has strong resemblance and logic of natural language, namely English language, a human language, yay !!

No, I’m not praising Ruby, but the point is, every language has it’s own strength and weakness. And also depend on your habit and common sense on using them. Human has uncanny ability to adapt, while paradoxically make them averse to changes. Like hitting semicolon in Python and BASIC, or forgot that indentation is a must in Python, i think those are glitches commonly happen in natural human language, of course , syntax is more stringent in programming language, but you see the big picture.

I truly believe that programming language is like natural language, in a sense that every individual programmer has one language the know best, like native language, although they’re not necessarily like it, because that will be the earliest language they learn to understand the concept of programming. And then came another ( or several other languages ) they learn, and then like to use, because they find it easier to fit their needs, and make their good living nonetheless :)

I strongly encourage learning multiple programming language, just so we know that there’s no point on “mine i is better than yours” attitude. PHP tends to become a mess of spaghetti, we all know that, Perl is arcane and makes me feels old, Java is slow and resource hog, etc, etc… but also remember, PHP is easy and forgiving, Perl has short list of reserved functions, while having a huge repository of nifty modules ready to be used by anybody around the world. So, I suggest, go out and play, find out about lots more programming languages, from the cryptic one into the most elegant one, and you’ll see why becoming (programming) language neutral won’t make you less valuable from the rest of the world. It will only teach you to tap the best of each programming languages, and never the other way around.

AJAX is the current buzzword these days… no doubt about that. To learn to program AJAX, is like mall roaming teenagers trying to get the latest piece of accessories to make them look hip and cool… That is, as there is nothing really cool about the piece of stuff, but you will look cool wearing it because everybody will say so…

No different with AJAX, since there is nothing new in the technology, just good old Javascript plus some ingenuity on using dormant browser feature, then you get a whole new buzzword, which in turn, if you can do it well enough, will raise your self esteem among your fellow programmers, or maybe raise in salary or fee since now you can say “I can do AJAX too” to you boss or your client.

From user perpective, no one cares… all user see is that now they can click on your website and the information pops up quickly, without having to wait for the page to reload. What does it mean for them ? You may say, better user experience. But, be aware, user comes from all walk of life, meaning, they access your site using many different kind of browsers, devices, and don’t forget, many different levels of infrastructure capacity and capability.

Internet users still varies greatly these days, even with all broadband, wireless whatever technologies.. major portion of the world is still using dial up, yes it is true, and believe it or not, old OS like Win95 is still alive in many many places, meaning IE5 is still around ( yeah, bad enough to have IE around, let alone the old one )

I’m not exaggerating things here, because this is what happen in my country. I once had a shocked overseas client when I told him I had to switch to dial up connection because he broadband connection went down.

Ok, regarding the title above, in my opinion, a good developer should be aware of everything above mentioned. Developers rarely concern about accesibility, many of us simply trying to create “cool” stuff, create the next Facebook, or Google, or WhateverCoolToday sites, then after that wonders, why there’s only a few people visiting, let alone registering and become returning user ? When that day comes, look back at your codes, don’t look at marketing people, at least, recheck your codes before you throw flames at marketing :)

What does these have anything to do with AJAX ? AJAX is cool , and it provide better user experience isn’t it ? Hmmm… AJAX put more strain to the server than ever before. that’s one for a start. Back in the days, a hit means one user accessing one url, or one web page, if she stays for 10 minutes on the same page, doesn’t really matter because no request sent to server during that 10 minutes ( well sort of …). These days, take example of a page with autoupdating AJAX widget, when a user access it , read that page for the same 10 minutes, she wouldn’t even realize that during that 10 minutes of her visit, her browser has sent hundreds of request, AJAX request or XHR if you prefer geekier term. Put more variables into the situation, let’s say, her PC is a rather old Pentium 3 laptop, with bundled Windows2000 and yet to be upgraded IE5.5 … She connect to the internet using 50kbps residential shared broadband connection, on peak hour which only give her only a portion of the term “broadband”… chances are she won’t even stay for 10 minutes, but if she survived, then that will become a strain on her PC too.

Think about this when developing web application in general, not just when being cool developing AJAX. Good developer do test, meaning, not just testing for the functionality and reducing bugs, but also test in every condition possible. Remember, you develop for user, not just for your personal enjoyment ( but if that the case, then good for you, you may scrap all my blurb here ). In my experience, you can throw anything you want to the user, they will grab it instantly, but on the other hand, they are smart enough not to swallow everything, and when it happens, they simply move on and forget about your site entirely.

Other thing is mash ups and APIs… I personally like the concept of sharing with the world for the better, but I never understand how one can build a business out of somebody else’s application API. How realiable could it be for the user ? Fine if the API come from Yahoo, Google or the glorious Facebook, but what about so many more that provides API because they want their application to grow bigger, not because they think their application is usable, unique and people really demand API to get connected ? reliability is the main concern here. Just take example of pre Ajax mash ups, the banner exchange… nothing too smart about exchanging banner, but when a website has too many different affiliates, with different infrastructures, and different server loads, it will become hell for the user because pages will load with random and somewhat significant speed difference, and hell for the developer to figure out which affiliate link cause the problem. Things get worst when banner exchange start to use javascript, which is NOT threaded, therefore, it will be executed in blocking sequence, and once it stuck on one affiliate code, it will attemp to finish that block of code first before moving on to another block. If it stuck forever, you’ll get crashed browser, or simply half complete page staring at you.

Okay, no worry.. I do believe in progress, and I also believe that technology will solve it’s own problem, but in the mean time, there’s nothing wrong with becoming developer with conscience. A developer with good understanding on what user will need and use, rather than developing something too advanced and too sophisticated that will defeat it’s own usability.

I’ve been wondering for a while if I can do automatic subdomain using username, same as Wordpress MU does. Some thought come across and all leads to same point , the $base_url() variable.

What makes me a bit wary is that particular variable reside in config file, which suppose to be static. On the other hand, manipulating the variable in controller is easy but redundant. So what the heck…
There are three places to modify for this :

  1. DNS entry
  2. Apache vhost
  3. Codeigniter config.php

Life has been good to me since I have full control over those three, I have my own DNS server, and apache server, so if you are less fortunate than I am, do not hesitate to nag , beg and annoy your hosting company to do changes for you

DNS entry :

make sure you put wildcard entry :
mygreatsite.com. A 123.123.123.001
*.mygreatsite.com. A 123.123.123.001

Apache vhost :

We use separate vhost file for each domain, and include those files using Apache “Include” directive, to keep things tidy and avoid fiddling with main apache config.
<virtualhost>
ServerName mygreatsite.com
ServerAlias *.mygreatsite.com
ServerAdmin superduperadmin@superduperwebcompany.com
#RedirectMatch 301 (.*) http://mygreatsite.com$1
DocumentRoot /var/oi/keepcodeigniterhere
<directory>
Options Indexes FollowSymLinks MultiViews
</directory>
AllowOverride All
Order allow,deny
allow from all
</virtualhost>

the most important part is :
#RedirectMatch 301 (.*) http://mygreatsite.com$1
CodeIgniter config.php :

I test using this simple hack ( on the config.php ) :
$config['base_url'] = "http://".$_SERVER["HTTP_HOST"];

And wala !! I can test using whatever.mygreatsite.com and codeigniter still working as if there is nothing wrong with $base_url variable, therefore you can use any words ( hence, wildcard ) as subdomain prefix and apache will direct the request to the same codeigniter installation. Next step I will do is using username as subdomain, eliminating ugly url like
http://www.mygreatsite.com/someuser/profile
and make it nicer as in
http://someuser.mygreatsite.com/profile
Nice !!
Yeah I know I have to test rigorously to ensure nothing is broken with codeigniter ( and my application ) but at this moment I think it leads to the right direction.
I also do some search at CodeIgniter’s forum just to verify my method and I’ve found great reference :
http://codeigniter.com/forums/viewthread/51627/

For wildcard DNS, take a look at this guide by Wordpress creator :
http://photomatt.net/2003/10/10/wildcard-dns-and-sub-domains/

from those forum entry, I’ve made final modification to the config.php file :
$config['base_url'] = "http://".$_SERVER["HTTP_HOST"];
// provide easy to access variables for the rest of the application
$usernamehost = explode('.', $_SERVER['HTTP_HOST'], 2);
$config['tld_base_url'] = $usernamehost[1]; // contains "domain.com"
$config['user_base_url'] = $usernamehost[0]; // contains "sub"

Hopefully this will work as expected , and also useful to anybody who wants to achieve similar thing.

Just a twitch in my brain :

  1. know basic HTML… seriously :)
  2. have Firefox browser, the (most) standard compliant browser whatever that standard is ( actually i don’t really care about standard, it works for me as long it looks good on any browser ), always develop using this, then test on the rest of bunch, namely IE, Opera and Safari, and don’t forget your phone browser, which is more or less having the same base with Safari ( Webkit )
  3. have Firebug extension for Firefox, save a lot of trouble on debugging, CSS, Javascript, AJAX
  4. have a good text editor, not Notepad, use serious one designed for programmer like UltraEdit, Crimson ( Win ), TextMate ( Mac ), or vim, geany, bluefish ( Linux )
  5. can edit (X)HTML using number 4, not using brain-killing-WYSIWIG-tools like Dreamweaver, so that is why knowledge on number 1 is a must.
  6. know CSS. Yeah, sometime great design can be produced without table and image.
  7. know how to program Javascripts
  8. can program at least in one of popular server side language, namely Java, PHP, Python, ASP (ick..), ability to use frameworks also helps, just pick one, Ruby on Rails, CakePHP, CodeIgniter, Prado, Django, Turbogears, Pylon, and so on, and so on. Knowledge on SQL also mandatory if working with database.
  9. know how to put all those above together and produce good looking and usable website ( must be both not just pick one ), meaning, it must be clean, clear for user, optimized for viewing on any platform, even any device, through any bandwith… such a heavy undertaking eh.. oh yes, it must be clean from error messages and bulletproof from any possible hacks.
  10. have sex regularly , heheh, well at least once in a while… to clear up all those dirty xhtml, css tags and program errors from your brain… come on, no matter how cool a website you can produce , nobody really cares about who creates the good stuff. So get a life, have fun in real world, get a real good stuff for yourself.
  11. that’s it I think :)