Mental model of languages

March 11, 2014

“The better decision maker has at his/her disposal repertoires of possible actions; checklists of things to think about before he acts; and he has mechanisms in his mind to evoke these, and bring these to his conscious attention when the situations for decision arise.” 
(Herbert Simon, Nobel Laureate)

C’s mental model is of blocks of memory. C makes you go bare metal – there is a block of memory address blocks underneath!

Python’s underlying mental model is of dicts. Almost everything is a dict or a dict with superpowers!

Erlang’s mental model is of processes. Everything is around handling these processes, monitoring them, how they behave.

LISP’s mental model is of Lists. Everything is a list – function definition, function invocation, data … everything IS A list!

PHP makes you think in terms of HTML output (just kidding).

There is a line I remember – A language that does not fundamentally affect the way you think is not worth learning. Hmmm… time to do some serious work in these languages?

Language vs VM Wars!

Rant follows

Erlang has a weird syntax but again not that far away from being an acquired taste. Python was weird when I started. So was Perl and PHP not so much since. C, C++, Java are all the normal ‘looking’ languages.

These days when I keep coding in Python or PHP, I keep missing the enforced standards of Erlang…

However all of this goes for a toss when I start looking at long term hiring and building a team that can work in Erlang for the long term. And then when I saw Elixir it was neat epiphany. Will there be a time when we will move away from languages and to the Language Virtual Machines.

Now undoubtedly having immutable values gives a huge power to having a pauseless GC and the BEAM is probably better for it. Had the syntax been more “normal” looking, Erlang has many many ideas that definitely need to be heard and learnt by all. It is sad that Erlang does not have the batteries included approach of other languages (I am looking at you Python), but I think where infrastructure and message architecture is involved Erlang is the best bet for now. Except when a class or a struct is involved it is very rare that we try to reuse a variable for more than one purposes. So with some programmer discipline we can ensure that a variable is never used more than once. In that case can the GC of non-Erlang languages be more efficient?

There are so many ifs and buts but it would be nice to see a solid language succeed.

cloud computing is …

August 30, 2013

Cloud is …

truecaller is a social network in an app

August 23, 2013

Let me share a small story …

It was my birthday yesterday (yes, yes, yet another year down the hill…). Anyways so dinner was had with all my folks. Midway my cousin started prank calling my wife. Of course me and my brother being privy to the whole mischief decided to play along with the charade. Well… and the charade kept playing. In the meantime, my cousin installed a new app on my wife’s phone – viz truecaller. Curious about the app we started asking more questions, he told us that it was an app which would give the name of the person calling you even if the number was not present on your phone’s address book. He had my interest then and there.

Playing around with truecaller by searching through the application some things became very clear

  1. The phone number look-up was happening on the true caller server and not as a peer to peer search as earlier assumed by my cousin
  2. The application clearly was uploading the complete list of contacts from our phone to the true caller server which was not completely apparent from the application permissions
  3. Clearly, a lot of people either do not understand that this is the case or just do not care about privacy as long as the name lookup works perfectly

Once we started playing around with truecaller some beautiful insights started emerging…

But not once does truecaller state that its value is the above. truecaller’s simple selling point is “know who your caller is or find someone you know”. Now culturally, this is something that happens quite often in India that we first determine the caller and only then take the call. And truecaller fits this mindset like a glove.

In spite of the many buzz-words it covers, truecaller never for once succumbs to the buzz and sells itself as “X of Y”. Quite simply the app identifies itself by the user’s needs and not by the capabilities. Truly cutting the crap and bringing down the value to the bare minimum I think is truecaller’s best selling point at this point in time. My bow to the team for truly truly getting down to simplifying the message to the users.

Just thinking deeper on the different value that truecaller can reap from itself just on a few adjacency moves had me truly appreciate the full scale of the app’s accomplishment.

1. Fully connected and open Social Network

India had its telecom revolution in the 2000 but what we are seeing now is the beginning of a truly mobile revolution spearheaded by marginal costs of software, apps, operating systems and the Chinese manufactured hardware. In India where the penetration of the global social networks (FB, G+) is not at a level where they can cover the complete social spectrum, truecaller is truly riding on the Android-driven mobile revolution and is now almost a default must-have app on Android phones (WhatsApp being the other must-have app). If the privacy concerns are set aside for a moment, quite clearly truecaller now clearly has my phone number, list of all people whom I met or am connected to via my address book and the list of all calls landing on my phone (the hook which does the look up for the true called id of the number when I get a call).

