principle of least privilege.... 
Author Message
 principle of least privilege....

can someone point me to more info on this subjest. the book that we
are using for the 'intro to c programming' class mentions it breifly
in the chapter on pointers, but really never explain what it is.

tia,
bob brozewicz



Sat, 01 Jan 2005 08:48:28 GMT  
 principle of least privilege....

Get a better book!

The point is to divide different parts of your program into smaller
sections that are easier to test and debug.

The parts need to talk to each other but should not need to get into
each others guts.

This is actually very common sense.

However i've seen 'professional' code that just ignores this.  The
program in question had hundreds of functions but was very very open.
So if you changed function number #345 ten totally unrelated functions
might break.  This totally defeats the purpose of having different
functions at all.  The thing was no better than having one big mess of code.

So the basic idea is try to keep different parts seperated.

Most langauges allow you to bend the rules.  Good programmers sometimes
make exceptions.  For example I'm writing a program now that has ONE
global variable.  Using this global breaks the rules but makes the
program better. This is because half my program needs access to the
variable _anyway_.  The key concept is _need_.

Now it may seem pointless for homework and it pretty much is.  Small
programs less that 200 lines can often be completely open without
problems.  Depending on the task at hand.  However software has a habit
of becoming very complex very fast- so this is an esssential skill.

Quote:

> can someone point me to more info on this subjest. the book that we
> are using for the 'intro to c programming' class mentions it breifly
> in the chapter on pointers, but really never explain what it is.

> tia,
> bob brozewicz



Sat, 01 Jan 2005 09:33:41 GMT  
 principle of least privilege....
The principle basically means that a function shouldn't be given additional
abilities more than it needs to. So if an unknown error occurrs you will
know which function is NOT involved.

Hope i made it clear...


Quote:
> can someone point me to more info on this subjest. the book that we
> are using for the 'intro to c programming' class mentions it breifly
> in the chapter on pointers, but really never explain what it is.

> tia,
> bob brozewicz



Sat, 01 Jan 2005 09:48:30 GMT  
 principle of least privilege....

Quote:
> can someone point me to more info on this subjest. the book that we
> are using for the 'intro to c programming' class mentions it breifly
> in the chapter on pointers, but really never explain what it is.

IIRC,

A term used by Deitel & Deitel, that basically says the minium const
priveledge is OK.

so:
If strcmp(const char *, const char *) is given some non-const pointers it is
fine.
but:
If strtok(char *, const char *) is given a const pointer for the first arg,
it's not OK.

IOW:

#include <stdio.h>
#include <string.h>

int             main(void)
{
    const char     *const_string = "I am a const string";
    char           *token;
    char            modifiable_string[] = "I can be modifed.";
    /* This is just peachy: */
    if (strstr(modifiable_string, "modified"))
        puts("found it");
    else
        puts("not found.");

    /* This is a {*filter*} no-no because we increase pointer capability */
    if (token = strtok(const_string, " "))
        puts("broke rules");
    return 0;

Quote:
}

--
C-FAQ: http://www.*-*-*.com/ ~scs/C-faq/top.html
 "The C-FAQ Book" ISBN 0-201-84519-9
C.A.P. FAQ: ftp://cap.connx.com/pub/Chess%20Analysis%20Project%20FAQ.htm


Sat, 01 Jan 2005 09:38:05 GMT  
 principle of least privilege....
Quote:

> can someone point me to more info on this subjest. the book that we
> are using for the 'intro to c programming' class mentions it breifly
> in the chapter on pointers, but really never explain what it is.

> tia,
> bob brozewicz

The principle's basic aim is to make your program clean and easier to
debug if need be. It says that a function should not be give more
privilages than it needs to do its job. Thus it would avoid
overlapping with other functions.


Sat, 01 Jan 2005 14:10:38 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. principle of least priviledge

2. Programming Principles or MFC Principles?

3. Programming Principles or MFC Principles?

4. Little by little

5. little program, little problem

6. little logical problem with vector...need little help

7. CFP for Workshop on Principles of Abstract Machines

8. Principles of C Programming

9. Principles of Writing Portable C Code

10. Language principles

11. The Principle of Most Astonishment

12. make principles

 

 
Powered by phpBB® Forum Software