correctness through simplicity

Download Correctness through simplicity

Post on 01-Nov-2014

365 views

Category:

Documents

2 download

Embed Size (px)

DESCRIPTION

 

TRANSCRIPT

  • 1. Correctness through simplicity
    Ulvi K. Guliyev
  • 2. 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.
    Prof. Joseph Kiniry (Software Development Group)
  • 3. How do we think about computation?
  • 4.

    void InsertNutritionalSubstance(List dishes, ImperativeGeek bob)
    {
    _burps = new List();
    foreach(vardish in dishes){
    foreach(varfoodItemindish.Items){
    if(foodItem.IsTasty(bob)){
    Burpburp;
    switch(foodItem.Kind){
    caseFoodKind.Yummy:
    bob.ConsumeItem(foodItem, out burp);
    break;
    caseFoodKind.Chewy:
    var timeout = TimeSpan.FromSeconds(10);
    bob.Chew(foodItem, timeout);
    break;
    default:
    throw new Exception(Yuk!);
    }
    if(burp != null)
    _burps.Add(burp);
    }
    else{
    Environment.Spit(foodItem, bob);
    }
    }
    }
    foreach(var burp in _burps){
    Environment.Release(burp);
    }
    }
    Branch
    Loop
    Loop
    Branch
    Side-effect
    Branch
    Branch
    Jump
    Branch
    Side-effect
    Branch
    Side-effect
    Meet accidental complexity
    Meet imperative Bob
    Loop
    Side-effect
  • 5. How do we change thinking modality?
    We are computers
    Technology is secondary
    Intuition and ingenuity
    Structured roadmap
  • 6. Roadmap to dependable software
    Targeted at imperative programmers
    Focus on reducing code complexity
    Step by step discovery
    Meant to alter the way we reason about computation
  • 7.
  • 8. Step 1. Procedural decomposition
  • 9. void InsertNutritionalSubstance(List dishes, ImperativeGeek bob)
    {
    _burps= new List();
    foreach(vardish in dishes){
    foreach(varfoodItemindish.Items){
    if(foodItem.IsTasty(bob)){
    Burpburp;
    switch(foodItem.Kind){
    caseFoodKind.Yummy:
    bob.ConsumeItem(foodItem, out burp);
    break;
    caseFoodKind.Chewy:
    var timeout = TimeSpan.FromSeconds(10);
    bob.Chew(foodItem, timeout);
    break;
    default:
    throw new Exception(Yuk!);
    }
    if(burp != null)
    _burps.Add(burp);
    }
    else
    Environment.Spit(foodItem, bob);
    }
    }
    foreach(var burp in_burps){
    Environment.Release(burp);
    }
    }
    Operational demarcation
  • 10. void InsertNutritionalSubstance(List dishes, ImperativeGeek bob)
    {
    _burps= new List();
    foreach(vardish in dishes){
    foreach(varfoodItemindish.Items){
    if(foodItem.IsTasty(bob)){
    Burpburp;
    switch(foodItem.Kind){
    caseFoodKind.Yummy:
    bob.ConsumeItem(foodItem, out burp);
    break;
    caseFoodKind.Chewy:
    var timeout = TimeSpan.FromSeconds(10);
    bob.Chew(foodItem, timeout);
    break;
    default:
    throw new Exception(Yuk!);
    }
    if(burp != null)
    burps.Add(burp);
    }
    else
    Environment.Spit(foodItem, bob);
    }
    }
    Burp();
    }
    void Burp()
    {
    foreach(var burp in_burps){
    Environment.Release(burp);
    }
    }
  • 11. Step 2. Single responsibility
  • 12. void InsertNutritionalSubstance(List dishes, ImperativeGeek bob)
    {
    _burps= new List();
    foreach(vardish in dishes){
    foreach(varfoodItemindish.Items){
    if(foodItem.IsTasty(bob)){
    Burpburp;
    switch(foodItem.Kind){
    caseFoodKind.Yummy:
    bob.ConsumeItem(foodItem, out burp);
    break;
    caseFoodKind.Chewy:
    var timeout = TimeSpan.FromSeconds(10);
    bob.Chew(foodItem, timeout);
    break;
    default:
    throw new Exception(Yuk!);
    }
    if(burp != null)
    _burps.Add(burp);
    }
    else{
    Environment.Spit(foodItem, bob);
    }
    }
    }
    }
    void Burp()
    {
    foreach(var burp in_burps){
    Environment.Release(burp);
    }
    }
    Responsibility demarcation
  • 13. void InsertNutritionalSubstance(List dishes, ImperativeGeek bob)
    {
    _burps= new List();
    foreach(vardish in dishes){
    foreach(varfoodItemindish.Items){
    if(foodItem.IsTasty(bob)){
    Burpburp = ProcessFoodItem(foodItem, bob);
    if(burp != null)
    _burps.Add(burp);
    else
    Environment.Spit(foodItem, bob);
    }
    }
    }
    Burp();
    }
    Burp ProcessFoodItem(FoodItemfoodItem, ImperativeGeekbob)
    {
    Burpburp = null;
    switch(foodItem.Kind)
    {
    caseFoodKind.Yummy:
    bob.ConsumeItem(foodItem, out burp);
    break;
    caseFoodKind.Chewy:
    var timeout = TimeSpan.FromSeconds(10);
    bob.Chew(foodItem, timeout);
    break;
    default:
    throw new Exception(Yuk!);
    }
    return burp;
    }
  • 14. Step 3. Semantic regression
  • 15. Code beacons
    Patterns in code
    Sequences of imperative instructions
    Describe how to compute and not computation itself
    Denote hidden semantic intent
  • 16. void InsertNutritionalSubstance(List dishes, ImperativeGeek bob)
    {
    _burps= new List();
    foreach(vardish in dishes){
    foreach(varfoodItemindish.Items){
    if(foodItem.IsTasty(bob)){
    Burpburp = ProcessFoodItem(foodItem, bob);
    if(burp != null)
    _burps.Add(burp);
    else
    Environment.Spit(foodItem, bob);
    }
    }
    }
    Burp();
    }
    void Burp()
    {
    foreach(var burp in_burps){
    Environment.Release(burp);
    }
    }
    Beacon
    Beacon
    Beacon
  • 17. void InsertNutritionalSubstance(List dishes, ImperativeGeek bob)
    {
    _burps = ProcessFood(dishes, bob);
    Burp();
    }
    ListProcessFood(List dishes, ImperativeGeek bob)
    {
    return dishes.SelectMany(d => d.Items)
    .Where(i => i.IsTasty(bob))
    .Select(i => ProcessFoodItem(i, bob));
    }
    void Burp()
    {
    foreach(var burp in _burps){
    Environment.Release(burp);
    }
    }
  • 18. Step 4. Controlled side-effects
  • 19. Mutable type
    void InsertNutritionalSubstance(List dishes, ImperativeGeek bob)
    {
    _burps = ProcessFood(dishes, bob);
    Burp();
    }
    ListProcessFood(List dishes, ImperativeGeek bob)
    {
    return dishes.SelectMany(d => d.Items)
    .Where(i => i.IsTasty(bob))
    .Select(i => ProcessFoodItem(i, bob));
    }
    void Burp()
    {
    foreach(var burp in_burps){
    Environment.Release(burp);
    }
    }
    Mutable type
    Mutable type
  • 20. void InsertNutritionalSubstance(IEnumerable dishes, ImperativeGeek bob)
    {
    _burps = ProcessFood(dishes, bob);
    Burp();
    }
    IEnumerableProcessFood(IEnumerable dishes, ImperativeGeek bob)
    {
    return dishes.SelectMany(d => d.Items)
    .Where(i => i.IsTasty(bob))
    .Select(i => ProcessFoodItem(i, bob));
    }
    void Burp()
    {
    foreach(var burp in_burps){
    Environment.Release(burp);
    }
    }
  • 21. Step 6. Functional composition
  • 22. Non-compositional
    void InsertNutritionalSubstance(IEnumerable dishes, ImperativeGeek bob)
    {
    _burps = ProcessFood(dishes, bob);
    Burp();
    }
    IEnumerableProcessFood(IEnumerable dishes, ImperativeGeek bob)
    {
    return dishes.SelectMany(d => d.Items)
    .Where(i => i.IsTasty(bob))
    .Select(i => ProcessFoodItem(i, bob));
    }
    void Burp()
    {
    foreach(var burp in_burps){
    Environment.Release(burp);
    }
    }
  • 23. void InsertNutritionalSubstance(IEnumerable dishes, ImperativeGeek bob)
    {
    Burp(ProcessFood(dishes, bob));
    }
    IEnumerableProcessFood(IEnumerable dishes, ImperativeGeek bob)
    {
    return dishes.SelectMany(d => d.Items)
    .Where(i => i.IsTasty(bob))
    .Select(i => ProcessFoodItem(i, bob));
    }
    void Burp(IEnumerable burps)
    {
    foreach(var burp inburps){
    Environment.Release(burp);
    }
    }
    Composition
  • 24. Step 7. Computational abstraction
  • 25. IEnumerableProcessFood(IEnumerable dishes, ImperativeGeek bob)
    {
    return dishes.SelectMany(d => d