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

Ch3 Names That Can’t Be Misconstrued

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

1.Matching Expectations of Users

var ShrinkList = function (list, max_size) {

    while (list.size() > max_size) {
        FreeNode(list.back());
        list.pop_back();
    }

/*    The “bug” is that the author didn’t know that list.size() is an O(n) operation—it counts
    through the linked list node by node, instead of just returning a precalculated count, which
    makes ShrinkList() an O(n2) operation.*/


    //Had size() been named countSize() or countElements(), the same mistake would be less likely.
    while (list.countSize() > max_size) {
        FreeNode(list.back());
        list.pop_back();
    }


    return 0;

};

 

2.Prefer min and max for Limits

 

var euclidean_norm = function (v) {


    CART_TOO_BIG_LIMIT = 10
    if (shopping_cart.num_items() >= CART_TOO_BIG_LIMIT)
        Error("Too many items in cart.")


/*    A D V I C E
    The clearest way to name a limit is to put max_ or min_ in front of the thing being
    limited.*/

 

    MAX_ITEMS_IN_CART = 10
    if (shopping_cart.num_items() > MAX_ITEMS_IN_CART)
        Error("Too many items in cart.")

 

/*    print integer_range(start=2, stop=4)
      set.PrintKeys(first="Bart", last="Maggie")
    # Does this print [2,3] or [2,3,4] (or something else)?*/

    return 0;

};

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

파란실버라이트

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.

티스토리툴바