2009年4月27日 由 飞扬轻狂
没有评论 »
php的多分支控制
– 原文 (飞扬轻狂,fallseir) 20090427
==== php的多分支控制 ====
### if 方式 实现多分支控制
if(runStep(1)){
if(runStep(2)){
if(runStep(3)){
# all steps are success!!
}else{
# step 03 is failed!
}
}else{
# step 03 is failed!
}
}else{
# step 03 is failed!
}
# some others steps
### if 方式 2 实现多分支控制
$r=0;
if(runStep(1))
if(runStep(2))
if(runStep(3))
else $r=3;
else $r=2;
else $r=1;
if($r){
# step $r is failed!
return false;
}
# some others steps
### do..while(false) 方式 2 实现多分支控制
do{
if(!runStep(1)) # step 01 is failed!
break;
if(!runStep(2)) # step 02 is failed!
break;
if(!runStep(3)) # step 03 is failed!
break;
# all steps are success!!
}while(false);
# some others steps
### switch(true) 方式 2 实现多分支控制
switch(true){
case !runStep(1):
# step 01 is failed!
break;
case !runStep(2):
# step 02 is failed!
break;
case !runStep(3):
# step 03 is failed!
break;
default:
# all steps are success!!
break;
}
# some others steps
### try..catch 方式实现
try{
if(!runStep(1)) throw new SomeError(1); # step 01 is failed!
if(!runStep(2)) throw new SomeError(2); # step 02 is failed!
if(!runStep(3)) throw new SomeError(3); # step 01 is failed!
# all steps are success!!
}catch(SomeError $ex){
# step $ex is failed!
return false;
}
# some others steps
2009年4月27日 由 飞扬轻狂
没有评论 »
使用反射 实现的 简单的 单元测试框架
– 原文 (飞扬轻狂,fallseir) 20090427
==== generalized test methods use introspection ====
class customClass{
function selfTest(){[..] return [message|false]}
}
class tester{
function test($thing){
if(is_object($thing)){
if(method_exists($thing,'selfTest')){
$this->handleTest(call_user_method('selfTest',$thing));
}
}else if(is_array($thing)){
foreach($thing as $component){ $this->test($component); }
}else{
;//ignore if not an array or object
}
}
function handleTest($result){if($result)print "Warning $result";}
}
参考:
John.Wiley.and.Sons.PHP5.and.MySQL.Bible
2009年4月7日 由 飞扬轻狂
没有评论 »
测试FEED 点击广告