What clearly is being missed is that truecaller has a hook into all your contacts and mobile activity without the user having to do any work explicitly – This sets it truly apart from all other social networks where the activity must happen via user intervention to get recorded on the site. It truly has all the things going for being a truly global social network – it is completely crowd-sourced, has the exhaustive social graph and is deeply embedded into your connections and activity. No wonder Facebook is pushing for the Facebook phone – to be right at the place where the connections are happening.

So to sum to it all up, the things that are going for truecaller for leveraging the Social Network

  1. Clearly leveraging the network effect – more the people that install truecaller, the better the performance and the accuracy!
  2. Does not require the user to do anything to become sticky – it already is hooked into YOU – you volunteered to give all the info away
  3. Forget privacy concerns what so ever
  4. Ads while searching for people using their phone number – monetization ready!

Whether truecaller morphs into a social network is a different question, but quite clearly it has all the elements going for it to leverage the network effects of a social network.

2. Phone address book online backup

Going by the fact that after installing and probably at regular intervals the data is uploaded to the truecaller servers – your phonebook is always available on truecaller. truecaller can even charge for restoring your addressbook and you are done! There are other parts of the security of this data but then being the online backup of your phone book is no mean adjacency value! Having gone through my share of pain to restore all my contacts for my phones, I can trully attest this would be a neat service to build. If there is a truecaller API, someone should just build it on top of it. Quite clearly, the network provider will become irrelevant here :)

Concerns that one should not forget though

Privacy is irrelevant

This is huge! What is not probably apparent that all your contacts and all incoming end points are on truecaller servers. Is this something apparent to all the users who installed trueapp? I for one am not sure if I would be comfortable installing trueapp on my phone. But the bigger concern is my phone number is floating on the truecaller servers as people connected to me already consented to give truecaller all access to their address books. The weakest link can reveal all data and connections.

Eaves dropping

With the new revelations like PRISM – all that PRISM has to do is get a hold on truecaller servers and all data will be clearly accessible

Spamming

I understand that there has been no spamming till date. But can we trust truecaller with never selling out the contact points

Safety of data

There might have been attacks on truecaller. Every government or an oppressive regime would be looking in eagerly to hack into truecaller to get details of people, their location even probably and of course any one fighting against the regimes.

Zara – Fast Fashion

November 10, 2012

How Zara grew into the world’s largest fashion retailer

tl;dr

More about Inditex than Zara. The process is … Fast Fashion

Inditex’s 8 Brands
Inditex is the fashion company that owns Zara and many other brands – totaling 8.

The Zara template: Trendy and decently made but inexpensive products sold in beautiful, high-end-looking stores.

Inditex rivals: Arcadia Group, H & M, Mango

Process model / innovation

Impact
Stock is always fresh. This process has changed consumer behavior. In Zara, everything is a impulse buy – it is good and cheap – so no need to save for a leather jacket.

“With Zara, you know that if you don’t buy it, right then and there, within 11 days the entire stock will change. You buy it now or never. And because the prices are so low, you buy it now.”

Tidbits

Project Management learnings

October 2, 2012

These learning are from the Pearl City Project of PCC of 2012. Some of the learnings I took. Jotting them down before I forget.

By handling a Multi-contract approach there will be huge leverage on slippages.

Difference in IT and other industries

Project Management Essentials

Must haves:

Types of contracting

Object classification of projects
(What is the content of the project and purpose?)

Briefly about Cloud Computing:

Global Delivery Model #toread

What are imaginary numbers?

September 22, 2012

what-are-imaginary-numbers

The complex numbers allow us to consider scalings and rotations as two instances of the same thing; and by ensuring that negative reals have square roots, we get something where every (non-constant) polynomial equation can be solved: C is the algebraic closure of R.

Quora and StackExchange are fast turning out to be my personalized wikipedia. Unlike the sterilized quality of answers in wikipedia, the learned folks on Quora and SE reaching into their experience and sharing their personable answers, it is (they are) fast becoming my personal treasure trove of knowledge.

