Our life around REPL – Read–Eval–Print Loop

Whenever I see my niece so comfortable with iPhone, Mac, Advance Toys; I usually wonder almost similar feeling our parents must have pondered about us. But what is the biggest disadvantage of being part of GEN X. What? We have best things in the world but the irony is that we don’t enjoy or embrace the inventions/creations done by our forefathers generation. For us TV, Radio, Telephone, Mobile, Desktop was little obvious, now for next generation iPhone, iPad, Smartphone, DSLR, Laptops, Tablets et al are very obvious. Its clearly visible our parents struggle with our generation widgets and I have now started to struggle with next-generation gadgets.

You must be thinking what is it had to do with REPL. During college days, I started coding in C, bit of Java (to clear job interviews incase required), then majorly on PHP, RUBY, PYTHON, JAVASCRIPT, BASH. The moment I started coding on these languages, which are derived from their forefathers C & Lisp, I sensed a sheer bliss while working on them and started promoting them in peer group as soon as I realized the language is always available and it was obvious not to look back at C, C++, Java and many others. We can easily compare it to Gramophone, cassettes, VCR , VCP, Landline but these inventions were the foundation of where we stand today in our life or in programming world.

I was not clear about the term REPL when I started working on these languages and thought of it as a jargon of programming world. Recently, wrote a smallest code on ruby and a REPL was created. This is when I realized the power of REPL and thought to read about their forefathers. Let’s first have a sneak-peek into that smallest piece of ruby repl code.REPL

#!/usr/bin/env ruby
loop {p eval gets }

 

Now read this piece of code in reverse order, READ (gets), EVAL, PRINT (p), LOOP. Save this file as repl.rb and run as`ruby repl.rb`

─$ ruby repl.rb 1 ↵
"akshay Gupta".upcase
"AKSHAY GUPTA"
1+2*3
7

Congratulations, now you understand REPL and underlying fact of  language is always available i.e. no real distinction between read-time, compile-time and run-time. Now, when I start working on any new language, it’s easier to pick up if it’s REPL based and I truly thank Mr. John McCarthy father of Artificial Intelligence, creator of LISP (where lies the roots of REPL) for his immense contribution in the field of computer science, AI, programming languages and so many programming paradigm. If i’m not wrong, he is also the inventor of if-then-else conditional construct and we take these for granted now.

Running code at read-time lets users reprogram; running code at compile-time is the basis of macros; compiling at runtime is the basis of Lisp’s use as an extension language in programs like Emacs; and reading at runtime enables programs to communicate using expressions.

There have been two really clean, consistent models of programming so far: the C model and the Lisp model. As computers have grown more powerful, the new languages being developed have been moving steadily toward the Lisp model. A popular recipe for new programming languages in the past 20 years has been to take the C model of computing and add some parts taken from the Lisp model, like runtime typing and garbage collection.

repl-loop

It’s equally important to look forward and innovate in coming time and respect, embrace the efforts of our remarkable forefathers. To read and practice different languages that support REPL please follow the below links. I primarily depend heavily upon irb and PRY.

In our everyday life we do nothing more than READ (consume knowledge), EVAL ( between right and wrong), PRINT (discuss around), LOOP (day everyday) i.e. REPL 🙂

 

Magical ‘If..then..else’ conditional statement

I believe whole programming world stands on couple of pillars and ‘if..then..else’ (ITE) statement is one of those. Everyone programmer and non-programmer understands ITE conditional statement for sure.

 A typical if..then..else.. statement in Ruby:

 if 1 == 2
   puts "inside if statement"
 else
   puts "inside else statement"
 end
1.9.3p385  > inside else statement
Another example in ruby:
#/bin/ruby
near = "father"
if near == "father"
  puts "I'm studying"
elsif near == "mother"
 puts "I'm playing"
else
 puts "I'm sleeping"
end

1.9.3p385  > I'm studying

Essence is either of two given block is executed i.e. either if block or else block is executed by the code in any language.

Can there be a case/situation when both of these blocks if & else are executed?

…. This is really an unusual question but seriously can this be achieved. Can we challenge the very existence of conditional flow? Are the basics we have learned aren’t true anymore?

Answer lies in situation and yes this can be achieved. Unix fork(2) is the answer and can help if..then..else to behave in this manner.

example magicalif.rb

if f1 = fork
  puts "inside fork"
elsif f2 = fork
  puts "inside second fork"
else
  puts "outside fork"
end

─$ ruby magicalif.rb

