original:
PSEUDOCODE STANDARD
In general the vocabulary used in the pseudocode should be the vocabulary of the problem domain, not of the implementation domain. The pseudocode is a narrative for someone who knows the requirements (problem domain) and is trying to learn how the solution is organized. E.g.,
Extract the next word from the line (good)Note that the logic must be decomposed to the level of a single loop or decision. Thus "Search the list and find the customer with highest balance" is too vague because it takes a loop AND a nested decision to implement it. It's okay to use "Find" or "Lookup" if there's a predefined function for it such as
set word to get next token (poor)Append the file extension to the name (good)
name = name + extension (poor)FOR all the characters in the name (good)
FOR character = first to last (ok)
String.indexOf()
. Each textbook and each individual designer may have their own personal style of pseudocode. Pseudocode is not a rigorous notation, since it is read by other people, not by the computer. There is no universal "standard" for the industry, but for instructional purposes it is helpful if we all follow a similar style. The format below is recommended for expressing your solutions in our class.
The "structured" part of pseudocode is a notation for representing six specific structured programming constructs: SEQUENCE, WHILE, IF-THEN-ELSE, REPEAT-UNTIL, FOR, and CASE. Each of these constructs can be embedded inside any other construct. These constructs represent the logic, or flow of control in an algorithm.
It has been proven that three basic constructs for flow of control are sufficient to implement any "proper" algorithm.
SEQUENCE is a linear progression where one task is performed sequentially after another.
WHILE is a loop (repetition) with a simple conditional test at its beginning.
IF-THEN-ELSE is a decision (selection) in which a choice is made between two alternative courses of action.
Although these constructs are sufficient, it is often useful to include three more constructs:
REPEAT-UNTIL is a loop with a simple conditional test at the bottom.SEQUENCE
CASE is a multiway branch (decision) based on the value of an expression. CASE is a generalization of IF-THEN-ELSE.
FOR is a "counting" loop.
Sequential control is indicated by writing one action after another, each action on a line by itself, and all actions aligned with the same indent. The actions are performed in the sequence (top to bottom) that they are written.
Example (non-computer)
Brush teethExample
Wash face
Comb hair
Smile in mirror
READ height of rectangleCommon Action Keywords
READ width of rectangle
COMPUTE area as height times width
Several keywords are often used to indicate common input, output, and processing operations.IF-THEN-ELSEInput: READ, OBTAIN, GET
Output: PRINT, DISPLAY, SHOW
Compute: COMPUTE, CALCULATE, DETERMINE
Initialize: SET, INIT
Add one: INCREMENT, BUMP
Binary choice on a given Boolean condition is indicated by the use of four keywords: IF, THEN, ELSE, and ENDIF. The general form is:
IF condition THENThe ELSE keyword and "sequence 2" are optional. If the condition is true, sequence 1 is performed, otherwise sequence 2 is performed.sequence 1ELSEsequence 2ENDIF
Example
IF HoursWorked > NormalMax THENWHILEDisplay overtime messageELSEDisplay regular time messageENDIF
The WHILE construct is used to specify a loop with a test at the top. The beginning and ending of the loop are indicated by two keywords WHILE and ENDWHILE. The general form is:
WHILE conditionThe loop is entered only if the condition is true. The "sequence" is performed for each iteration. At the conclusion of each iteration, the condition is evaluated and the loop continues as long as the condition is true.sequenceENDWHILE
Example
WHILE Population < LimitCompute Population as Population + Births - DeathsENDWHILE
Example
WHILE employee.type NOT EQUAL manager AND personCount < numEmployeesCASEINCREMENT personCountENDWHILE
CALL employeeList.getPerson with personCount RETURNING employee
A CASE construct indicates a multiway branch based on conditions that are mutually exclusive. Four keywords, CASE, OF, OTHERS, and ENDCASE, and conditions are used to indicate the various alternatives. The general form is:
CASE expression OFindicating the value of "expression", but they can be English statements or some other notation that specifies the condition under which the given sequence is to be performed. A certain sequence may be associated with more than one condition.condition 1 : sequence 1ENDCASE
condition 2 : sequence 2
...
condition n : sequence n
OTHERS:
default sequenceThe OTHERS clause with its default sequence is optional. Conditions are normally numbers or characters
Example
CASE Title OF
Mr : Print "Mister"
Mrs : Print "Missus"
Miss : Print "Miss"
Ms : Print "Mizz"
Dr : Print "Doctor"
ENDCASE
Example
CASE grade OF
A : points = 4
B : points = 3
C : points = 2
D : points = 1
F : points = 0
ENDCASE
REPEAT-UNTIL
This loop is similar to the WHILE loop except that the test is performed at the bottom of the loop instead of at the top. Two keywords, REPEAT and UNTIL are used. The general form is:
REPEATThe "sequence" in this type of loop is always performed at least once, because the test is peformed after the sequence is executed. At the conclusion of each iteration, the condition is evaluated, and the loop repeats if the condition is false. The loop terminates when the condition becomes true.sequenceUNTIL condition
FOR
This loop is a specialized construct for iterating a specific number of times, often called a "counting" loop. Two keywords, FOR and ENDFOR are used. The general form is:
FOR iteration boundsIn cases where the loop constraints can be obviously inferred it is best to describe the loop using problem domain vocabulary.sequenceENDFOR
Example
FOR each month of the year (good)
FOR month = 1 to 12 (ok)FOR each employee in the list (good)
FOR empno = 1 to listsize (ok)
NESTED CONSTRUCTS
The constructs can be embedded within each other, and this is made clear by use of indenting. Nested constructs should be clearly indented from their surrounding constructs.
Example
SET total to zeroIn the above example, the IF construct is nested within the REPEAT construct, and therefore is indented.
REPEATREAD TemperatureUNTIL Temperature < zero
IF Temperature > Freezing THEN
INCREMENT total
END IF
Print total
INVOKING SUBPROCEDURES
Use the CALL keyword. For example:
CALL AvgAge with StudentAges
CALL Swap with CurrentItem and TargetItem
CALL Account.debit with CheckAmount
CALL getBalance RETURNING aBalance
CALL SquareRoot with orbitHeight RETURNING nominalOrbit
"Better"
Set moveCount to 1FOR all the number at the back of the array
SET Temp equal the addition of each number
IF > 9 THEN
get the remainder of the number divided by 10 to that index
and carry the "1"
Decrement one
Do it again for numbers before the decimal
"Good Enough (not perfect)"
SET Carry to 0
FOR each DigitPosition in Number from least significant to most significant
COMPUTE Total as sum of FirstNum[DigitPosition] and SecondNum[DigitPosition] and Carry
IF Total > 10 THEN
SET Carry to 1
SUBTRACT 10 from Total
ELSE
SET Carry to 0
END IF
STORE Total in Result[DigitPosition]
END LOOP
IF Carry = 1 THEN
RAISE Overflow exception
END IF
"Pretty Good" This example shows how pseudocode is written as comments in the source file. Note that the double slashes are indented.
public boolean moveRobot (Robot aRobot)
{
//IF robot has no obstacle in front THEN
// Call Move robot
// Add the move command to the command history
// RETURN true
//ELSE
// RETURN false without moving the robot
//END IF
}
Example Java Implementation
public boolean moveRobot (Robot aRobot)
{
//IF robot has no obstacle in front THEN
if (aRobot.isFrontClear())
{
// Call Move robot
aRobot.move();
// Add the move command to the command history
cmdHistory.add(RobotAction.MOVE);
return true;
}
else // don't move the robot
{
return false;
}//END IF
}
作者:IBM 软g集团大中华区L构师 寇卫?img title="寇卫? alt="寇卫? src="http://www.kuqin.com/upimg/allimg/111127/1K3342042-0.gif" align="right" height="280" width="200" />
有一些年ȝE序员向我咨询,来的\应该怎么赎ͼ俗话_条条大\通罗马。不同的路都能走向成功。到底选哪条\Q取决于自己的兴。可能有E序?会问Q如果还没找到自q兴趣怎么办?我的是多试Q努力做Q这是职业生涯的必经之\。当你积累了一定的技术和l验之后Q就会面临多U选择。选择哪条 路,因h而异?/p>
如果Ҏ一U或几种技术非常感兴趣Qƈ且能够持l钻研,l过一定时期的U篏Q你可以逐渐成长Z家E序员。专家E序员对于所掌握的专业技术的?l程度非一般程序员能及Q各cd见编E问题在他们手中都能q刃而解Q可以说q类专家“老越值钱”。但是这cM家也有一定的风险性:随着l验的增加和q龄 的增长,q些人的工资会越来越高,当公司改变技术\U而不再需要专家E序员所掌握的专业技术时Q或者想降低做事的成本,他们可能面临失业或者另扑ַ?的局面?/p>
资深培训专家也是个不错的发展方向。成为培训专Ӟ不仅需要深厚的技术功底,同时q要具备优秀的沟通和表达能力Q因Z们的主要工作不再是研发某U?技术,而是传播技术知识。这条\很宽Q有一些优U的技术培训师除了担Q本职工作Q还会兼职到大学里讲课。虽然培训专家的技术可能达不到专家E序员的水^Q?但是工作内容相对更ؓ丰富Q接触的Z更多?/p>
成ؓ公司的技术ȝ是很多程序员的梦惟뀂这条\U是从初U程序员成长为高U程序员之后Q以做项目ؓ工作重点Q进而发展成目l理、开发经理,最l成 为技术ȝ甚至公司副总裁。这些程序员走的是技术管理\U,从做目开始,逐渐U篏理l验Q然后成长ؓ优秀的技术管理者。技术ȝ在公司甚x术界的媄 响力非同一般,对于那些有志于成为公叔R导层的程序员Q是个很大的诱惑。但是权力大、管的h多,意味着更大的压力,技术ȝ不仅要保持对新技术的敏感Q?q要抽出_֊做管理。比h为纯技术专Ӟq条路也许更难?/p>
q有一些程序员职业发展的终ҎL构师、总设计师。这cȝ序员的兴,不是某种特定的技术,而是偏重对Y件品或者Y件应用项目的设计。如果将?仉目开发团队比作一个乐队,那么E序员就相当于一名乐手(比如提琴手、长W手{)Q他们负责将自己的乐器演奏好Q项目经理是乐队指挥Q负责指挥和协调 q个乐队的配合;架构师则相当于作曲家。从入门的架构师开始,逐渐成ؓ资深架构师乃xL构师。如同历史上伟大的作曲家Q杰出的架构师能够在各种软g中谱 写出旋律优美?#8220;曲子”?/p>
另外一些程序员心怀创业的理惻I{到自己有了一定的技术积累,再掌握一些市场需求以及管理方法,他们会开?a target="_blank">创业之\。一旦成功,q类人的影响力会非常大,像Google和雅虎的创始人,都是技?a target="_blank">创业?成功典范。但是这条\也是最艰辛的,有句话叫?#8220;不当家不知柴c”Q不亲自创业的h也很难体会它的艰辛。创业涉及方斚w面,E有差池׃功亏一,投n 创业的程序员q不,但是真正能成功的之又少。踏上这条\不仅需要过人的勇气和魄力,更需要坚韧不拔的毅力Q以及深度的商业智慧Q再加上市场ZQ才?够赢到最后?/p>
很多E序员会C技术支持\U,q而发展成为精通业务的技术和行业咨询专家。这cȝ序员会在成ؓ高E序员之后加入销售团队,直接面对客户Q负责技 术层面的问题。如果对某一行业Q比如银行、电信)非常熟悉Q久而久之,成为精通这个行业技术的专家Q如果对于某一c解x案(比如ERP、CRM?SCMQ非常擅长,可以发展成行业的技术专家?/p>
q有一部分E序员会成ؓIT专栏作家和自p业者。这些h通常对写作比较感兴趣Q文字表达能力也不错Q他们会自׃事技术工作的内容或心得写?来,然后发表文章赚取E费。只要对技术够精通,q类人是很受杂志Ƣ迎的。在北美q有一U自p业者叫做合同工Q就是不定期的承接项目,在项目开始前{订 协议Q项目完成后l束合作。虽然这U职业目前在中国q不太多Q但是其自由性对于很多程序员来讲Q也非常有吸引力?/p>
上文提及的若q条路,E序员可以根据自q兴趣q行选择Q但是一般来_无论走哪条\Q都有一个前提条Ӟ从初U程序员q阶为高U程序员。因为在q?之前Q你甚至没有选择的机会。从初q阶到高U,通常需?~5q的旉Q因个h素质而异。大安_E序员要耐得住寂寞和枯燥Q年ȝE序员更要克服Q w的心态。在职业生的v步阶D,很多人M怸着头脑Q这时一定要静下心来Q多向资q序员求教Q慢慢熟悉技术、熟悉开发流E和行业。有时你会感觉掉q?了一个知识vz,w边全是陌生的事物,很难抓住。所以就更要四处探\Q逐渐L到方向,在寻找中q步?/p>
成功q阶为高U程序员Q也q不意味着前途一片光明。如果说从初U到高需要的是学习,那么从高U到专家Q需要的是不断地试和坚持。比起前一个阶 D,q个q程更ؓ漫长Q通常需?~8 q。在q期_因ؓ有了之前的积累,q且已经取得一定的成就Qh会更加自信,同时也会更加彷LQ有一个问题会时常盘旋在脑中:来的\到底要怎么赎ͼq时 可以利用自己所U篏的资源,多做一些尝试,试不同角色、不同的目Q与不同的客h交道Q时间长了,自然会找到最适合自己的发展方向?/p>
ȝhQ初U?a target="_blank" >E序?/a>和高U程序员?期,都属于职业生涯发展的W一阶段Q我们可以称之ؓ黄金时期。这阶段E序员的q龄?0~35岁之_因ؓq轻Q所以更善于学习Q而且体力充沛Q很多走q?q个阶段的程序员有过通宵工作的经历。在q个时期Q你有大把的旉学习提高Qؓ来的事业打下坚实的基础。而一旦超q了30 岁,无论从体力还是精上Q都会有所改变Q??0~40 岁是转型时期。这时的E序员(很多人已l不再编E)已经明确了自q发展方向Qƈ且向着目标努力Q让自己有所建树?0~60岁是专家时期Q至此,一名优 U的程序员会彻底实?#8220;破茧成蝶”的愿望,成长Z家?/p>
E序员的职业很精彩,同时也很艰苦。n受高工资Q掌握最新的技术,有可能成为创业成功的富豪Q甚xZ改变人类的生zL式(例如互联|浏览器的开 发、电子商务的应用、手机短信等Q,q就是别人眼中程序员的生z,也许正因此,每年都会有很多新人加入这个庞大的队伍Q体验向往已久的精彩生zR但是大?Ch却忽略了光鲜背后的艰辛,高工资的代h是工作强度高Q学习新技术的代h是工作压力大Q成为富豪的代h是心力交瘁,而若x变hcȝ生活方式Q那p?得住日复一日的枯燥和寂寞。酸甜苦辣都要自己品,E序员的发展道\有很多条Q就看你怎么选?/p>
8.Tomcat和Ant创办?/strong>
James Duncan DavidsonQ?997q到2001q在Sun公司工作Q他创徏了Tomcat应用服务器,q是使用最为广泛的Java Web服务器,同时q创ZAnt构徏工具QAnt使用XML来描q项目的构徏以及依赖关系Q目前仍是Java Web目构徏的事实标准?/p>
相关链接
7.试驱动开发和JUnit的创办h
Kent Beck是极限编E和试驱动开发方法论的创始hQ此外他q开发了JUnit工具Q这是用最为广泛的Java单元试框架Q而且q有多种语言的变U都是基于该框架开发的?/p>
相关链接
新闻和访?/strong>
Kent Beck图书
6.Java集合框架创办?/strong>
Joshua Bloch领导了很多Javaq_Ҏ的设计和实玎ͼ包括JDK 5.0语言增强以及屡获D荣的Java集合框架?004q?月他d了SUN公司q成为Google的首席Java架构师。此外他q因为《Effective Java》一书获得著名的Jolt大奖?/p>
相关链接
新闻和访?/strong>
Joshua Bloch图书
5.JBoss创办?/strong>
Marc Fleury?001q创办了JBossQ这是一个开源的Java应用服务器,后来该Y件卖l了U帽公司Q然后加入红帽公司lJBoss的开发,直到2007q?月?/p>
相关链接
新闻和访?/strong>
4.Struts创始?/strong>
Craig Mcclanahan是Struts框架的创始hQ相信每个JavaE序员都会知道Strutsq个最名的MVC框架?/p>
相关链接
新闻和访?/strong>
3.Spring创始?/strong>
Rod Johnson是Spring框架的创始hQ而后创办了SpringSource公司qQCEO。此外他q写了一本书《Expert One-on-One J2EE Design and Development (2002)?/p>
相关链接
新闻和访?/strong>
Rod Johnson图书
2.Hibernate创始?/strong>
Gavin King是Hibernate目的创始hQ这是注明的Java的ORM框架Q同时他q创ZSeam目Q另外参与了EJB 3.0和JPA设计Qƈ在其中v非常重要的作用?/p>
相关链接
新闻和访?/strong>
Gavin King 图书
1.Java语言之父
詹姆?#183;高斯林(James GoslingQ?955q??9日-Q出生于加拿大)QY件专ӞJava~程语言的共同创始h之一Q一般公认他?#8220;Java之父”?/p>
在他12岁的时候,他已能设计电子游戏机Q帮忙邻居修理收割机。大学时期在天文pLȝ式开发工ȝQ?977q获得了加拿大卡加里大学计机U学学士学位Q?983q获得了国卡内基梅隆大学计机U学博士学位Q博士论文的题目是:"The Algebraic Manipulation of Constraints"。毕业后到IBM工作Q设计IBMW一代工作站NeWSpȝQ但不受重视。后来{至Sun公司?990q_与Patrick Naughton和Mike Sheridan{h合作“l色计划”Q后来发展一套语a叫做“Oak”Q后改名为Java?994q底QJames Gosling在硅谷召开?#8220;技术、教育和设计大会”上展CJavaE式?000q_Java成ؓ世界上最行的电脑语a?/p>
相关链接
新闻和访?/strong>
英文Q?a target="_blank">Top 8 Java People You Should Know
译文来自Q?a target="_blank">OSCHINA
在mvn的项目中 pom.xml 文g所在目录, q行 mvn eclipse:clean eclipse:eclipse ,会自动将mvn工程转成eclipse工程Q?然后在eclipse? “在myEclipse的Package Explorer 下点d键,菜单中有个Import 再点开General 里面有个Existing Projects into Workspace 点击?有个Select root directory 点击后面 Browse扑ֈ你的目所在位|?/pre>
]]>