2011年6月29日

為什麼程式設計師無法有效率地工作?為什麼總是要加班?兩段程式碼幫您解惑

(一) 程式設計師為什麼無法有效率地工作?

The "pids" is a plain text file contains PIDs for important tasks.
Project manager tell you every task is *IMPORTANT*, should be done as soon as possible.
You're a programmer (also a system administrator), it's a piece of cake to change piorities.

$ cat pids
16994
17377
17378
17379

for p in `cat pids`; do renice -n -20 -p $p; done

Which process is most favorable scheduling?

(二) 程式設計師為什麼總是不斷加班?

Demo: http://jsfiddle.net/MWMBk/

var taskNum 3;
var money 10000;
var health 100;

function incoming_task({
    taskNum ++;
    taskNum ++;
}

function work({
    taskNum --;
    money ++;
}

function work_overtime({
    taskNum --;
    money ++;
    money ++;
    health --;
}

function programmer_life({
    while (taskNum 0{
        work();
        incoming_task();
        work_overtime();
        
        if (money >= 1000000{
            return "retired";
        }
        else if (health <= 0{
            return "died";
        }
        else {
            //nothing
        }
    }
}

function assert(val1val2{
    if (val1 == val2{
        alert("True");
    }
    else {
        alert("False");
    }
}

assert(programmer_life()"died");
assert(programmer_life()"retired");
// or infinite loop ?

沒有留言:

張貼留言

lyhcode by lyhcode
歡迎轉載,請務必註明出處!