Tuesday, April 26, 2011

Applying Radical Programming: Software is a Batch Process

Before applying the lean thinking to software engineering we must understand what are the concerns that lean thinking tries to solve and where exactly process of producing software fits in. 
See my earlier post What is radical programming? if you want and introduction to Radical Programming.

Mass Production vs Mass Customization 
Unlike craft production mass production relies on the standard components and economy of scale. Each unit is like every other unit and  parts are interchangeable. The assembly line can increase the throughput but then it becomes very difficult to change and to customize. 
On the other hand the more customization is required the less standard and costly the production becomes. Why is this relevant to software engineering ? That is because each software system is unique we have a need for high degree of custom software development and at the same time we need to bring in mass production techniques. 

User Story (Use case) is the unit of software production. 
In Radical Programming we treat user story as the unit of production. Our output is measured in terms of number of user stories implemented. We imagine an assembly line where a user story starts its life as a simple statement of user need which is developed into full set of acceptance tests and lightweight use case. It is then translated into design delta and finally implemented, tested and integrated. Individual user stories are the basis of calculations to make production decisions. 

Process Types 
One of the most critical factor in implementing efficient production system is to identify the process type that best achieves the tradeoffs between quality , time and flexibility.
There are five types to choose from

  1. Project Process - There is a high degree of customization and very low volume . Which means each project is unique. Flows and dependencies are very complicated.
  2. Job Process - Even though it is customized the volume is high enough. Which means each job is not as unique as project. Each new order is handled as a single unit and produced made to order. Flows and dependencies are jumbled. Examples are your doctors's visit, jobs with car mechanic, process for auto loan approval. Variety is achieved through "made to order" strategy.
  3. Batch Process: There is high volume and variety is achieved through "assemble to order". Most importantly items are produced as a batch. Some intermediate products might be pre-processed.
  4. Line Process: Volumes are very high. Fast food services and car assembly lines are examples of line processes. There are line flows with very little inventory held between operations.
  5. Continuous Process: It requires extremely high volume and very generic standardized product.
Software as a batch process with Time Boxing 
Like Scrum the radical programming achieves its goal using series of scrums. In radical programming we treat the software production as a Batch Process where we produce batch of user stories each iteration.

by Sachin Joshi
for Washington Technical Resources

Simple theory of Management: 8 Ps

I have a very simple theory about what senior managers need to do.  There job is to convert potential into profitability through internal and external interaction
And that means specifically managing 8 Ps described below. Call it "Sachin Joshi Model of Management" if you wish.
Discussion is more relevant to executives and other senior managers who in my vocabulary are called "business owners".
Financial Perspective 

1. Profitability : The reality is that businesses need to keep themselves profitable which means managers must take right financial decisions. At minimum it means managers must be financially  literate. Beyond budgeting and forecasting there are many decisions that require using finance/accounting tools. Selecting the right project size and team size. Pricing the products. Making buy vs build vs rent decisions. One of the most useful concepts are   Minimum Marketable Feature and idea of Real Options.   
External Perspective
2. Positioning : Nothing is so critical than finding the right fit to market and positioning the products in a market place. Nothing succeeds like an idea whose time has come. Your talent as a manager is in finding that right idea. The entire process of dividing the markets in right segments, selecting the right customers and solving right set of problems for them is all what I call "positioning". It requires making right decisions all the time. And that doesn't happen without instituting the customer focus. Customer focus is not some magic thing you do but a value system and tool that results in a well defined procedure for "positioning" your service.
3. Partnerships: No business works in isolation. So yet another job is to manage partnerships with vendors and clients.
Internal Perspective
4. Programs: Many managers make mistake of thinking that what they are delivering is product or a project. But in reality what they are doing is managing series of projects and set of products which requires Program Management. Defining and managing program objectives is a top item in job description of senior manager. A successful manager must be able to map strategy into programs and then translate the vision in terms of program objectives. (I plan to write a blog about mapping strategy into program objectives.)
5. Process : No software gets built without proper process in place. One of the important jobs of manager is to define process and actively manage it. There is a large body of knowledge dedicated to project management and process improvements. Wisdom and drive in applying these principals to increase quality is what managers demonstrate everyday.
6. Policy: Make sure that technical standards are defined and followed. Rather than actually making each and every decision themselves senior managers define policy. To me policy is framework in which those decisions are made.  One of the most important job of managers is to define that framework and provide guidance in applying it to everyday decisions. 