feedsky
提供的内嵌式 feed 点击广告开始测试了
发篇文章来测试 多少个阅读器中可以看到它..
2009年1月20日 由 飞扬轻狂
没有评论 »
虽然一直在网上 但好久不在意网络了
在google reader中看到大家在议论GTD
好炫的名字啊 我都不知道这个是什么东西 (囧~ 亏你还是做IT的呢)
赶快去下了本《尽管去做–无压工作的艺术》瞧了下
看了头一章 就上来把自己的想法先记下来 免得时间久就丢了
(晕死,WP竟然上传图片有问题… 算了懒得去看是什么原因了 )
上面是一张简图 描述了大脑的思维和行事历之间的关系(偶自己的理解,和书中可能不大相同,我才看了一章…)
1、这里把所有不能决定的和没有决定的事情都称作 待办事项
2、在空闲或计划处理待办事项的时间对存在于待办列表中的事情进行 转化
3、觉得没有必要的就直接划掉丢弃
4、短时间内能完成的就直接 执行 处理了
5、需要长时间处理的就放在计划列表中根据优先级排序
6、不能判断的就继续留在待办列表里
7、设定一个提醒装置 到期进行提醒(比如短信、Mail或及时聊天工具中的消息)
8、当有突然出现的事情发生时,直接将它们记录为待办事情(不丢失又最少的影响当前的事情)
9、当有高优先级的任务需要处理时,暂停当前执行的事情并在行事历中标注,着手转化这个插进来的任务
通过这种方式最大限度的让大脑中只考虑当前执行中的事情 而不需要因为考虑其他的事情而分神
并把零散的随机出现的待办事项集中处理
从上面的内容可以看到 当前只是解决了思维被占用和干扰的问题,但并没有提出对因工作边界模糊,需求不定而产生的问题的解决方式,也问题被集中到了转化部分
参考:
GTD,Getting Things Done
《Getting Thing Done – The Art of Stress-Free Productivity》 — David Allen
2008年10月24日 由 飞扬轻狂
没有评论 »
在使用c++ 进行控制台交互时 也许你也容易忽略掉的细节
– 飞扬轻狂 20081024 fallseir[at]gmail.com
http://blog.fallseir.com/2008/10/note_std_cinnote_std_cin/
注意1: ” cin >> value ” 没有正确的读取换行
注意2: 不匹配的类型 将导致输入流错误 而在其后的调用中自动返回
注意3: 空字符 在使用 >> 赋值给变量时将自动过滤 直到读入非空字符为止
出错的代码 !!
$ vim 02-05-BasicIO-err.cpp
---------------------------------------------
#include
using namespace std;
int main( int argc, char *argv[] ){
int num;
string str,line;
cout << "Please enter a number:" ;
cin >> num;
cout << "Please enter a text :" ;
cin >> str;
cout << "Please enter some words :" ;
getline( cin, line );
cout << endl;
cout << "number : " << num << endl;
cout << "text : " << str << endl;
cout << "some words : " << line << endl;
return 0;
}
---------------------------------------------
$ g++ 02-05-BasicIO-err.cpp
$ a.out # 貌似正确的输入
----------------
Please enter a number:12
Please enter a text :message
Please enter some words :
number : 12
text : message
some words :
----------------
/*
分析原因:
第二次输入 "message" 的时候 自动过滤前次的 并得到了正确的值
getline 的时候 因为输入流中还有一个 没有被读取 所以没有等待用户输入,直接返回了
*/
--------------------
$ a.out # 貌似正确的结果
----------------
Please enter a number:13 message some words in the line
Please enter a text
lease enter some words :
number : 13
text : message
some words : some words in the line
----------------
/*
分析原因:
cin >> str 的时候 从流中读取了 "message"
getline 的时候 读取了流中剩下的内容
*/
--------------------
$ a.out # 错误的开始
----------------
Please enter a number:a
Please enter a text
lease enter some words :
number : 6696948
text :
some words :
----------------
/*
分析原因:
cin >> num 的时候 从流中读取了不匹配的数据 "a" ,cin 进入异常状态
cin >> str 和 getline 的时候 因为流异常 所以没有进行读取
*/
--------------------
优化的严谨的代码
$ vim 02-05-BasicIO.cpp
---------------------------------------------
#include
using namespace std;
int main( int argc, char *argv[] ){
int num;
string str,line;
string tmp;
cout << "Please enter a number:" ;
cin >> num;
while(cin.fail()){ // 如果出现错误
cin.clear(); // 清除错误
getline(cin,tmp); // 清除缓存
cerr << "Error input!!,Please try again" << endl;
cin >> num;
}
getline(cin,tmp); // 使用getline清除缓存,因为 >> 操作符不会对末尾的 进行读取
cout << "Please enter a text :" ;
cin >> str;
getline(cin,tmp);
cout << "Please enter some words :" ;
getline( cin, line );
cout << endl;
cout << "number : " << num << endl;
cout << "text : " << str << endl;
cout << "some words : " << line << endl;
return 0;
}
---------------------------------------------
----------------
$ a.out
----------------
Please enter a number:123 message test words!
Please enter a text :word and message
Please enter some words :some words in the line!
number : 123
text : word
some words : some words in the line!
----------------
--
http://blog.fallseir.com/2008/10/note_std_cinnote_std_cin/
飞扬轻狂
fallseir[at]gmail.com
blog.fallseir.com
2008年10月24日
转载请注明