Showing posts with label Code is design. Show all posts
Showing posts with label Code is design. Show all posts

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.

    Thursday, March 3, 2011

    10 Myths about Writing Design Spec/Doc







    In my last post we explored how Code is Design and How Design Spec is Muda (waste).
    Idea I'm presenting is simple: Code itself is design.  Writing traditional software design docs describing details like API/class level design is just  a sheer wastage of time and money and is plain irresponsible. (And plain immoral to keep writing them knowing that it is not useful at all).
    Again  I'm reiterating the simple mantra : code itself is design.
    • We have sufficiently high level object oriented and functional programming languages.At the same time our libraries are getting smarter and richer. Templated data structures and algorithms add set of powerful tools.
    • It takes more time to write a design document than to write some code that actually embodies and expresses that design.    
    • We need to keep improving the code and keep refactoring. Experimentation is reality. 
    • Everyone who deals with code must understand code so make code understandable and comment it well.
    • Among the many advantages of co-locating extra explanatory description with code itself is that it is always in sync with code, versions are tracked with code. 




    Correct Alternative to Writing Design Documents

    Here is a simple alternative - it is simplicity in itself and magically effective at the same time. 
    1. Write actual classes and methods stubs in code and write header comments for them. Don't worry about logic yet - just simple return statement returning in method body is good enough. However, if your language supports it then add pre and post conditions (i.e requires/ensures) or the equivalent asserts in the empty method body. 
    2. Build them. Make sure you have document generation enabled. With modern tools like ndoc or javadoc all the information about parameters and classes is then generated automatically. 
    3. Now check in the new code (may be in a dev branch). Now ask other developers/testers to take a look at the generated documentation, better yet ask them to look at your code. Ask them to use the class.

    One thing to always keep in mind is that at this point our code is not production ready, bug free or complete - or anything like that.It half baked , unhardened and fluid. And certainly not set in stone. It is in a flux. You can change or refactor your design.  But it is compilable without errors and commented very well.


    Debunking the Design Myths
    MYTH 1 : Design specs/docs/models must be written for class or API design.
    What is better than actually having a compilable stubs for classes and methods? It has all the same information that design spec, possibly even more .
    • If people asking for API design docs can't understand actual method signatures with parameter details then they should shouldn't be asking the design doc in the first place.
    • Stub methods are super useful because they can be built and then actually used in other code. People can actually try out your design. Unlike the design doc your code is executable. 
    • Intellisense works with your "design"
    • Tools can tell you if your comments are missing or not in line with actual method parameters.   
    Don't write word docs. Write actual class and method stubs. There is nothing better than executable design i.e code. It takes more time to write a design document than to write some code that actually embodies and expresses that design.

    MYTH 2:  Design spec helps with early feedback.   
    Wrong! You won't generally know if your design is right until you have used it. (Otherwise why ask for the feedback in the first place.)
    So to repeat my mantra: Don't write docs write stubs for classes
    Once you have checked in the stubs and ask others to use it in their code. There is nothing better than trying out your code with couple of samples. Ask others to try out you code and ask for the feedback on completeness, ask how it feels to use you design.
    Last but not least, write samples yourself and share them.

    • Now or later ultimately other must use your classes/methods. So why not use the stubs right now to see if design can be improved. 
    • Others will often make suggestions based on concrete things like "Can you return an List<Foo> instead of Foo[]? because it's hassle converting and casting all the time". 
    • Test team and you yourself can start writing the unit tests and acceptance tests, which further clarifies the design and actually helps you understand the intricacies. 
    • If you add preconditions, post-conditions and invariants then that is yet another way to comprehend the design. You can even force compiler + static analyzer to give you some feedback.
    • You can run the automated tools like FxCop and others to see it you are confirming to the design patterns.
    None of this is actually possible with design document.

    MYTH 3: Design spec explains how code works.
    Absolute bullshit! 
    • Comment your code well and people will comprehend your code. There is nothing better than actually reading the code to understand code.
    • Choose descriptive names and make an effort to write very clean code. When you make a hack. Put comment. 
    • If you are using design patterns then choose names to reflect that. Let the code speak for itself. 
    • In class description write bullet point description of responsibilities and collaborations. 
    •    
    Here is  simple trick that can solve most of your documentation problems as well as coding problems. Write some pseudo code in the method body first. Now for each step in the pseudo code write the actual code leaving the original pseudo code in comments. 
    Good developers should be able to read the well-written and well-commented code and mentally walk through it. So spend time writing clean beautiful code rather than pretty word documents.

    MYTH 4: Design doc needs to be written before the code.
    One of the purpose of the design doc is to make sure that maintainers understand how code works. Instead of worrying about the design doc before writing new code. Take some time to comment and clean the code after you are done writing code. That will bring more rewards that writing stupid design doc that gets lost. 
    • If you write public APIs then obviously you can write 'higher quality' documentation after you have fixed all the bugs. For that matter it doesn't make sense to release a design document before the product itself. So ideally write design document after your code is written, tested and ready to ship. It has better chance of reflecting how code actually works.
    • If general population is not going to see design documentation then don't waste time writing one. We already know that combination of code stub and a few tests is far better than API design doc in getting feedback. 
    MYTH 5: When you have external dependency or you are someone else's dependency you need a design spec.
    Create two assemblies one for defining interface and other for implementation. Code the interface assembly first.Write some sample usage code. Give them interface assembly and samples, get feedback on it.

    MYTH 6:  Test team needs design spec. 
    They don't. They need list of scenarios to test and actual classes/method that they need to test. It is better to give them compilable stubs so they can start writing tests. Now you can actually use them TDD fashion!  All the testing team needs to do is to understand what code is supposed to do and actually reading the code to search for bugs. Don't waste time reading and writing design specs.  To repeat what has already been said before: design by contract, asserts and unit tests can only be added and tested against the real compilable code not against the doc. In addition, writing acceptance tests can actually be used to drive design.


    MYTH 7:  Big software needs big teams and therefore detailed design specs.
    If you are writing monoliths you have a bigger problem than simple design specs. 
    Ideally your software is modular and component based, which means small teams can independently build components as long as interfaces are well-defined. 
    This means 

    • Strict separation between interface and implementation. Consumers of your interface should not be forced to know internal details of your design. 
    • Define assembly containing interface, again don't write design docs write the interface code and generate help files from the inline comments. 
    • Share the interface code with others. All the things we talked about writing code instead of docs still remains true. 


    MYTH 8: The is extra information that can not be explained in code.
    This is actually not true. Most of the information falls into one of these groups

    • Structured information closely tied to the code. This can often be integrated using custom tags. Eg. Class-Resposibility-Collaboration can be expressed using <responsibility> <collaboration> tags. Similarly for the things like algorithmic complexity.
    • Higher order design information like grammar, patterns and state machines which is often expressed at higher level for tools like yacc/lex/bison , make etc.  All these are just 'code' so you can always comment it.
    • Details about why particular data structure was used or why particular algorithm was chosen. I think you can always add this kind of extra information at the appropriate comments at the right place. 
    • Database design results in bunch of tables and queries which again is better expressed with well commented SQL code.
    • Modern UI design is based on declarative languages, once again can be just well commented code.
    MYTH 9: Design document can be shared,tracked better through collaboration tools.
    You seriously believe tracking commented code through SVN, perforce etc is somehow inferior to tracking it through any other way? People can still use the collaboration tools to review the code changes.  

    MYTH 10: There are others who don't deal with the code itself but still need design spec.
    No there is no one like that generally. Check your assumptions. Either they are blindly following the ritual or they need some completely different piece of information that design document could not possibly have provided in the first place.
    People who don't read, write or consume code on everyday basis do not need to know about any internal details about it's design. What people need is an one page overview document can be written after code is written,tested and ready to be shipped.




    Conclusion : Code is Design. Start writing code instead of design documents.

    Tuesday, March 1, 2011

    Lean Wisdom: Software Design Spec is Muda





    Goal of any software is to create customer value. Aim of Radical Programming is to create order of magnitude improvements in returns on the efforts required to generate that value. There are two obvious ways of achieving that: increasing productivity and reducing waste. 

    Waste reduction is an effective way to increase profitability. The lean thinking originated at Toyota Production System. It is based on the idea of reducing three types of wastes viz. muda ("non-value-adding work"), muri ("overburden"), mura ("unevenness").
    There is nothing so useless as doing efficiently that which should not be done at all. 
    -        Peter F. Drucker

    Mistaken Identity
    For a long long time our industry has mistakenly borrowed construction metaphors. Result is our desire to write up a design document or complex graphical representations like UML. 
    In other industries like mechanical production or civil construction, we actually need physical (hard) material to build each new unit. This production requires workers, materials, tuning assembly lines, takes time and costs money. There is an inventory of physical things to manage. In a nutshell, production is a big deal. Mistakes in design cost money, rework and lots of pain. It is not simply a matter of undo a checkin it is lot more painful. If design of your car chassis is wrong, you'll actually have to recall vehicles and melt the car back into the steel and start over again.
    Now if you could find the problem before going into the production all you have lost is just time required to design that thing. That's why proper design is important and why 'building' is lot bigger deal than designing. 
    Compare all this to how we 'create' software: We start our "build' which in turn calls compilers. Once we have binaries we then 'publish' them- Ready for people to download (or copy) and install. It probably took us only a couple of minutes. From this point of view software construction is free! Remember we don't ship code, we ship binaries! If you found the problem before going into production all you lost was developer's time. If you have found a problem after production release you can release a critical patch - it won't be fun but you can at least fix it. Building software is nowhere close to building a car or a dam or a space shuttle or a microprocessors. Just type in make (or ant or nmake) and you have 'made' the software.

    Blueprints  
    Whenever we think of a design it reminds me of a blueprint. In 'hard' engineering designs are important. They really are. You can't argue with the fact that blueprints are absolutely essential to construction. Say we want to build a house.  I hope you agree with the sentences in bold italics (Remember these as you read because we are going to see if exact statements are equally true with software design.)

    • We want to make sure the architects and structural engineers we are hiring are professionals. That they have tested their design. That they have stress tested it for earthquakes, winds, snow on the roof. That they have made sure that it adheres to the building code.So on...design can be analyzed using different models.  
    • Once they create a viable design or a blueprint, from that blueprint they can estimate how much material they need. Project engineers can then create a project plan Eg.When to start laying foundation, when structure is erected, when flooring is done, when to paint etc. Each step takes time and really can't start before it's prerequisites are complete. In theory you can build a house one room at a time but that doesn't make much sense. So they plan the work for the entire house. They will then hand the blueprint off to the contractors, who will actually build them. Things can not be built randomly we need to understand dependencies between various stages.  
    • Going into Production is a big deal. It is a point of no return. Having good design before hand is important. Because once you start building, you can't correct design defects.
    • What about Design changes before going into production? They can of course change the design thousands of time before going into production. If something is wrong with the design like there are too many stresses in the beam or something like that they can change it. They can go through iterations until they resolve most of the engineering problems. There can be thousand iterations with the design itself and no one will complain, in fact it is encouraged.  
    • Again we want to customize our house. You know what I would like? I would love to see a 3D model so I can make suggestions. Shuffle rooms around, move columns around , change where I put doors and windows. Most of the times we can accommodate these things by changing design. Early in the game, showing mockups or models (i.e prototypes) to the customers is helpful.  
    • But at some point I need to stop and sign off on a final design. We now have a blueprint we can use to 'produce'/ 'build'/'construct' dream house. We need sign-offs only because construction can not begin before we finalize design.   
    • Now what is the best way to communicate a design ? Write up a design doc ? No! You draw a blueprint. Contractors, electricians, interior decorators, inspectors all communicate though blueprints. Why blueprint? Because that's the most natural way to communicate 'design information'. It is precise and "executable". Of course you must be able to read and understand blueprints but then everyone in that profession can do that. With medium like that you don't need yet another document describing the blueprint or design. Blueprint (i.e. Design) itself is actionable, quantifiable, measurable - it is executable.   

    But dude, for software engineering - Code is the Design!
    With the modern object oriented programming languages like Java, C# or C++, a well commented code is like a blueprint. It is self explanatory. You don't need a separate design document. Software Design Specification document is a Muda (waste) that needs to be eliminated.

    • It wastes valuable resource - developer time to write and review it.  
    • It is often stale, out of date and out of sync with the actual implementation.
    Assuming you write modular and component oriented software, all you need is a very high level overview of  what each module/component does and the actual code for it. No need for design spec! If act of coding itself is a design then all the following is still true. Except one thing production is not at all a big deal.
    • design (aka code) can be analyzed using different models. Eg. static analysis, code inspections, memory and time complexity, 
    • Things can not be built randomly we need to understand dependencies between various stages.  Yes indeed. That's why we right complex make files and build scripts. I'm not cheating here. We really do need to understand dependencies and a plan to 'build' software. It just happens that actual building is cheap.
    • Going into Production is a big deal. It is a point of no return. If production is 'building'- no big deal. If it means 'deployment', Yes big deal - but then we are not going to release software until we thoroughly test it.
    • There can be thousand iterations with the design (aka. code) itself and no one will complain, in fact it is encouraged. Refactoring? TDD?
    • Code (i.e. Design) itself is actionable, quantifiable, measurable - it is executable

    We should not waste time writing design documents. We should start coding. Because CODE IS DESIGN