inside fork
inside second fork
outside fork

So what has just happened? Condition checks for fork(2), kernel command to create a subprocess of the parent process.  So fork, creates a subprocess called child process similar to parent process (having copy of parent process, file descriptors and sockets etc) and returns a pid (child process) to parent process and nil to child process. Hence, IF block was executed by parent process as it returned pid to parent process and ELSE statement is executed by CHILD process as fork returned nil to child process.

Let’s have a closer look which block is executed by which process (parent or child)

supermagicalif.rb

puts "Master Process: #{Process.pid}"
if f1 = fork
  puts "inside fork"
  puts "Fork PID: #{f1}"
  puts "Process pid: #{Process.pid}"
elsif f2 = fork
  puts "inside second fork"
  puts "Fork PID: #{f2}"
  puts "Process pid: #{Process.pid}"
else
  puts "outside fork"
  puts "Process pid: #{Process.pid}"
end

─$ ruby supermagicalif.rb
Master Process: 21267
inside fork
Fork PID: 21268
Process pid: 21267
inside second fork
Fork PID: 21269
Process pid: 21268
outside fork
Process pid: 21269

This clearly shows IF block is executed by PARENT process, ELSIF block executed by first CHILD process and ELSE block executed by SECOND CHILD process.

Will have a more closer look in fork(2) in next blog where will see it’s usage and how can it be used in our programming. For now, yes it’s possible and now you know MAGICAL IF..THEN..ELSE statement 🙂

How to study and learn from world’s best Teachers and Professors

When I was in college their was always a desire that If I would have been in Stanford or some great university I would have access to world’s best professors and it would have been a different learning experience altogether.

Or

How great it would be if I can study whatever I feel like outside of our course in a systematic way and can learn the fundamentals that help to grow my knowledge, fundamentals or businesses

Education for all

Education for all

Internet is open and google always helps but still felt their is a lack to find the best course material or community for International Students to learn new courses and subjects that interests you. Life is no better and still lakhs of student who passes out every year have very diminished knowledge about what they study. In most part, Indian Universities and Institutions are unable to provide good Professors or teachers to students. It still continues to be like this and “Quality Education” is still far from anyone without any differences. Students are first categorized on basis of their caste, creed, grades and reservation. Economic condition of a family is always a primary concern besides all these factors.

Recently after 4 years of college education and during my visit Bay area and Stanford. I heard about Coursera, founded by Stanford computer science professors Daphne Koller and Andrew Ng ( StanfordDaily ).

About Coursera

We offer high quality courses from the top universities, for free to everyone. We currently host courses from Princeton University, Stanford University, University of California, Berkeley, University of Michigan-Ann Arbor, and University of Pennsylvania. We are changing the face of education globally, and we invite you to join us.

Then I started with more exploration and soon realized some best part of joining these courses. Mind it it’s free

  • Variety of Courses. I can study about anything and take up course of my choice e.g Algorithms, Pharmacology, Finance, Humanitics etc
  • Course taught by World’s best professors and Universities. Seriously it feels great to have access to best profs.
  • Small Video based tutorial. According to me “Small” videos are the key, as it’s easy to concentrate for shorter time and easy to watch as and when time suits you
  • Interactions with like minded people from the globe on the Discussion Forums
  • Format of the Syllabus and weekly assignment keep the clock ticking
  • Content of the course is way too good and easy to understand for anyone.

Last but not the least, now anyone from anywhere in the world can enroll and (re)study without any hesitation in his/her own time.

Heartiest thanks to the Universities and their Teachers and Professors to impart their knowledge to the world from their schedule and thanks to Coursera for providing it for free without any difference to everyone. Period

Note: This is in no way Coursera marketing but genuine feedback from a learning student 🙂

Happy Learning!

Online vs offline commerce: Targeting and Re-targeting your customers

Attended Triggr event today at InstaMedia Noida. It was interesting to hear couple of presentations and thoughts which was majorly focussed on one term “ENGAGEMENT”. I started loving this term especially, as everything revolves around this one simple term. Either your business is online or offline, engagement is involved at first hand once user showed some interest, then comes all other factors. If you succeeds in this engagement, you can turn your business to X folds.

In offline market, you go to shopkeeper to buy something, you showed interest then he starts engaging or recommending things to you, as you might also be interest and we tend to buy most of the times (credibility plays a vital role). If something is unavailable or when you come next time, he remembers what you want, he’ll greet you and engages you more. Now you’ll go to that shopkeeper again and again. Thats how a typical offline businesses run.

