Wednesday, January 26, 2011

How Programming Language Shapes Thought: Overview of Series

In my last blog I went down the memory lane to see some of my own hand written notes from 1996-1998. Actually reams and reams of papers filled with many interesting ideas ranging from chip design to programming languages from Natural language processing to object oriented operating system design. (I also found bunch of science fictions I wrote that I am going to cleanup and publish.
I am planning a series of blogs on the subject. Here is an overview.  

I am opinionated because I'm Literate.
Donald Knuth coined the term "Literate Programming 
He says:  Let us change our traditional attitude to the construction of programs: Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do.
Planned Blog : Don't be illiterate!!

Syntax sugar is good.
 In my opinion the number one job of any programming language is to make programmers productive. I hate people who say "it's just syntax sugar". Yes, you are right- you idiot! Assembler is a syntax sugar, C is a syntax sugar, C++ is syntax sugar ..so on and so forth. I want 10th generation language right now. As long as it makes me productive and makes my intent clear sugar is good!! 
Planned Blog : Sugar is good!!
If someone is insisting on writing the 'raw' code then they are wasting their time and money.

Code is Design  
Software is different, the code we write is itself design.
Planned Blog : Be Extreme! Refactor your thinking: How to neutralize the guys who ask for design specs... 

Quality vs. Correctness: Be Assertive. 
Now, as software engineers we spend a huge amount of time finding fixing and debugging the bugs. So being productive means language features that force me to think about quality and make it easy to write the code. One of the books that has influenced me the most is Writing Solid Code. Two things that have stuck with me for lifetime are (A) I use asserts like crazy (B) I use debugger a lot. 
I like to be super paranoid so lots of asserts. And I write a lots of tests which tend to be exhaustive.
Here is a catch though : Absence of bugs is not quality and presence of asserts is not correctness.  When I misunderstand something or simply did not think about something. I write wrong code , wrong asserts and wrong tests ! All unit tests pass and I have a bug filed against me !!!  
planned blog: Be Assertive
planned blog: Quality Strategy
planned blog: Being Probably Correct .. 
planned blog: Automate my way to disaster. 
planned blog: Fragile Development

Ineffective Design!
One of my favorite books was  The Design and Evolution of C++ . The three takeaways ..
  1. Language must be must be a natural progression of what programmers are comfortable with right now.
  2. It must be statically compiled. With no runtime overhead.It must be able to link with existing code.
  3. Pay the price for only for the features that you use. Also,
With multi paradigm language like C++ one problem is that with increased flexibility comes increased complexity and increased risk that you'll shoot in your foot. You are always free to write the ineffective, sloppy or very clever "(!?#@)" code.  With increased flexibility comes increased responsibility. Thankfully there are books like these
Effective C++: 55 Specific Ways to Improve Your Programs and Designs (3rd Edition)
More Effective C++: 35 New Ways to Improve Your Programs and Designs
But problem is that all that good stuff is option.
Be Effective ! Analyze that! 
Use static analysis tools
Other blogs
  • Design by contract
  • Unit Testing
  • Pex an interesting Idea
and many more ...
    Testing Object-Oriented Systems: Models, Patterns, and Tools (ARP/AOD) 2 Vol. SetTest Driven Development: By ExampleToward Zero Defect Programming

    Sunday, January 23, 2011

    How (Programming) Language Shapes Thought: Trip Down the Memory Lane

    In my earlier posts I talked about interesting issue of how language you speak (may or may not) affect how you think.
    How Language Shapes Thought
    How Language Shapes Thought : Take 2

    Being a computer engineer and an Agile Supporter I have to get back to my roots and passion: Programming languages and  how it affects the software life cycle.
    Before I talk about how programming language can shape your thought. I must first confess how the whole tpoic has shaped and influenced my thoughts.  Where I come from and where I want to go ...

    I was a passionate compilers freak in college days. 
    I think I still am. I am one of those programmers who started coding in pre-internet era. Back in college days it felt like it was a privilege to get even a one hour of internet time each week. For most part we just coded and coded in turbo C.
    Compiler was my favorite subject (with Computer Architecture equally appealing). As a final year college project I chose "Fortran Compiler for Java Virtual Machine". We defined our own IL,wrote an assembler for it, wrote "binary dumper and editor", and of course the compiler and also wrote a VB MDI application to provide the Visual Studio editor's cheap imitation.

     
    Why fortran? Because we thought CDAC Param Super Computers guys might be interested. Well that never went too far beyond couple of meetings and we didn't followup either.

    Recently I found the treasure trove of my own writings from my college days going back some fifteen years. My mom had kept all of the reams and reams of my hand written papers.It is an amazing experience to read those things.

    Obsession in Two Stages
    Back in 1996-97, I was obsessed with this idea of having a two stage  architecture where N number of languages could compile to common byte code,distributing it in that format and then installing/converting it to machine code of M different architectures.I have written reams and reams of paper describing the concept . I think I also wrote the specification for "my" virtual machine instruction set.
    I was able to convince my friends to take the whole concept as our project and they helped me realize that idea back. We needed something concrete so instead implemented "Fortan compiler for Java Virtual Machine".
    I got out of college, got the job and because of my exposure to compilers I got some project for testing one of the compilers. Years passed, projects changed ...And then I got another project involving something called COM 2.0 and COOL.
    You can image my joy when I saw C# and .net for the first time. I was impressed with Microsoft.  I have to that Microsoft's C# guys have been consistently continued to impress me since then.
     
    But it is kind of interesting to read some of my own writing after fifteen years and see how the idea progressed and how it still remains valid. In Indian education system publishing papers was never a goal. I wrote reams and reams of "papers" for myself  and back then it helped me in developing/clarifying those concepts. And I had time!!!




    It is all about Syntax Sugar Stupid !
    Programming languages are all about converting higher level abstractions into suitable low level constructs. Yes it is often syntax sugar but that is what compilers are for to make your job easier and fun. And make you productive and less error prone.

    When I was in college I had another love affair.I wanted to create a new Programming language I used to call it Object Curry.
    I was interested in another idea using SQL like syntax to manipulate object oriented data structures in the program. It was an awesome concept and I painfully  tried hundreds of syntax/semantics combination. I never got time to actually implement the language I spent so much time "Designing". Just Below are some of the scans of my written "papers" from those days.
    (That must be at least fifteen years ago.)
    Somehow I kept on switching between Pascal like syntax and C like syntax. There is something beautiful and "clean" about pascal like syntax and something powerful and natural about C like syntax. For most part they are equivalent. In that respect C# is actually clean like pascal and looks like C.
     Again you can image how happy I am to see C# finally getting those constructs. Personally today, I like to use the raw APIs themselves because they give so much flexibility.

    It is interesting to compare "my syntax" with real C#/.net.
    I had a  
    for each (select_clause;from_clause;where_clause)
    {//use variable names as you would use in normal case.}

    I had this construct where I planned to change the meaning of the word enum to return a list of objects.
    So you could do something like
    enum x = {1,2,3}; 
    enum y =  each(/*select*/ int a ; /*from*/ x; /*where*/ x%2 ==0);
    for y { fn(y.a); }




    Functional Beast. 
    My notes/papers show that for some reason I was very interested in C having nested procedures .
    I have to confess I always thought of delegate as simply a pointer to function and mildly amused by the closure concept. But I must say great way to pass a state machine.
    Will talk about that in a next post.


    Fast Faster Fastest:
     I also found many interesting things related to performance and concurrency.





    How Language Shapes Thought - Take 2

    Cogito ergo sum! I am thinking that's the only thing I can be sure about. But I can only assume that the world I'm sensing is real and that you are also probably sensing the same world. I can only imagine and "simulate" your experience when you use language to tell me something. Immanuel Kant resolved this issue by using concept of a priori knowledge. -We have instinctual knowledge of space and time.
    I'll go one step further ... Let us assume a few things and then try a thought experiment.Let's turn the argument around and open Pandora's box

    ASSUMPTIONS (or a priori knowledge)
    Assumption 1: We must use Verbs to describe world. Things are the way they are or they change.(i.e stative verbs/action verbs)

    Assumption 2 : When things change they either undergo transformation or someone acts on them.
    - That change must happen in "Time", at a "Place" and in certain "Manner".
    - An "Agent" acts and some "Object" is affected.
    - These are the salient features of "Action"
    - There might be a "Reason" for the action and an "Instrument" might be used.
    Let's call these 'Salient Slots'.
    (These are more or less various cases described in classical latin, sanskrit and greek.)

    Assumption 3: The sentence must have a "verbal center" and can fill one or more of the slots with a phrase leaving other unspecified and must fix "Tense", "Aspect" and "Mood" (possibility/necessity)

    HYPOTHESIS: All humans share this same a priori knowledge and it forms the schema or "instruction set" to analyze,understand,code decode and imagine information transmitted though use of language- in short to "derive meaning". Therefore all languages despite their superficial differences must be equally capable and must be expressing same underlying meaning.

    PANDORA'S BOX WHEN WE DENY THE HYPOTHESIS.
    1.There are some languages that are "smarter" than others.If yes I should better start using the smartest language. I already think Indo-aryan languages are the best and english and chinese are the dumbest.(I can give long list of why)
    2. Better yet I can "design" a language that makes me and my fellow language speakers super smart. Better yet sell the product and become zillionaire. Wait, wait - I can also file a patent and stop you from being smart. "Method & apparatus to enhance cognitive capabilities through carefully arranged symbol mapping of spatio-temporal imagary extracted from verbal communication"
    3. Langauge preservation is all non-sense. Those idiots should learn chinese/russian/english/foo/blah/ "sachinease


    Some of the useful links on the topic
    From the Personal Library
     I am a fan of Steven Pinker's work all are must have books
    The Language Instinct: How the Mind Creates Language (P.S.)  Words and Rules: The Ingredients of LanguageThe Stuff of Thought: Language as a Window into Human Nature
     The Language Instinct: How the Mind Creates Language (P.S.) 
    The Stuff of Thought: Language as a Window into Human Nature 
    Words and Rules: The Ingredients of Language 
    Some important Linguistic books
    Study Guide for Contemporary LinguisticsStudy Guide for Contemporary LinguisticsGeneralized Phrase Structure Grammar
    Study Guide for Contemporary Linguistics
    Generalized Phrase Structure Grammar
    Other Grammar books
    A Sanskrit grammar,: including both the classical language, and the older dialects, of Veda and Brahmana. 
    A Sanskrit grammar,: including both the classical language, and the older dialects, of Veda and Brahmana. 


    Essential background
    http://en.wikipedia.org/wiki/Tense_aspect_mood
    http://en.wikipedia.org/wiki/Universal_Grammar
    http://en.wikipedia.org/wiki/X-bar_theory
    posted by Sachin Joshi

    Friday, January 21, 2011

    How Language Shapes Thought

    Just received my issue of Scientific American and came across an article by Lera Boroditsky.
    It was one of the rare articles where I had this urge to say "Enough! I must say you are completely wrong." Well ! Couldn't help myself and I am saying it - Here.

    Being a computer engineer, I have worked on couple of compilers/parser myself and when I was in dreamy early years of my engineering I was attracted to AI and natural language processing. One thing lead to another and I started reading a good deal about linguistics - Enough to begin to understand stuff like X bar theory, Generalized Phrase Structure Grammar, Interlanguage Grammar, Markedness and likes.

    Personally I am fluent in 3 languages.  English (8 out of 10), Hindi (9 out of 10) and Marathi (10 out of 10 being my mother tongue).
    I also learned Sanskrit for 3 years when I was in high school. For last few years I think I am getting better with my Spanish.
    Background
    There are over 6000 human languages and they often differ along many dimensions. Word order, whether you can drop the pronoun, agreement rules for gender and number, use of cases stress accent/mora timed and many others. For some time,  people used to think that structure of your language affects the way you think and perceive the world. It is called Sapir-Whorf hypothesis. It seems to suggest that if you 'control' the structure of language then you can control how people view the world. The article says they now have stronger argument.

    I disagree - choice of words may affect analysis of abstract conceptual things but not the concrete perception of every day reality.

    Here is a Counter Argument - sort of paragraph for paragraph.

    1.  Lera' Article: Sapir-Whorf hypothesis is gaining credibility
    Response : Both weak and strong versions of the Sapir-Whorf are empty, meaningless and circular. In my view

    • Our ability to experience the world, recall and analyze it remains independent of language. 
    • However our ability to express and articulate that experience precisely and accurately does depend on the medium (the langauge), acts of coding/ decoding and shared meaning between sender and receiver.
    Claiming that knowledge transfer is influenced by the communication is sort of meaningless and empty. That fact is derived from the definition. More importantly it can NOT make any claims on how the cognition itself is affected especially while person is experiencing or recalling or analyzing it. We are not talking about how he communicates or is expected to communicate or while he is "understanding" the words coming out of someone else's mouth. But how his own cognition works for himself.

    2. Lera's Article: Languages differ in their treatment of gender, tense, aspect and so on ...
    So what? Amongst the many choices people have, the actual choice of vocabulary and grammar for particular language depends on what works best in the cultural context. It has evolved through survival of the fittest amid the need for brevity, precision, cultural significance and sometimes following the shared convention instead of reinventing the wheel.
    She talks about how in some languages distinction between maternal and paternal relatives is important. I think she is putting the cart before the horse.
    For example: In a traditional Indian patriarchal society the social structure required different powers/influence depending on whether relative is paternal or maternal. Traditional roles and responsibilities differed too. Hence the different words. Person knows by experience that maternal/paternal are different. What does language has to do with it ? Beyond labeling a 'class of objects' that have different properties? It is their cultural reality that must be reflected in the language.
    I imagine it may be similar to solders being sensitive to the rank of the other and especially attentive to such details.
    The variety of languages just means that some concepts/categories/nuances are better expressed in one language than other. That does not mean it can not expressed at all in other language or is somehow inaccessible or hard to understand to non-natives. All things being equal, all languages can convey any human experience conceivable. 

    3. Lera's Article: Pormpuraaw people don't have idea of right /left.
    Story is that some aboriginal people don't have words for right or left so they must tell 'side' using true north/south. They have honed the directional sense to become human compass. But they have no 'conception' of right or left.
    This is laughable. Gravity dictates  people understand up and down.There is one side you are constantly pulled. There is a clear idea of front and back. You can see only infront of you - same side your mouth and nose is and where you can easily travel/run/walk. Now most people are either right handed or left handed. You know the side on which your are "power"-handed. Most people have heart and stomach on left. You know on what what side you heart races and which side your acid reflux hurts. No matter what you call - left, bad side, down side or weak side , heart side you know what you are talking about.
    I am almost certain that those people will have some real word for the right/left. But culturally required to   drag reference to some hill or something when giving directions. Every now and then,the communication is totally broken when my wife calls me and says "I am at the stop sign, near Sears and I want to go to JC penny which turn should I take - Right or left?" Well I need more info - Which direction she is going north/south? She doesn't know - well then on which street ? Away/towards Starbucks? While I'm thinking she says "Sorry I was in the wrong lane so had to take left turn and but i did the smart thing  I pulled into Les Schwab complex. Can you now tell me should I take right or left?" I am lost.  
    I wish we had a system of "towards mt. Rainier /away from Cascades" like those Pormpuraaw!


    4. Lera's Article: People seem not to understand flow of time or how they describe it. 
    People seem to map time to space directions (top, left, front) in many different ways. But it is ridiculous to even think that some people can not comprehend concepts like growing etc. Everyone knows that the sun sets and rises again and again. Past is history and tomorrow is mystery.
    Any teenager who has his memory intact knows that he was a kid in the past, will be looking forward to meeting a nice girl in future and knows after a long in the future he will be a grandfather. 
    People have written top to down, left to right,right to left, like a plough, spirally. People drive on left side/right side of the road. SOV, SVO. Prefix/Postfix. We need to order things and we pick one of the possible directions. Physical things happen in space-time. Even crazy 11 Dimensional string theory needs a notions of "distance"- near/far. Here is a funny thing - Don't we draw the syntax "tree" upside down? Instead of calling it "tree with branches and leaf" why not call it "root system". It seems arbitrary. Now: Yes - poetics , rhetorics and similes,puns won't work if past is "up" and you ask someone to look forward to go up and up (say the corporate ladder) within his job rank.  But it is coincidence. In cultures where moon is 'she'. You can clearly say moon is a beautiful fair lady.(That too only if you care about being fair).  It is just the coincident caused by convention. 


    5. Lera's Article: Details like whether language is accusative/ergative etc can affect understanding of who did what to whom.
    First I thought this might be actually true. But even seemingly fundamental differences seem to be "artificial".  My language Marathi (and Hindi) is mixed ergative. But I totally know when dog bites the man and why man should not bite the dog. Also my language has similar structure like spanish me gusta la flora . Instead of I like flower. But it would have been foolish of me to think that a flower can potentially like me.(unless I am being poetic.)
    Here are some counter example of categories English lacks yet english speakers have a very clear cognition of underlying idea.

    • You all : English does not have plural second person pronoun but that does not mean english speakers can't address to the crowd.
    • Inclusive/Exclusive We: My language has different words for "we including you" and "we excluding you." But english speakers know which one is meant given the context. Imagine- On negotiating table our needs are different than your needs but we (all) need to make a deal.  
    • Spanish has words for here, there and 'over there'. Well we have a phrase 'over there'.
    Multi lingual people may still have some rough edges in their "inter language". But they very well guess and know who is doing what to whom , where, how etc they may  misunderstand but that is because it is lost in the translation. Some times the translation is not loss less. Okay the passive voice can be used strategically to obscure the facts or emphasize different aspacts.

    Conclusion
    Each language seems to creates its own set of potential ambiguities. 
    Eg. What does the english 'you' mean? - just you OR you and your family?What does 'We' mean?
    That only means that people need to use extra word or two to clarify when context requires so.
    But Lera is wrong - at least that is what I thought based on her article.


    posted by Sachin Joshi

    Wednesday, January 19, 2011

    Why we are supporting Agile Manifesto


    Process of creating software is a unique human endeavor and is unlike any other engineering. It requires its own value system. Without the proper enlightenment and clarification of our values, as Confucius once said, it is really hard finding a black cat in a dark room, especially if there is no cat. Thus far we were behaving like those proverbial blind philosophers trying to describe the beast called “Creating Software”.

    Software is unique: 
    Software is unique because it is often a force multiplier and catalyst in the context of organizational dynamics and its financial goals. Often the processes, protocols, jobs are redefined around the software systems. It is not just yet another cog in the machine- It actually changes the machine itself –often radically!

    Software is unique because by definition it requires rigorously accurate coding for a machine that is unforgivingly obedient in reproducing your misconceptions and defects in the implementation that you failed to catch and correct.

    It is unique because software is more about negotiating the shared meaning and understanding of the problem.
    Software Creation is a future oriented creative activity full of possibility and potential. It unlocks creative force within people by automating all that dull work, turning hard things easy and making impossible possible.

    You say – “Okay may be software is unique. So what? 

    Why do we need a Manifesto?”

    Sometimes if the only tool you have is a hammer then every problem looks like a nail! We have been applying wrong models to Software engineering all along.  Software is not construction or mechanical engineering. Software is not like manufacturing either. Our model was as wrong as that of a flat earth at the center of the universe.

    It is an old saying- Give man a fish and you’ll feed him for a day. Teach him how to fish and you’ll feed him for lifetime. We can blindly follow detailed prescription that is unsuitable or simply wrong OR teach ourselves to understand our unique environment and adopt best practices to our unique situation and goals.

    Agile Manifesto gives that deeper insight and teaches us the profound knolwdge. Its simplicity is similar to the profound insights of Sir Issac Newton in formulating simple laws of motion and gravitation. Its embrace of ultimate truth is similar to the Einstein’s theories based on accepting the truth that light is simply unique- unlike any other.

    We have been planning the work and working the plans and getting things done right way.
    It’s time we start doing the right things instead. We fully support Agile Manifesto.


    posted by Sachin Joshi