Water water everywhere…

August 9, 2012

Away from the regular posts that I have, this is a simple infographic that came my way. And given its such a neatly presented work I decided to post it here. Of course, I would have loved it if this was a movie in itself (and Meika you must really make this into a small movie, with a sound and all… kids will love it).

I do think infographics are about the wisdom shown with pictures. This one about the oceans is a story in itself.

Caution: Links to a Biiiiig image below… But a definitely very useful and informative one.

Hat Tip: Meika Jensen, Masters Degree.net
Created by: MastersDegree.net

Bloodbath in Genres

August 7, 2012

From here…

Kano Model

Ultimately many attributes transition from delight to feature to requirement as customer expectations raise. This is why in games specifically genres often become an arms race between a few key players.

Quite clearly, the model of things has this transition where features in a product change from being a novelty to a must have by the next iteration of the product. Any marketplace, which has a set of players whose features are a differentiating factor – and any factor being a major differentiator will be assimilated inside the products of all the competitors over a period of time. No wonder, the patents are looked as a potential trump card to stop this transition.

Table Helper in PHP

April 12, 2009

Custom built frameworks are always a zero-sum game. You get the freedom to build the framework completely suited to your business needs, but then you will more or less have to retread the bug ridden path of other frameworks. For our company currently, as an architect I have immense freedom to look at application from completely ‘techie’ viewpoint and keep building better and simpler solutions to make the lives of ouri developers a bit simpler.

PHP is an amazingly simple language to build webapps in. Though personally I am in favor of Python or even Ruby to build webapplications, the amount of workforce in PHP available in the market makes it an immensely favored language.

Anyways, back in my work, we have this interesting problem where we have to render hundreds of analytics reports. Pull from the DB and display the results in table format. To deal with this tedium of having to write innumerable presentation layer files to deal with table rendering we use a small function to render the tables. Its a pretty simple function that formats the data in neat table cells using

and encloses each of the resultset in the table rows.

. However, because of this limitation we had the presentation layer tainting the data with the presentation tags.

Hence the genesis of this unit test code.

require 'table_helper.lib.php';

################# FOR UNIT TESTING THE FUNCTION #######################
function url_logos($profile_id) {
  switch($profile_id) {
    case 1: return "abcde"; break;
    case 2: return "vwxyz"; break;
    default: return "NONE"; break;
  }
}

$Data = array(
  array('john', 'john carmack', 1, 75, '2008-12-1 00:0:00'),
  array('galt', 'john galt', 2, 2, '2008-06-06 06:06:06'),
  array('dagny', 'dagny taggart', 1, 180, '2008-11-00 00:0:00'),
  array('hank', 'hank rearden', 2, 200, '2008-06-02 06:06:06'),
  array('roark', 'howard roark', 1, 0, '2008-12-1 00:0:00'),
  array('john', 'john carmack', 1, 75, '2008-12-1 00:0:00'),
);
$Headers = array('Alias', 'Name', 'Profile', 'Games', 'Joining Date', 'Square');
$Templates = array(
  '"{$data[0]}"',
  '$data[1]',
  '"http://www.someurl.com/profile.php?id={$data[2]}&name={$data[0]}"',
  '"{$data[3]}"',
  '$data[4]',
  'url_logos($data[2]);'
);

TableHelper::Render($Headers, $Templates, $Data);

This led to the first version of my code for the TableHelper class which would simply use the PHP ‘eval()’ code the replace the Templates and fill it with data.

class TableHelper {
        /**
         * @func   Render($Headers, $Templates, $Data, $Prefix = 'data')
         * @desc   renders a table for the given data and the cell templates given.
         * @param1 $Headers a string array of table column headers
         * @param2 $Templates string of cell templates. The data bucket should be named 
         *         as data in the default case. If you think of any other name be sure
         *         to pass the correct prefix to the function.
         * @param3 $Data Data to fill the templates with.
         * @param4 $Prefix Default bucket for row data is 'data'. Can be anything else.
         * @note   This function now builds a template file instead of using eval.
         */
        static function Render($Headers, $Templates, $Data, $Prefix = 'data') {
                $NumCols = count($Headers);

                echo '< table>';
                echo '< tr>';
                        foreach ($Headers as $header)
                                echo '< th>'.$header.'< /th>';
                echo '< /tr>';

                foreach ($Data as $$Prefix) {
                        echo '< tr>';
                        for ($i = 0; $i < $NumCols; $i++) {
                                        eval("\$_cell=\"$Templates[$i]\";");
                                        echo '< td>',$_cell,'';
                        }
                        echo '< /tr>';   
                }
                echo '';
        }
}

