It was the start of summer and Stephen was almost as excited about college junior Nathan's internship as Nathan was. Stephen’s company had a history of selecting new employees from their small group of fresh interns that started each summer and Nathan seemed like the right guy for the position.

To get his feet wet, Nathan would be first assigned to the SEO group where Stephen would be overseeing Nathan’s work. Though the SEO team was small when compared to the rest of the web development group, Nathan was in a position to make a big impact on driving traffic to the sites that Stephen’s company maintained and add a nice set of bulleted items to his resume or, if things worked out, a full time job after graduating from college.

On Nathan’s first day, Stephen and his manager carefully explained to him some of the problems faced by the company.

"We have millions of users, but the search engines don't know that. We show just enough information about each user publicly so that when you Google for this person, you can find their profile on our site. For this to be truly effective, however, we need a user directory the search engines can crawl."
"For each locale, just throw up a page listing all usernames in that locale alphabetically ordered and linked to their profiles." Stephen’s manager continued, "We serve pages in over a dozen languages, so just let standard libraries figure out what 'alphabetically' means.”
Stephen capped the conversation by explaining, “You don't need to worry about how it looks-- the crawlers won't care. This is really just to get you familiar with the codebase and the way we do things here before to get you ready for your real project."
Later, once Nathan got settled into his, Stephen began explaining some of the basics of their architecture, gave a refresher on SQL, being sure to highlight the use of the "ORDER BY" clause, and told Nathan to be sure to drop by if he needed anything.
The next day, Nathan spent the day browsing through code running in production, but found himself confused by the mixing of different paradigms. He found a potpourri of heavily object-oriented code and fancy UI libraries, to endless seas of HTML string concatenation and hard-coded FAQs. Stephen explained to Nathan about ongoing efforts to rewrite some of the poor code, majority of which was inherited from clients.  He offered to go into more detail about current best practices later that day, but Nathan, in his words, was “on top of this one”.
He knew what methods worked for him after several years in a well-known computer science program, and knew doing things his own way would continue to serve him well. He did have a 3.9 average after all.
After working through the weekend, Nathan proudly showed his results four days later.
$letters = range('A', 'Z');
$locale_arr = array('ca_es', 'cs_cz' , 'da_dk', 'de_de', 'en_gb', 'en_us', 'es_la', 'es_es', 'fr_ca', 'fr_fr', 'nl_nl', 'ja_jp', 'ru_ru', 'he_il',  'fa_ir');
foreach ($locale_arr as $locale) {
 $locale_str = substr($locale,0,3).strtoupper(substr($locale,3,2));
 exec("mkdir /user_dir/".$locale);
 $output_path = '/user_dir/'.$locale.'/'.$locale;
 $line = sprintf('mysql -e "SELECT * FROM users WHERE locale=\'%s\'" > %s &', $locale_str, $output_path);
 //open 26 files to write to (A to Z)
 foreach ($letters as $l) {
   $seperate_var_temp = 'handle'.$l;
   $$seperate_var_temp = fopen('/user_dir/'.$locale.'/'.$l, "w");
 $inp = fopen($output_path, "r");
 while($line = trim(fgets($inp))) {
   list($name, $locale) = explode("\t", $line);
   $line_output = $name."\t".$locale."\n";
   if (preg_match('/^a/i',$line)){
    } else if (preg_match('/^b/i',$line)){
    } else if (preg_match('/^c/i',$line)){
    } else if (preg_match('/^d/i',$line)){
    } else if (preg_match('/^e/i',$line)){
    } else if (preg_match('/^f/i',$line)){
    } else if (preg_match('/^g/i',$line)){
    } else if (preg_match('/^h/i',$line)){
    } else if (preg_match('/^i/i',$line)){
    } else if (preg_match('/^j/i',$line)){
   } else if (preg_match('/^k/i',$line)){
   } else if (preg_match('/^l/i',$line)){
   } else if (preg_match('/^m/i',$line)){
   } else if (preg_match('/^n/i',$line)){
   } else if (preg_match('/^o/i',$line)){
   } else if (preg_match('/^p/i',$line)){
   } else if (preg_match('/^q/i',$line)){
   } else if (preg_match('/^r/i',$line)){
   } else if (preg_match('/^s/i',$line)){
   } else if (preg_match('/^t/i',$line)){
   } else if (preg_match('/^u/i',$line)){
   } else if (preg_match('/^v/i',$line)){
   } else if (preg_match('/^w/i',$line)){
   } else if (preg_match('/^x/i',$line)){
   } else if (preg_match('/^y/i',$line)){
   } else
 //close the 26 files opened
 foreach ($letters as $l) {
   $seperate_var_temp = 'handle'.$l;
  foreach ($letters as $l) {
    $sorted_file_name = '/user_dir/'.$locale.'/'.$l;
    exec('sort '.$sorted_file_name.' > '.$sorted_file_name.'_sorted.txt');
    exec('rm /user_dir/'.$locale.'/'.$l);
 foreach ($letters as $l) {
   $fname = $l.'_sorted';
   $conn = get_db_conn();
   exec(sprintf('mysqlimport -h -u company_ceo --password=ceo_password users_%s %s', $locale_str, '/user_dir/'.$locale_str.'/'.$fname.'.txt'));

Several weeks later, despite Stephen’s best efforts, Nathan was still working on Stephen's requested improvements, his way, and Stephen could hardly wait for the summer to end.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!