#PARAN SILVERLIGHT#
  • Tistory
    • 관리자
    • 글쓰기
Carousel 01
Carousel 02
Previous Next

Ch9 Variables and Readability

SOFTWARE ENGINEERING/Art Of Readable Code 2012. 11. 23. 11:36

 

1.Eliminating Intermediate Results


//Here’s an example of a JavaScript function that removes a value from an array:
    var remove_one = function (array, value_to_remove) {
        var index_to_remove = null;
        for (var i = 0; i < array.length; i += 1) {
            if (array[i] === value_to_remove) {
                index_to_remove = i;
                break;
            }
        }
        if (index_to_remove !== null) {
            array.splice(index_to_remove, 1);
        }
    };

 

//sometimes be eliminated by handling the result as soon as you get it:
    var remove_one = function (array, value_to_remove) {
        for (var i = 0; i < array.length; i += 1) {
            if (array[i] === value_to_remove) {
                array.splice(i, 1);
                return;
            }
        }
    };

 

2. if Statement Scope in C++

 

//the person reading this
//code might keep info in mind, wondering if/how it will be used again.
PaymentInfo* info = database.ReadPaymentInfo();
if (info) {
    cout << "User paid: " << info->amount() << endl;
}
// Many more lines of code below ...


//Now the reader can easily forget about info after it goes out of scope.
if (PaymentInfo* info = database.ReadPaymentInfo()) {
    cout << "User paid: " << info->amount() << endl;
}

 

3. Shrink the Scope of Your Variables

 

//two methods, in the following way:
    class LargeClass {

    string str_;

    void Method1() {
        str_ = ...;
        Method2();
    }
    void Method2() {
// Uses str_
    }
// Lots of other methods that don't use str_ ...
};


//For this case, it may make sense to “demote” str_ to be a local variable:
    class LargeClass {
    void Method1() {
        string str = ...;
        Method2(str);
    }

    void Method2(string str) {
// Uses str
    }
// Now other methods can't see str.
};

 

 

 

 

 

 

 

 

 

 

 

저작자표시 비영리 (새창열림)
블로그 이미지

파란실버라이트

To remember the time when I started learning Silver Light!

,

카테고리

  • Inforamtion Technology (281)
    • DESIGN PATTERN (33)
      • 실용주의 디자인패턴 (29)
    • SOFTWARE ENGINEERING (21)
      • Art Of Readable Code (12)
      • Object Oriented Programming (6)
      • TDD (2)
    • FRAMEWORK (22)
      • Spring.net (2)
      • LightSwitch (20)
    • PROGRAMING (58)
      • C# (20)
      • .NET (6)
      • HTML5 (7)
      • ASP.NET (9)
      • SILVERLIGHT (7)
      • Ruby On Rails (6)
    • PROJECT MANAGEMENT (10)
      • SW Version Management (7)
      • Schedulring Management (1)
    • BOOKS (18)
    • MOBILE APP (1)
      • SENCHA TOUCH (1)
    • SECURITY (5)
    • MES (1)
    • B2B (14)
      • WEBMETHODS (4)
    • ERP (53)
      • SAP/R/3 (51)
    • ABOUT TOOLS (2)
    • FUNDAMENT CONCEPT (21)
    • SOA BPM (22)
    • PORTFOLIO (0)

태그목록

  • 병렬
  • 동시성
  • 프로그래밍

최근에 받은 트랙백

글 보관함

링크

파란실버라이트

블로그 이미지

To remember the time when I started learning Silver Light!

LATEST FROM OUR BLOG

RSS 구독하기

LATEST COMMENTS

BLOG VISITORS

  • Total :
  • Today :
  • Yesterday :

Copyright © 2015 Socialdev. All Rights Reserved.

티스토리툴바