twitter
    Find out what I'm doing, Follow Me :)
Showing posts with label pragmatic programmer. Show all posts
Showing posts with label pragmatic programmer. Show all posts

Your Language Shapes Your Thought

I recently finished reading “Outliers the Story of Success”, the latest book from Malcolm Gladwell. This is not a book review. But there are a couple of thought provoking ideas in this book that struck me. It made me think how it is applicable to this world of programming.

In the “Rice Paddies and Math Tests” chapter Gladwell try to present answers to this stereotype: Why are Asians good at math?

Gladwell started by quoting example from Stanislas Dehaene's book "The Number Sense” . He asks reader to try to memorize this sequence of numbers: 4,8,5,3,9,7,6 in twenty seconds. He states that English speakers would have 50% chance of getting it right. However if you speak Chinese, you're almost certain to get it right every time. Why so?

This is where things getting interesting. It’s a fact that people have about two seconds memory span. We can easily retains information that we can fit in two seconds. Here cultural or linguistic background doesn’t matter. What does matter is how many numbers you can comfortably fit into those 2 seconds. Chinese speakers get that numbers sequence right every time because—unlike English speakers—their language allows them to fit all those seven numbers into two seconds.

I’ve observed this with my Chinese friends. They can recite and write down 10 digit phone number easily while I always need the last half to be repeated.

Gladwell further argues that, the numbering system in Chinese is much more logical than in the western languages. It matches nicely with the decimal numbering system that we use in Maths. Chinese, for example say two-tens three for 23. While English speakers say twenty three. Ten two for 12 vs twelve. Math is therefore thought of, spoken and written all in the same way.

It makes learning math a much more logical and much less daunting process. Same thing with the concepts of multiplication, division, and fraction, it fits perfectly with the Chinese language.

How does it relate to programming? I’ve observed, while reading other people code, that their programming language background define the kind of abstractions they will use. It influences how they will solve a particular problem.

For example, while reading Java code written by people with functional programming language background, I’ve found they used anonymous inner classes repeatedly. Which I rarely found in code written by programmers which solely program in Java.

I found myself start to use some anonymous inner classes in Java or lambda expression in C# after learning Ruby, Python, and LISP. I started to use higher order function more in my Javascript code. Why? because the concept of passing a function as parameter by using anonymous inner classes in Java or delegate in C# pre 3.0 is a very remote concept for me. The syntax is clunky. Hence, it doesn’t come intuitively to use this abstraction in my code.

However, when I learned Ruby, or especially LISP, it is used everywhere. The syntax is so much more intuitive. Thus, I started using it more and more.

Joel Spolsky in his article “The Perils of JavaSchools” states:

“Without understanding functional programming, you can't invent MapReduce, the algorithm that makes Google so massively scalable. The terms Map and Reduce come from Lisp and functional programming. MapReduce is, in retrospect, obvious to anyone who remembers from their 6.001-equivalent programming class that purely functional programs have no side effects and are thus trivially parallelizable.”

The point is, your language defines your thought. And real world experience is a big influence to both your thought and language.

As the book itself. It is a great book. It is informative, entertaining, and thought provoking.

Don’t be a Blub

I like to learn new things. As a programmer I have this affinity toward shinny and cool things. I remember while still at Uni, I used to tell my friends that we should learn both J2EE and .Net, then we wouldn’t have to worry about getting a job.

However, not until after reading The Pragmatic Programmer: From Journeyman to Master book by Dave Thomas and Andy Hunt, my affection for learning programming languages goes to the next level beyond Java and C#. Among other excellent recommendations/advices in this book , Dave and Andy taught us in their "Your Knowledge Portfolio" section that in order to be well-rounded developers, we need to set a goal to learn at least one new programming language every year.

They also suggests to treat your skills like an investment portfolio so you should:

  • Invest regularly
  • Diversify portfolio
  • Balance portfolio for risk
  • Buy low/sell high (be an early adopter of new technology)
  • Rebalanced you portfolio periodically.

Why a year, what can you learn in year you would ask. Won’t we just turn into a jack of all trades? No, the idea is not to be a master in all the languages. No one can do that. But the ideas is to open your mind to different way of thinking through and solving programming problems. So it is much more than just learning different kind of weird syntax. Learning the syntax is one of the most easiest task.

Instead try learning different concepts and abstractions in these different languages. Learn about lambda expression in language such as LISP, Python. Learn about mixins in Ruby. Learn about actor/agent in Erlang. Learn about curry function, monads, fixed combinator in Haskell, or OCaml. Learn about macro in LISP.

In fact, you are in dangerous becoming a blub programmer otherwise. Blub programmer is a concept coined by Paul Graham in his article Beating the Averages.

Paul argues that some languages are more powerful than others and there exists a hypothetical mid level power language called Blub. He describes the Blub programmer as:


“As long as our hypothetical Blub programmer is looking down the power continuum, he knows he's looking down. Languages less powerful than Blub are obviously less powerful, because they're missing some feature he's used to. But when our hypothetical Blub programmer looks in the other direction, up the power continuum, he doesn't realize he's looking up. What he sees are merely weird languages. He probably considers them about equivalent in power to Blub, but with all this other hairy stuff thrown in as well. Blub is good enough for him, because he thinks in Blub. “

Although It is debatable that there exists such a continuum in programming language power. But the concept of Blub programmer succinctly described the dangerous of becoming a narrow focused programmers.

Most people without the experience of a programming language can't see that language features as really useful things. If the only language I know were C# and the only web framework that I know were ASP.Net probably I would still thing that ASP.Net is the best web framework in the world. I wouldn’t know it is such a leaky abstraction of web programming. I wouldn’t know there are better alternatives. And if all other .Net developers thing the same way, Microsoft wouldn’t have to fix it and created ASP.Net MVC.

I also found learning different kind of abstractions in different languages increases my knowledge and understanding of the main languages that I used(Java and C#). It is not until I learn the concept of pattern matching that I really understand the Visitor pattern.

The other day, I showed my program that does screen scraping(written in Ruby using Mechanize and hpricot) to a Java developer. I used Ruby for this app because I think it is the right tool for the job at hand.

To my surprise he screamed what is that weird looking syntax and hard to understand code, you should have used Java. What, Ruby syntax is weird and hard to understand? That is the weirdest things I've ever heard. Beside that, how long it would take to write the same app in Java. Three or five times at least and with much more noise. Or could it be that I’m the Blurb programmer. What a paradox :)).

Departing thought, don’t think in Blub!