Thread: The Principal Of Least Priviliged ?

  1. #31
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Because of the way I picture it in my mind. An object is a big box with many little boxes in it. Each of the little boxes is a member of the class and holds a value. The setX method puts a new value into the box labeled x, so obviously the old value needs to get out, right? This is what a setter returns in my mind

    It should be noted that this is the behaviour of many functions, such as set_new_handler, SetWindowLong(Ptr) and SelectObject.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #32
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    You can't use microsoft's behaviour as a logical argument

    I see the set functions as an assignment, what does assignment return, the new value.

    I see your point but I guess thats what good documentation is for

  3. #33
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You can't use microsoft's behaviour as a logical argument
    I'm not saying it's logical, I'm just saying it's existing practice and thus might be the expectation of programmers.

    That said, you're right, good documentation is needed. But how often do you have this luxury?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #34
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Always, thats what comments are for.

  5. #35
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    You could always have it return void, to save a (very neglible) CPU cycle or two and eliminate any ambiguity And you could name the function 'swapM()' if you want CornedBee's behaviour, though I can't think of any names that would intuitively tell you if it behaved Thantos' way.

    >>You can't use microsoft's behaviour as a logical argument
    I wonder what Microsoft employees' re-employability prospects are
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie to C++ needs help plz!!
    By xuder in forum C++ Programming
    Replies: 11
    Last Post: 01-23-2008, 08:36 AM
  2. while loop help
    By bliznags in forum C Programming
    Replies: 5
    Last Post: 03-20-2005, 12:30 AM
  3. Principal of least privilege
    By carlin70 in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2003, 08:15 PM
  4. Loan calculation formula
    By C++Nerd in forum C++ Programming
    Replies: 1
    Last Post: 10-06-2002, 12:57 PM