SlideShare a Scribd company logo
1 of 29
Download to read offline
Correctness through simplicity,[object Object],Ulvi K. Guliyev,[object Object]
“…domain of dependable software engineering boils down less to money and more to ethics. Its about your duty as a software engineer to ensure that system is of as higher quality as possible.” ,[object Object],Prof. Joseph Kiniry (Software Development Group) ,[object Object]
How do we think about computation?,[object Object]
∞,[object Object],∞,[object Object],void InsertNutritionalSubstance(List<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],_burps = new List<Burp>();,[object Object],foreach(vardish in dishes){,[object Object],foreach(varfoodItemindish.Items){,[object Object],if(foodItem.IsTasty(bob)){,[object Object],Burpburp;,[object Object],switch(foodItem.Kind){,[object Object],caseFoodKind.Yummy:,[object Object],bob.ConsumeItem(foodItem, out burp);,[object Object],break;,[object Object],					caseFoodKind.Chewy:,[object Object],var timeout = TimeSpan.FromSeconds(10);,[object Object],bob.Chew(foodItem, timeout);,[object Object],break;,[object Object],default:,[object Object],throw new Exception(“Yuk!”);,[object Object],			},[object Object],if(burp != null),[object Object],			_burps.Add(burp);	,[object Object],		},[object Object],else{,[object Object],Environment.Spit(foodItem, bob);,[object Object],},[object Object],	},[object Object],},[object Object],foreach(var burp in _burps){,[object Object],Environment.Release(burp);,[object Object],},[object Object],},[object Object],Branch,[object Object],Loop,[object Object],Loop,[object Object],Branch,[object Object],Side-effect,[object Object],Branch,[object Object],Branch,[object Object],Jump,[object Object],Branch,[object Object],Side-effect,[object Object],Branch,[object Object],Side-effect,[object Object],Meet accidental complexity,[object Object],Meet imperative Bob,[object Object],Loop,[object Object],Side-effect,[object Object]
How do we change thinking modality?,[object Object],We are computers,[object Object],Technology is secondary,[object Object],Intuition and ingenuity,[object Object],Structured roadmap,[object Object]
Roadmap to dependable software,[object Object],Targeted at imperative programmers,[object Object],Focus on reducing code complexity,[object Object],Step by step discovery,[object Object],Meant to alter the way we reason about computation,[object Object]
Correctness through simplicity
Step 1. Procedural decomposition,[object Object]
void InsertNutritionalSubstance(List<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],_burps= new List<Burp>();,[object Object],foreach(vardish in dishes){,[object Object],foreach(varfoodItemindish.Items){,[object Object],if(foodItem.IsTasty(bob)){,[object Object],Burpburp;,[object Object],switch(foodItem.Kind){,[object Object],caseFoodKind.Yummy:,[object Object],bob.ConsumeItem(foodItem, out burp);,[object Object],break;,[object Object],					caseFoodKind.Chewy:,[object Object],var timeout = TimeSpan.FromSeconds(10);,[object Object],bob.Chew(foodItem, timeout);,[object Object],break;,[object Object],default:,[object Object],throw new Exception(“Yuk!”);,[object Object],				},[object Object],if(burp != null),[object Object],_burps.Add(burp);	,[object Object],			},[object Object],else,[object Object],Environment.Spit(foodItem, bob);,[object Object],		},[object Object],	},[object Object],foreach(var burp in_burps){,[object Object],Environment.Release(burp);,[object Object],	},[object Object],},[object Object],Operational demarcation,[object Object]
void InsertNutritionalSubstance(List<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],_burps= new List<Burp>();,[object Object],foreach(vardish in dishes){,[object Object],foreach(varfoodItemindish.Items){,[object Object],if(foodItem.IsTasty(bob)){,[object Object],Burpburp;,[object Object],switch(foodItem.Kind){,[object Object],caseFoodKind.Yummy:,[object Object],bob.ConsumeItem(foodItem, out burp);,[object Object],break;,[object Object],					caseFoodKind.Chewy:,[object Object],var timeout = TimeSpan.FromSeconds(10);,[object Object],bob.Chew(foodItem, timeout);,[object Object],break;,[object Object],default:,[object Object],throw new Exception(“Yuk!”);,[object Object],				},[object Object],if(burp != null),[object Object],burps.Add(burp);	,[object Object],			},[object Object],else,[object Object],Environment.Spit(foodItem, bob);,[object Object],		},[object Object],},[object Object],Burp();,[object Object],},[object Object],void Burp(),[object Object],{,[object Object],foreach(var burp in_burps){,[object Object],Environment.Release(burp);,[object Object],	},[object Object],},[object Object]
Step 2. Single responsibility,[object Object]
void InsertNutritionalSubstance(List<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],_burps= new List<Burp>();,[object Object],foreach(vardish in dishes){,[object Object],foreach(varfoodItemindish.Items){,[object Object],if(foodItem.IsTasty(bob)){,[object Object],Burpburp;,[object Object],switch(foodItem.Kind){,[object Object],caseFoodKind.Yummy:,[object Object],bob.ConsumeItem(foodItem, out burp);,[object Object],break;,[object Object],					caseFoodKind.Chewy:,[object Object],var timeout = TimeSpan.FromSeconds(10);,[object Object],bob.Chew(foodItem, timeout);,[object Object],break;,[object Object],default:,[object Object],throw new Exception(“Yuk!”);,[object Object],				},[object Object],if(burp != null),[object Object],_burps.Add(burp);	,[object Object],			},[object Object],else{,[object Object],Environment.Spit(foodItem, bob);,[object Object],},[object Object],		},[object Object],},[object Object],},[object Object],void Burp(),[object Object],{,[object Object],foreach(var burp in_burps){,[object Object],Environment.Release(burp);,[object Object],	},[object Object],},[object Object],Responsibility demarcation,[object Object]
void InsertNutritionalSubstance(List<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],_burps= new List<Burp>();,[object Object],foreach(vardish in dishes){,[object Object],foreach(varfoodItemindish.Items){,[object Object],if(foodItem.IsTasty(bob)){,[object Object],Burpburp = ProcessFoodItem(foodItem, bob);,[object Object],if(burp != null),[object Object],_burps.Add(burp);	,[object Object],else,[object Object],Environment.Spit(foodItem, bob);,[object Object],		},[object Object],},[object Object],},[object Object],	Burp();,[object Object],},[object Object],Burp ProcessFoodItem(FoodItemfoodItem, ImperativeGeekbob),[object Object],{,[object Object],	Burpburp = null;,[object Object],	switch(foodItem.Kind),[object Object],{,[object Object],caseFoodKind.Yummy:,[object Object],bob.ConsumeItem(foodItem, out burp);,[object Object],break;,[object Object],caseFoodKind.Chewy:,[object Object],var timeout = TimeSpan.FromSeconds(10);,[object Object],bob.Chew(foodItem, timeout);,[object Object],break;,[object Object],default:,[object Object],throw new Exception(“Yuk!”);,[object Object],},[object Object],return burp; ,[object Object],},[object Object]
Step 3. Semantic regression,[object Object]
Code beacons,[object Object],Patterns in code,[object Object],Sequences of imperative instructions,[object Object],Describe how to compute and not computation itself,[object Object],Denote hidden semantic intent,[object Object]
void InsertNutritionalSubstance(List<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],_burps= new List<Burp>();,[object Object],foreach(vardish in dishes){,[object Object],foreach(varfoodItemindish.Items){,[object Object],if(foodItem.IsTasty(bob)){,[object Object],Burpburp = ProcessFoodItem(foodItem, bob);,[object Object],if(burp != null),[object Object],_burps.Add(burp);	,[object Object],else,[object Object],Environment.Spit(foodItem, bob);,[object Object],		},[object Object],},[object Object],},[object Object],Burp();,[object Object],},[object Object],void Burp(),[object Object],{,[object Object],foreach(var burp in_burps){,[object Object],Environment.Release(burp);,[object Object],	},[object Object],},[object Object],Beacon,[object Object],Beacon,[object Object],Beacon,[object Object]
void InsertNutritionalSubstance(List<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],	_burps = ProcessFood(dishes, bob);,[object Object],Burp();,[object Object],},[object Object],List<Burp>ProcessFood(List<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],return dishes.SelectMany(d => d.Items),[object Object],            .Where(i => i.IsTasty(bob)),[object Object],            .Select(i => ProcessFoodItem(i, bob)); ,[object Object],},[object Object],void Burp(),[object Object],{,[object Object],foreach(var burp in _burps){,[object Object],Environment.Release(burp);,[object Object],	},[object Object],},[object Object]
Step 4. Controlled side-effects,[object Object]
Mutable type,[object Object],void InsertNutritionalSubstance(List<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],	_burps = ProcessFood(dishes, bob);,[object Object],	Burp();,[object Object],},[object Object],List<Burp>ProcessFood(List<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],return dishes.SelectMany(d => d.Items),[object Object],            .Where(i => i.IsTasty(bob)),[object Object],            .Select(i => ProcessFoodItem(i, bob)); ,[object Object],},[object Object],void Burp(),[object Object],{,[object Object],foreach(var burp in_burps){,[object Object],Environment.Release(burp);,[object Object],	},[object Object],},[object Object],Mutable type,[object Object],Mutable type,[object Object]
void InsertNutritionalSubstance(IEnumerable<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],	_burps = ProcessFood(dishes, bob);,[object Object],	Burp();,[object Object],},[object Object],IEnumerable<Burp>ProcessFood(IEnumerable<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],return dishes.SelectMany(d => d.Items),[object Object],            .Where(i => i.IsTasty(bob)),[object Object],            .Select(i => ProcessFoodItem(i, bob)); ,[object Object],},[object Object],void Burp(),[object Object],{,[object Object],foreach(var burp in_burps){,[object Object],Environment.Release(burp);,[object Object],	},[object Object],},[object Object]
Step 6. Functional composition,[object Object]
Non-compositional,[object Object],void InsertNutritionalSubstance(IEnumerable<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],	_burps = ProcessFood(dishes, bob);,[object Object],	Burp();,[object Object],},[object Object],IEnumerable<Burp>ProcessFood(IEnumerable<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],return dishes.SelectMany(d => d.Items),[object Object],            .Where(i => i.IsTasty(bob)),[object Object],            .Select(i => ProcessFoodItem(i, bob)); ,[object Object],},[object Object],void Burp(),[object Object],{,[object Object],foreach(var burp in_burps){,[object Object],Environment.Release(burp);,[object Object],	},[object Object],},[object Object]
void InsertNutritionalSubstance(IEnumerable<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],Burp(ProcessFood(dishes, bob));,[object Object],},[object Object],IEnumerable<Burp>ProcessFood(IEnumerable<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],return dishes.SelectMany(d => d.Items),[object Object],            .Where(i => i.IsTasty(bob)),[object Object],            .Select(i => ProcessFoodItem(i, bob)); ,[object Object],},[object Object],void Burp(IEnumerable<Burp> burps),[object Object],{,[object Object],foreach(var burp inburps){,[object Object],Environment.Release(burp);,[object Object],	},[object Object],},[object Object],Composition,[object Object]
Step 7. Computational abstraction,[object Object]
IEnumerable<Burp>ProcessFood(IEnumerable<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],return dishes.SelectMany(d => d.Items),[object Object],            .Where(i => i.IsTasty(bob)),[object Object],            .Select(i => ProcessFoodItem(i, bob)); ,[object Object],},[object Object],Burp ProcessFoodItem(FoodItemfoodItem, ImperativeGeek bob),[object Object],{,[object Object],	Burpburp = null;,[object Object],	switch(foodItem.Kind),[object Object],	{,[object Object],caseFoodKind.Yummy:,[object Object],bob.ConsumeItem(foodItem, out burp);,[object Object],break;,[object Object],		caseFoodKind.Chewy:,[object Object],var timeout = TimeSpan.FromSeconds(10);,[object Object],bob.Chew(foodItem, timeout);,[object Object],break;,[object Object],default:,[object Object],throw new Exception(“Yuk!”);,[object Object],	},[object Object],return burp; ,[object Object],},[object Object],void Burp(IEnumerable<Burp> burps),[object Object],{,[object Object],foreach(var burp inburps){,[object Object],Environment.Release(burp);,[object Object],	},[object Object],},[object Object],Could be null,[object Object]
IEnumerable<Maybe<Burp>>ProcessFood(IEnumerable<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],return dishes.SelectMany(d => d.Items),[object Object],            .Where(i => i.IsTasty(bob)),[object Object],            .Select(i => ProcessFoodItem(i, bob)); ,[object Object],},[object Object],Maybe<Burp>ProcessFoodItem(FoodItemfoodItem, ImperativeGeek bob),[object Object],{,[object Object],	Burpburp = null;,[object Object],	switch(foodItem.Kind),[object Object],	{,[object Object],caseFoodKind.Yummy:,[object Object],bob.ConsumeItem(foodItem, out burp);,[object Object],break;,[object Object],		caseFoodKind.Chewy:,[object Object],var timeout = TimeSpan.FromSeconds(10);,[object Object],bob.Chew(foodItem, timeout);,[object Object],break;,[object Object],default:,[object Object],throw new Exception(“Yuk!”);,[object Object],	},[object Object],return burp != null ? burp.ToMaybe() : Maybe<Burp>.Nothing; ,[object Object],},[object Object],void Burp(IEnumerable<<Maybe<Burp>> burps),[object Object],{,[object Object],foreach(var burp inburps.Where(b => b.HasValue)){,[object Object],Environment.Release(burp);,[object Object],	},[object Object],},[object Object]
Step 8. Constrained state space,[object Object]
∞,[object Object],∞,[object Object],IEnumerable<Maybe<Burp>>ProcessFood(IEnumerable<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],return dishes.SelectMany(d => d.Items),[object Object],            .Where(i => i.IsTasty(bob)),[object Object],            .Select(i => ProcessFoodItem(i, bob)); ,[object Object],},[object Object],Maybe<Burp>ProcessFoodItem(FoodItemfoodItem, ImperativeGeek bob),[object Object],{,[object Object],	Burpburp = null;,[object Object],	switch(foodItem.Kind),[object Object],	{,[object Object],caseFoodKind.Yummy:,[object Object],bob.ConsumeItem(foodItem, out burp);,[object Object],break;,[object Object],		caseFoodKind.Chewy:,[object Object],var timeout = TimeSpan.FromSeconds(10);,[object Object],bob.Chew(foodItem, timeout);,[object Object],break;,[object Object],default:,[object Object],throw new Exception(“Yuk!”);,[object Object],	},[object Object],return burp != null ? burp.ToMaybe() : Maybe<Burp>.Nothing; ,[object Object],},[object Object],∞,[object Object],∞,[object Object]
IEnumerable<Maybe<Burp>>ProcessFood(IEnumerable<Dish> dishes, ImperativeGeek bob),[object Object],{,[object Object],Contract.Requires(dishes.Any());,[object Object],Contract.Requires(bob.IsHungry);,[object Object],Contract.Ensures(bob.IsFull);,[object Object],return dishes.SelectMany(d => d.Items),[object Object],            .Where(i => i.IsTasty(bob)),[object Object],            .Select(i => ProcessFoodItem(i, bob)); ,[object Object],},[object Object],Maybe<Burp>ProcessFoodItem(FoodItemfoodItem, ImperativeGeek bob),[object Object],{,[object Object],Contract.Requires(foodItem.ExpiryDate < DateTime.Now);,[object Object],Contract.Requires(foodItem.IsWarm);,[object Object],Contract.Requires(bob.IsHungry);,[object Object],	Burpburp = null;,[object Object],	switch(foodItem.Kind),[object Object],	{,[object Object],caseFoodKind.Yummy:,[object Object],bob.ConsumeItem(foodItem, out burp);,[object Object],break;,[object Object],		caseFoodKind.Chewy:,[object Object],var timeout = TimeSpan.FromSeconds(10);,[object Object],bob.Chew(foodItem, timeout);,[object Object],break;,[object Object],default:,[object Object],throw new Exception(“Yuk!”);,[object Object],	},[object Object],return burp != null ? burp.ToMaybe() : Maybe<Burp>.Nothing; ,[object Object],},[object Object]

More Related Content

Correctness through simplicity

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.