As any seasoned programmer will tell you looking at the code, I was sacrificing speed (lots!) for want of better code separation by using eval(). After days of rumination I decided to use aggressive template caching in pphplace of eval(). And here’s the class with the caching mechanism built in…

# BEGIN Section Table Template Caching Section
define(CACHED_TEMPLATES_FOLDER, './cache/');

class TableHelper {
        /**
         * @func CachedFilePath($Id)
         * @desc The table template cached file is just named as unique id.tpl.php
         *       in the CACHED_TEMPLATES_FOLDER folder.
         */
        static function CachedFilePath($Id) {
                return CACHED_TEMPLATES_FOLDER.$Id.'.html.php';
        }

        /**
         * @func BuildTemplate($Id, $Headers, $Templates)
         * @desc Generates the php code for rendering the table and writes the
         *       table generation view code template to the cached folder.
         */
        static function BuildTemplate($Id, $Headers, $Templates) {
                assert(is_writeable(CACHED_TEMPLATES_FOLDER)) or die('Error THL001: Cache Folder has no Write Permissions.');

                $str = '';

                /* Build the Table Rendering PHP Code String */
                $str .= "< table>\n";
                $str .= "< tr>\n";
                        foreach ($Headers as $header)
                                $str .= "< th>$header< /th>\n";
                $str .= "< /tr>\n";
                
                $str .= '< ? php foreach ($Data as $$Prefix) { ?>';
                        $str .= "< tr>\n";
                        foreach ($Templates as $template)
                                $str .= "< td>< ?= $template ?>< /td>\n";
                        $str .= "< /tr>\n";
                $str .= "< ? php } ?>\n"; 
                $str .= "\n";

                $handle = fopen(TableHelper::CachedFilePath($Id), 'w'); 
                        fwrite($handle, $str);
                fclose($handle);

                return true;
        }
        # END Section Table Template Caching Section

        /**
         * @func   Render($Id, $Headers, $Templates, $Data, $Prefix = 'data')
         * @ver    1.2
         * @desc   renders a table for the given data and the cell templates given.
         * @param1 $Headers a string array of table column headers
         * @param2 $Templates string of cell templates. The data bucket should be named 
         *         as data in the default case. If you think of any other name be sure
         *         to pass the correct prefix to the function.
         * @param3 $Data Data to fill the templates with.
         * @param4 $Prefix Default bucket for row data is 'data'. Can be anything else.
         * @note   This function now builds a template file instead of using eval.
         */
        static function Render($Id, $Headers, $Templates, $Data, $Prefix = 'data') {
                $NumCols = count($Headers);

                /* Attempt to just include the cached template file for this table */
                $cached_file_path = TableHelper::CachedFilePath($Id);
                if(!file_exists($cached_file_path)) 
                        TableHelper::BuildTemplate($Id, $Headers,$Templates);
                
                if(file_exists($cached_file_path)) {
                        include_once $cached_file_path; return;
                }

                /* If Cached File cannot be created, just do the EVAL way! */
                echo '< table>';
                echo '< tr>';
                        foreach ($Headers as $header)
                                echo '< th>'.$header.'< /th>';
                echo '< /tr>';

                foreach ($Data as $$Prefix) {
                        echo '< tr>';
                        for ($i = 0; $i < $NumCols; $i++) {
                                        eval("\$_cell=\"$Templates[$i]\";");
                                        echo '< td>',$_cell,'< /td>';
                        }
                        echo '< /tr>';   

                }
                echo '< /table>';
        }
}

Catches
The only dependency with this code is that you have to create a Apache writeable folder referenced by the CACHED_TEMPLATES_FOLDER. After that its just fun all the way! Also note that the call to the Render in the unit testing class will now have to be supplied a unique Template Id.

TableHelper::Render($Id, $Headers, $Templates, $Data);
← Previous Page