Blog of Leonid Mamchenkov

You just stepped in a pile of posts.

Entries Tagged ‘software development’

Perl vs. PHP : variable scoping

I’ve mentioned quite a few times that I am a big fan of Perl programming languge.  However, most of my programming time these days is spent in PHP.  The languages are often similar, with PHP having its roots in Perl, and Perl being such a influence in the world of programming languages.  This similarity is often very helpful.  However there are a few difference, some of which are obvious and others are not.

One such difference that I came up recently (in someone else’s code though), was about variable scoping.  Consider an example in Perl:

#!/usr/bin/perl -w
use strict;
my @values = qw(foo bar hello world);
foreach my $value (@values) {
    print "Inside loop value = $value\n";
}
print "Outside loop value = $value\n";

The above script will generate a compilation error due to undefined variable $value.  The one outside the loop.

A very similar code in PHP though:

#!/usr/bin/php
<?php
$values = array('foo','bar','hello','world');
foreach ($values as $value) {
    print "Inside loop value = $value\n";
}
print "Outside loop value = $value\n";
?>

Will output the following:

Inside loop value = foo
Inside loop value = bar
Inside loop value = hello
Inside loop value = world
Outside loop value = world

In Perl, variable $value is scoped inside the loop.  Once the execution is out of the loop, there is no such thing as $value anymore, hence the compilation error (due to the use of strict and warnings).  In PHP, $value is in global scope, so the last value “world” is carried further down the road.  In case you reuse variable names in different places of your program, counting on scope to be different, you might get some really interesting and totally unexpected results.  And they won’t be too easy to track down too.  Be warned.

Migrating MS Dynamics CRM to SugarCRM

I’ve been a bit quiet for the last couple of month.  That’s because I was leading an ambicious project at my new job – migration of a Microsoft Dynamics CRM version 3 to SugarCRM Community Edition version 5.0.0.  There were only three people involved, non of us could afford to work full time on the project, and we only had three weeks to do it.

Read on for a story on why it took us longer, how we did, and if it was a success at all.

[Read the rest of this entry...]

Google Profile coming up

In my recent post about Google Reader and Google Talk integration I mentioned that it would be nice to have a possibility to control friends’ names and pictures.  Similar to the way I can do so in Gmail.  Having things a bit more centralized would be nice.

Obviously, Google realizes that.  They are some of the smartest people put together after all. Well, it looks like we’ll have something centralized in the near future.  Web Worker Daily runs a post about Google Profile.  Good news.

And while I was going through that stuff, I had a thought (yes, again).  Google must have some really nice tools for its developers. Usually, companies try to maximize the utilization of available resources, boost code reuse, and minimize time spent on re-implementing things.  Google shown a few decentralized bits over time.  Like this contact management issue, for example.  That probably means that creating something like Google Profile (simple, but very scalable application) has been made extremely easy.  It’s like it is easy to make one rather than to decide if one is really needed and what are the alternatives and how to use those alternatives. That, or they have some a weak approach to code reuse – something that I find hard to believe.  Either way, it’s interesting…