Growth Perspective 

7. People: The generative power of business comes from the talent and creativity of its people. And no where is this more important than in software. Success in providing the environment where people can grow is how we must measure our progress
8. Productivity : Equally important is increasing our production capability or "Productivity". Smart tools turn smart people into even smarter geniuses.   

by Sachin Joshi
For Washington Technical Resources

Tuesday, March 22, 2011

Speech Technology : Phonology

Words  are formed by series of syllables which re formed by series of phones. In last blog we looked at the Phonetics and how variety of  speech sounds are generated.

Contrasts, Phonemes and Allophones
We already looked the variety and variations of the phonetic elements. But not all sounds are used by all the langauge. Most importantly not all sounds are distict in the same langauge. Consider ph and p (aspirated vs non aspirated). This distinction is not important in english but extremely important in indic langauges. Similarly indic langauges have two D's one dental and other palatal. English has mostly alveolar where as spanish has mostly dental. If indic langauge has vast number of consonants the english langauge has many finer distinctions betweeen vowels.  The point ? What makes two sounds similar or distinct really depends on the langauge. From speech technology perspective this distinction is important because speakers may not articulate sounds exactly like each other when that distinction doesn't matter. Whereas when speech recognition fails to distinguish the sounds when they should it is a problem. 
When two or more phonetic elements are distinct but map to the same phoneme it is called allophones. One of the most striking example of allophones having distinct value is "visarga" in Sanskrit where 's' and 'h' are equivalent to each other. Similar historical allophone is hard 'g' like in gut and soft 'g' as in ginger. That is exactly the reason why we have letter 'g' used for two completely different sounds. At some point these sounds were considereed close to each other and therefore allophones of each other.

Structure of Syllables
Sounds are either 'singable' meaning they are sonorant or not. Vowels, nasals and liquids are singable.All others are not. Sylables almost always have sonorant sound at the nucleus.
Syllable is formed by   Onset+(Nucleus+Coda).
Not all combinations are relevant. Some langauges allow many constonants in onset while others can not handle it. In every language there are some obvious constraints on what words are valid and what are non-sense. We must understand these constraints.

Once we understand all this our next task is to actually group the phonemes into sylables.

Stress, Mora and Syllable timed languages
In a stressed langauge like english or russian each stressed syllable takes about equal time. Where as in other languages like Spanish or most of the indic languages the syllables are timed equally. The mora based langaues are yet another way of timing the phonemes.

Yet another complication is formed by what is called Sadhi in Sanskrit and Liasion in French. I have studied Sanskrit for three years and I know first hand the pain of "breaking" the Sandhi and coming up with individula words. I won't go into all the details but all of us in all of the langauges merge words while talking and we must be able to separate them when recognizing the speech.

Sunday, March 20, 2011

Speech Technology : Phonetics