offline shopkeeper engagement

Talking in terms of Online context, their is no physical person, companies usually do lot of investment on Suggestions, Recommendations of products if a person shows a interest by saying “people also bought this”, “we recommend you to buy this” etc. to engage the users and converting it into business.

online product recommendations

Their were talks on how to minimize the bounce rates and more user engagement. Some implemented and proven ideas are designing it right way which comprises focusing the social media aspect i.e fb/tw views etc (talk from Slideshare), a/b testing (Paras, http://visualwebsiteoptimizer.com), Multi Variant testing (MVT), landing pages ( I must say unbounce guys have done a fantastic job) to understand what works best in terms of user engagement. Your product should ideally deliver the right message about your product in minimum words and should emphasize on self-talking images and help user talking the action on your page (without confusion). Once done, he will spend time to understand your product(s).

Interesting, met with Nitin Chawdhary, India Head, Tyroo ad network, I really like his presentation on E-Commerce, Engagement and Re-targeting your customers. To explain re-targeting in layman’s terms:

If your customer shows some interest in a product but goes off, next time if you happen to advertise/target him again, about that very specific items he was interested in, there is a high probability that he will buy this time.

According to him, if you re-target your customer around 5-6 times, there are high chances of actual lead conversion. One of the pain points he mentioned in e-commerce is, its very hard to find and target the customer back, once he is gone.

Talking more in terms of offline businesses or online businesses and once you scale re-targeting is hard to achieve, I’m sure technology has its limitations but its achievable on Internet. But re-targeting in physical world is yet missing according to me and in Indian context e.g. If I have an intention to buy a microwave and I go to market and try out couple of stores, how about the store shoots a message back to me (once I left his store) with some offer, to actually convert the lead and the time sales guy invested in explaining the whole Microwave functionality in person. I think enterprises will be interested in these solutions of re-targeting in physical world and simple implementation of this common and complex problem.

Moments, Life and Remarkability

Moments pass by as a drop of water, each one of it make Life. Moments vanishes as you start thinking of it to complete your life. But just analyze WHY? Why are we here ? What we are supposed to be?
Some good saying: Live whole-heartedly, help others, do whatever you like with passion, contribute to the miraculous deeds our ancestors had done once, never give up life will always test your patience and endurance. Is it love, lust, success we are living for? Are we going the right way? Are we destined ?

If one ever think of why Einstein, Faraday, Sachin, Gandhi..name anyone..why were they great?How come respect comes out of its own while remembering them.

  • Simple they discovered something, they were leaders, they were simply different.
  • How come they were different, they were mere humans.

Your answers started sprouting:

  • Things were easier at that time. Nah
  • Easy resources. Not possible.
  • Plenty of time to try out something new. Not sure? same 24 hours.
  • Things was unexplored, now everything is there. Same thoughts prevails over centuries.
Eight Secrets Of Life

View SlideShare presentation or Upload your own. (tags: secrets powerpoint)
It seems they did something different, impossible and remarkable. My thoughts say follow those simple guys who were remarkable, contributer and made their life worth living. Moving against the tide is never easy, but the flew, they were not different rather they were much simpler. Isn’t?
Its just that they analyzed and walked through the path their heart was leading. It was their passion and inner urge to follow their dream that made them remarkable. They never did it to be famous or for wealth, its the satisfaction they were thriving for. This is greatness.Now, lets discuss our life, we are brought up educated, equipped with all resources (most of them one don’t even need), plenty of time (exclude the time spent on cell, chat, bc and complains about life), I belief everything is more easy, approachable, just one click away thanks to Mr Tim Berners Lee. One dont have to travel years to find where India is, on boat with few crew members. Our great remarkable leaders fulfilled all the resposibilities, they did loved some one, they did married, they did whatever a common man spent time upon. So whats missing ??

Passion, Depth of thought, Direction etc
In one thought we have never thought, why are we here for? It was their remarability that made them respectable, different, famous, successful. You know Apple never fell over Newton‘s head, he was just sitting idle under apple tree and looking at calm moon and an Apple and he realized that both are of same size and yet one falls down and one never. So distance can make things look alike but something decreases and he coined the name as Gravity. Remarkable enough for the whole world.In Modern World one try to dress, talk , walk, become rich but surprisingly none of them takes to the path of remarkability other than creating differences, boundaries. Simplicity is the characterstic of being different.

I believe “Simplicity of character is the natural result of profound thought