Last year around this time I was working on one of my projects related to speech recognition. It was a personal side project and I really did not give the project enough attention. Plus it had been a long time since I had seen stuff like Fast Fourier Transform and I kind of procrastinated .Well - it is time to again start where I left and true to its original meaning - blog. This is a series of blogs is where I speak whatever is on mind about speech technology, phonetics and various options available for implementing it. 
I first got introduced to the subject of phonetics back in 1992. I was in college and used to visit my aunt every weekend. My uncle used to teach Communication Skills  in a technical college. He must be having a couple of dozen of books on english language and teaching english. While going through his bookshelf  I found a book on english sound system. That was the start of a fascination for phonetics and languages. My dad also had bought all volumes of Marathi Vishwakosh (Encyclopedia) which I used to read a lot in my free time. (And I had a lot of free time back then). I then read about phonetics and grammar of my language and about human language in general. That fascination still remains ...     
The language ability of our race has made us the only species able to successfully transition to civilization. Every human being has capacity of language and it is impossible to think of human society with out language. 
[Without language we would be still in sub saharan desert and probably extinct by now. As a side note please do watch   Journey of Man if you get some time. Anthropology is yet another subject I am fascinated with.]
How human voice is produced.
Human speech articulation begins in the larynx. The vibrations created there are modified through out the vocal tract which ultimately comes out of the mouth as series of sounds which we understand as sequence of phonemes. Larynx is where the "voice" starts but that sound is progressively modified in the mouth by forming various shapes with our tongue and lips. I have modified the standard diagram to show the schematic of the vocal tract. 
The most important key concept is this: Our tongue is a very flexible muscle that can form various shapes and that profoundly affects the way we perceive the basic sound that begins at the larynx. 
[Edited from original here : http://en.wikipedia.org/wiki/File:Illu01_head_neck.jpg.]

That brings us to the next concept. There are two types of sounds viz. vowels and consonants.
When the airflow from larynx is not obstructed we perceive that sound. Anyone how has dealt with waveform of human sound knows that most of the waveform is basically sound of vowels. However the most interesting sounds are generated when the airflow is blocked (or substantially modified) for the brief amount of time. This time frame is seriously tiny compared to rest of the vowel sound and we perceive it as consonant
In terms of digital signal processing the waveform of the voice that starts in larynx is modified by the resonance of the vocal tract and therefore we apply the convolution of the simplified model on the right side.

Vowels take most of the time in speech signal. All consonants are meaningful only in the context of background of robust vowel signal.  The larynx is actively producing "voice" during the vowels.
The quality of vowel depends on  four attributes.
  1. Height of tongue position- In other words whether the gap between tongue and roof of mouth is closed or open. generally four positions are considered. Open, Open mid,Close mid and Close.
  2. Position of tongue - Front, central or back
  3. Roundness of lips - The roundness of lips add another effect.  They are generally rounded for back vowels.
  4. Nasalization ? are the vowels nasalized.
Below is the list of known vowels and their IPA symbols.

Edited from original here : http://en.wikipedia.org/wiki/File:IPA_chart_2005_png.svg

The best way to analyze vowels is to look at their frequency spectrogram and look at the peaks. The first three formant are specifically interesting. The roundness of lips changes the positions of formant.
Again there are further diphthongs and glides that are combination of  two vowels.

 The consonants are interesting because they are numerous, show great variation in how they are produced and the signal is available for only the short time. They are "negative" because the voicing and vowel are interrupted or blocked by the position of tongue. Here I am going to use somewhat non-standard terminology and classification only because that is how I understand it. Also because i was introduced to the subject via Sanskrit Grammar.
There are three main things to look for - (A) Properties of original sound that is obstructed (B) manner in which the air flow is obstructed/modified
(C) place of obstruction/modification
Properties of original sound
  1. Voiced vs Unvoiced - whether voicing continues or not . [b -p]. [k -g][t-d] are some examples . (saghosh and aghosh.सघोष- अघोष )
  2. Aspirated vs Non aspirated - this difference is important in Indic langauges it effectively doubles the consonants available for use in languages.   (alpa prana- maha prana अल्पप्राण- महाप्राण)
Manner in which flow is obstructed /Modified
  1. Stops - The airflow completely stops
  2. Friction - Sound produced by friction is introduced in the mix.
  3. Affricates - these are combination of stop, followed by the friction at the same place.
  4. liquids - sibilant and approximants - where air flow is partially blocked
  5. Nasals - the airflow goes through the nasal channel
Place of articulation

  • Labial 
    • Bilabial
    • Labio-dental
  • Coronal 
    • Dental
    • Alveolar
  • Palatal 
    • Alveo-palatal
    • Retroflex
    • Palatal
  • Dorsal
    • Velar
    • Uvular 
  • Radial 
    • Pharyngeal /Epiglotal
    • Glotal

Edited from original here : http://en.wikipedia.org/wiki/File:IPA_chart_2005_png.svg

Common Tasks in Speech Recognition
  1. Audio signal capture
  2. Spectral Analysis
  3. Phonetic Feature Identification
  4. Phoneme Identification
  5. Phoneme to word translation

Friday, March 18, 2011

Does democracy make most people unhappy? Future of democracy

I am a student of computer science, a science fiction writer and I am interested in philosophical discussions every once in a while, so while world is busy transitioning to democracy I started thinking about how computer science , social networking can help usher the democratic utopia. My mind was racing, I started thinking about machine learning, "collective intelligence algorithms", optimization and things like Nash Equilibrium etc..I already had an idea of science fiction taking shape in my head...and BAM ..I realized something very simple.
I realized we have to solve a very basic problem first!

First Past Post Voting or Formula for maximum dissatisfaction?
In many countries the elections are held using what is called first past post method. The person with most votes wins the seat. call it winner takes all. This sounds fair but in a multi party system like India or UK or many other countries there are always more than a couple of political parties and many a times a winning candidate get less than 50% of votes. This means that there are more people NOT liking the winning candidate than the ones who voted for him/her.

Here is an example - there are 4 parties

  • Candidate A - 35% votes
  • Candidate B - 30% votes
  • Candidate C - 20 % votes
  • Candidate D - 15 % votes

Clearly candidate A is winner but also that 2/3 of the population does not like him. 
As if it looks like Democracy makes more people unhappy than it makes them happy !! 
This is not a problem with multi-party system but a problem with vote counting method.

Are there any alternatives? Yes enter Science of  Voting Methods
Science of Voting Methods
There are many voting systems. Some are proportional and preferential.
Please see: http://en.wikipedia.org/wiki/Voting_system
One of the methods that can be readily used is Single Transferable Vote http://en.wikipedia.org/wiki/Single_transferable_vote.  Here the voters rank the candidate with their preference and candidate with most preferential votes is declared a winner. To me this seems like a simple fix that once again makes most people happy Jeremy Benthum style. One of the barriers has been the complexity of vote counting. But with the advent of computerized vote counting it can be easily administered at relatively low cost.

Popular Votes vs Representational Democracy.

This is a pure thought experiment with no relation any country/nation/state what so ever. Let us talk about a 22nd century colony on Mars. Let call it XYZ. The problem with first past post voting was solved long time ago in 21st century. But there are other problems though that need to be solved differently. And that is a problem of representing evenly distributed minority.
Say in XYZ there is a 30% population which is considered minority. But it is evenly distributed. In this case it seems like they will be massively under represented. They can never elect 30% of the representatives- in theory they may get none.    

Bicameral Parliament with a different structure.
One of the invention of modern democracies is bi-cameral parliament/ congress. There is a upper house and a lower house. Generally a upper house has equal (or fair) representation for each state/province. However theoretically this need not be the case. A party list system where an entire country votes for their favorite party can also be used. Each party gets the seats proportional to the aggregate votes they receive in election. In this example instead of states sending delegates, parties send their nominated candidates.  In this minority can be always get their say.

Tri-cameral parliament ?
Many people will object to the idea of changing the upper house. But how about adding a third house which is popularly elected?  Let's call it middle house! Instead of two houses passing the law three houses will need to do that. Well that sounds complicated but the idea of "double majority" is not far from it.
Responsible Executive and Separation of Concerns?
There are two styles of democracies - Presidential and Parliamentary. In parliamentary system there is no clear separation and in presidential system no clear accountability. We can actually solve these problems by merging the concepts with president being responsible to lower house and only middle + upper house acting as legislature. Lower house still has the budget!

Well, well !! That's enough for now. Political science is not a subject of this blog we are only interested in the algorithms for voting system so we'll leave all that undiscussed and unsaid and let the people from 22nd century figure out tri-cameral parliament. 

Democracy of the future.
So how will democracy of the future look like ?

  1. With instant communication and tele conferencing do representatives need to be present in the "house" ? Or can they just "log into the parliament" to cast their vote and participate in a debate.
  2. Is law making in Open Source style possible ? 
  3. Can there be a one big direct democracy?
  4. Can a giant computer cluster solve the optimization problem of representing most people with least amount of representatives? 
Really how will future democracy look like? 

Disclaimer : This is a blog related to science, computers, philosophy and its intersection with the society. I have not expressed any political views here. It is from pure theoretical perspective and as an interesting computer science problem. This is not a place for flame wars and random comments. Intellectual discussions and comments are welcome. But if you express your political views those are yours not mine!  

Thursday, March 17, 2011

What is Radical Programming?

What is Radical Programming?

It is a post-Agile software construction methodology which aims at order of magnitude improvements in value delivered through software projects.
The word radical has a Latin root radix.
Webster defines: (1) proceeding from root (2) fundamental (3)unusual (4) cool.
In that respect it recognizes that the primary source of all the value ultimately created through a software is the source code itself. It recognizes that root purpose of the software is to satisfy customer need.

Eight-fold way of Radical Programming.
Aim of any software is to create customer value. Aim of Radical Programming is to create order of magnitude returns on the efforts required to generate that value.
The eight principles of Radical Programming work together to achieve exactly that.
In today's fast moving world with multi faceted sales channel Software Product Line Engineering is the most sensible option. It creates multiple differentiated versions of product by using the same underlying code base and repository of components. As you can see it is component oriented reuse. 

1: Four Quadrants
Radical Programming uses a variant of Software Product Line Engineering that simultaneously undertakes parallel activities in four quadrant.
  • Quadrant I : Creating and discovering  Domain Model. All prototypes, spike solutions and various differentiated product versions reuse the same object oriented domain model.
  • Quadrant II: Product Assembly.Various differentiated product versions are constructed using iterative development. Rapid delivery of customer feature is the primary aim. The secondary aim is to achieve maximum reuse possible.
  • Quadrant III: Creating Platform code. Most products require common infrastructure and we spend significant time in developing productivity tools
  • Quadrant IV: Aspect Orientation.We also spend significant time taking care of global and cross cutting "aspects" like performance, security ease of use etc

2:Value Streams

Applying lean thinking to Software Engineering it envisions the assembly line where features are continuously "manufactured". A feature starts it life as user story and goes through various development stages of acceptance tests, precondition, post conditions, detailed description and test , design, implementation , unit tests and is finally released. Radical Programming considers software delivery as a Batch Process. Scrum and Kanban are used to deliver  the batch. Body of knowledge developed for lean thinking and batch management is then systematically applied.

    3:Code is Design

    Radical Programming treats Code as the primary expression of Design. It uses code centric approach to development where unnecessary documents are eliminated. Various techniques and concepts like Static analysis, Literal programming and Design by Contract are used. Code is re-factored mercilessly. 

    4:Standard Architecture

    One of the ways to achieve great flexibility and productivity is to use standard architecture with predictable interaction between components. N-tier service oriented architecture or plugin based architecture or pipeline like architecture. Emphasis is on implementation agnostic interfaces and loosely coupled interfaces so that components can be readily interchanged. There are many many design principles that can be seen in existing systems and design philosophies. Eg. Unix Philosophy, COM, N-tier SOA with REST etc, Many "component oriented" CMSes.  

    5:Data Driven Design

    One of the main principles of Radical Programming is to use data driven programming. This means program logic is driven by configurable data sets. Every argument that can be made for DSL is equally valid for data driven programming.

    6:Fractal Time Boxing

    Time boxing is a familiar concept, however time boxing is applied to various time horizons and product definition and planning is handled only at the appropriate level of details. Vision is defined on 1-3 year time horizon, the mission and strategy is calibrated every quarter and quarterly goals are achieved by series of monthly/fortnightly releases. At every "scale" the process looks similar because we deal with uncertainty, deliverable and work to be done at only the appropriate level of details. 

    7:Spiral Development

    Spiral development is different than iterative development. In the context of Radical Programming it means within a sprint product is developed by first building it in big chunks and refining it again and again. Rapid development and progressive elaboration is the mantra.

    8:Flexible Team Structure.

    In short it is a self organizing team with collective code ownerships and lack of silos. Developers sometimes wear SDET hat and sometimes volunteer to drive issues like product wide secuirty/performance etc. Load balancing is the matra.

    12 Management Books That Changed How I think

    Today I had an interesting discussion about difference between Leadership and Management.
    So far the best way to describe it is : Managers do things right way and Leaders do the right things.
    Management is relatively easy to define it is set of skills and principles that a person exhibits. In theory leadership is also a set of skills but it is hard to define and there is a continuum from management to leadership. However it is hard to precisely tell when management ended and leadership started.
    For now all I can say is that "I know it when I see it".
    Subject of management and leadership is confusing because it has three distinct and but related components

    • hard skills 
    • soft skills  
    • envisioning skills.

    Like many others I have my theories which I will be blogging about from time to time.
    To me it is pretty simple - If I am right, people will tell me which should feel good. But more importantly
    people will tell me when I am wrong! and that is far more valuable!!

    I am a avid reader and for last 20+ years I have been reading books on subjects related to management for one reason or other. I never aspired to be a great manager or anything like that but somehow I always extremely interested in three subjects :  Economic, Philosophy and Management !
    Below are the 12 management books that changed the way I think ...here you go... in no particular order...

    12 management books from my personal library that changed how I think.
    1.   First, Break All the Rules: What the World's Greatest Managers Do DifferentlyFirst, Break All the Rules: What the World's Greatest Managers Do Differently
    Theme: The author introduces the concept of 12 central questions and 4 keys to handle them. The keys are Selecting for talent,define right outcomes,focus on strengths and finding the right fit.
    First Encountered: 2001
    Why I like it: In simplest terms it presents the issues in terms questions to which I as manager must find the answer in the framework of four keys.Instead of nebulous concepts it gives me blueprint for brainstorming. I find a lot of similarity between behavioral interviewing and the method author suggests.
    How it changed my thinking:  Before this book I was clueless, I had read books about competency matrix but could never put them into the context of how to "actualize" that knowledge. 

    2. Successful Manager's HandbookSuccessful Manager's Handbook

    Theme: The book sees management as set of skills along multiple dimensions like administrative skills, communication skills, interpersonal skills, motivational skills and organizational knowledge etc. 
    First Encountered: 2001 
    Why I like it: Coupled with models like situational leadership and "Beginner-Proficient-Expert scale", the skills competence model is actually a great way to assess and develop skills. 
    How it changed my thinking: Although people are more than sum of their parts, it is extremely helpful to have tool in hand that helps us understand various dimensions of management skills.   
    Other related books I liked: Successful Executive's Handbook

    Theme: This is an excellent book that explains barriers to communication, active listening skills. It also teaches assertive and conflict resolution skills
    First Encountered: 2001
    How it changed my thinking: For a techie guy like me bubbling with enthusiasm for technology and propensity to be a straight talker I do sometimes feel like I sometime talk more than listen. A book that every techie should read at least once because at the end of the day we do have to live with people. 
    Many years earlier I had read book on body language and another one on emotional intelligence. I know this subject is important but frankly I am so involved in conversation when I talk I forget most of the stuff  or at least not consciously aware of any of it. 


    Theme: The book catalogs 30 profit patterns and strategic moves that help follow migrating value. It is a great book for anyone interested in understanding strategic landscape.
    First Encountered: 2000
    How it changed my thinking: I was impressed with Design patterns book and knew about various business models out of hunch I searched for "profit patterns" and voila stumbled upon the greatest concept. After this book I read Value Migration: How to Think Several Moves Ahead of the Competition. I have deeper appreciation important competitive forces and the patterns in strategic landscape. Blue Ocean Strategy: How to Create Uncontested Market Space and Make Competition Irrelevant seems to be the continuum of this concept. I also like Hypercompetition because it's new 7-s really are relevant in a hyper competitive area like Software.

    Theme: This is a classic that is still true. It talks about how to compete in fast changing world. 
    First Encountered: 2002
    How it changed my thinking: To me it is the competency model for the organization managing various aspects of its existence. Couple it with Capability Maturity Model and you have a very powerful tool to direct you.

    Theme: Very detailed introduction to project management. Little encyclopedic. 
    First Encountered: 1999
    How it changed my thinking:  It has to be the most important book I read for a long time. Very systematic approach touches every aspect of the project management. Some of the key concepts were matrix organization,  stake holder involvement and project risk management. Now little outdated but changed the way I saw things.  

    Theme: Analysis of 18 visionary companies and understanding inherent cultural DNA that allowed them to succeed and last.
    First Encountered: 2004
    How it changed my thinking: After In search of excellence and thriving on chaos this is the latest book based on how company should think from inside out. It validated my conviction that it is the companies core competence and quintessential "unique" culture that makes company great.

    Theme: This is a hardcore book on managing company finances.
    First Encountered: 2004
    How it changed my thinking:  Financial literacy is an absolute must for successful manager. It changed the way I talk about process, product and business because it forms an essential part of every economic decision. 

    (Disclaimer - I have lost the copy of this book. And title sounds right but not sure if it is the same book)
    Theme: Uses HDBI to describe four quadrants of cognitive thinking viz. analytical  thinking, procedural thinking, interpersonal thinking and intuitive thinking. The key was understanding how managing technical people is fundamentally a different beast. 
    First Encountered: 1997
    How it changed my thinking: First management book that I read in college which specifically talks about understanding technical people and their unique way of thinking. Obviously Software Engineering: A Practitioner's Approach coupled with this book was my idea of software engineering.

    Theme: Various personality types are analyzed across 4 axes giving four temperaments. 
    First Encountered: 2002
    How it changed my thinking: I hope I am better able to set aside my prejudices and better understand and complement other people's talent.

    Theme: Very systematic development of explaining effectiveness through 7 habits and universal principles. 
    First Encountered: 1999
    How it changed my thinking: The most lasting impact was the four quadrants of time management and idea of 30 methods of positive influence. I also liked his Principle-Centered Leadership.

    Theme: This is a first book on negotiation. With the help of principles like separating people from the problem, focusing on interest rather than positions and insistence on objectivity it teaches to create mutually acceptable options and if not then the batna for yourself.
    First Encountered: 2002
    How it changed my thinking: In my mind the negotiation always had a negative connotation and conflict. If you approach problem with genuine and authentic intention to find mutually beneficial agreement then this book is perfect.  

    Be Assertive: Change your (programming) life using power of defensive thinking.

    We use defensive programming extensively.
    In the context of Radical Programming it boils down to three practices
    1. Make no assumptions about the input to your code. Don't trust it to be well behaving. Build a firewall of validation code around your public interfaces.
    2. Use assertions in code to check assumptions.
    3. Test the code thoroughly. Try every way to break your code.

    Murphy's Law

    Murphy's law states that if something can go wrong then eventually it will.
    We can not predict all the ways in which our code will be called. Our assumptions may turn out to be wrong. Code branches you "know" will never be taken are executed. The conditions that must "obviously" be true are far from. Eventually in some case our code will fail miserably. Assertions are our friends.
    Always test your code with debug build and lots of assertions.

    Fail Often, Fail Fast, Fail Cheap.

    Aim of the defensive programming is to discover as many bugs during development as possible. Ideally we should write as many assertions as possible. Initially there will be lots of failures and it will be difficult to get the code to pass unit tests or even the basic scenario running. However once all those issues are fixed they tend to not come back and what remains is a robust code.
    Assertions are basically alternative way of comprehending your code. When your assertions fail in most cases they mean that your implementation is wrong, but sometimes your assumptions/assertions are wrong. Either way you have found a problem and end up in a better place.
    Once you encounter the invalid data, you should immediately stop processing it to limit unexpected side effects. Failure in one place may not be visible until it creates mayhem in other component and results in data corruption. Best place to catch failures is before it starts cascades of failure. A stitch in time saves nine.

    Three types of Checks

    There are generally three types of checks.
    1. Checks that help you during development and debugging
    This is the bulk of assertions that go into debug builds. These are often preconditions and post conditions, loop invariant etc. The important 
    2. Checks that must be part of release build
    Parameter validation is one example. In case of public interfaces you must throw exceptions for invalid parameters so that caller knows what went wrong. If you use just debug asserts the assertion will not fail in release build and continue causing mayhem downstream. There are other genuine conditions where your code can not continue.
    You have to make sure that asserts you use stops execution at the point of failure in release code.
    3. Checks that validate the consistency of  state and data at various points.
    It is important to check internal consistency periodically. For example if your internal data is a tree data structure then it is important to check that there are no cycles. This code is useful as assertions, in test code and even in released code as "feature".

    Self document code with assertions.

    Like unit tests the assertions are part of the active documentation. Every place in your code where you write a comment, think if there can  be a assertion instead.

    Use of oracles

    Oracles are alternative implementations that give the same results.
    If using assertion is perfection then using oracles is divine.

    Fulfill assertion's destiny by subjecting code to testing and static analysis.

    Writing the assertions is only half the story. You must also exhaustively test the code.
    Monkeying around
    Unit tests and scenario tests are no doubt helpful, but it also helps to monkey around your code by actively giving it input that will break it.
    Active Debugging
    It always helps to instruct your debugger to break on assertion failure so you can actually watch your program fail.


    Do not write clever code

    Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?
    -Brian Kerninghan
    Often times the clever code fails because the requirements change and the underlying assumptions are no more valid. Cleverness is based on taking short cuts and to be frank it does "cleverly" use the context to achieve that. But when you add new functionality and refactor that context is gone. And you are left with the broken code.
    The KISS principle viz. Keep It Simple & Stupid is still the best advice.

    Ideas for coming up with great Assertions.


    Toward Zero Defect Programming Writing Solid Code (Microsoft Programming Series)

    PEX is a great tool from Microsoft Research

    More Info