Powered By Blogger

2011年6月9日星期四

AWT vs Swing

Recently I am about to develope a java program with visual interface. From the very beginning, there are two definations needed to make them clear. That is , the differences between AWT and Swing.

When developing a Java program it is important to select the appropriate Java Graphical User Interface (GUI) components. There are two basic sets of components that you will most likely build your Java programs with. These two groups of components are called the Abstract Window Toolkit (AWT) and Swing. Both of these groups of components are part of the Java Foundation Classes (JFC).

An Overview of the AWT

AWT stands for Abstract Window ToolKit. The Abstract Window Toolkit supports GUI Java programming. It is a portable GUI library for stand-alone applications and/or applets. The Abstract Window Toolkit provides the connection between your application and the native GUI. The AWT provides a high level of abstraction for your Java program since it hides you from the underlying details of the GUI your program will be running on.
AWT features include:

  • A rich set of user interface components.
  • A robust event-handling model.
  • Graphics and imaging tools, including shape, color, and font classes.
  • Layout managers, for flexible window layouts that don't depend on a particular window size or screen resolution.
  • Data transfer classes, for cut-and-paste through the native platform clipboard.
The AWT components depend on native code counterparts (called peers) to handle their functionality. Thus, these components are often called "heavyweight" components.

The Begin of Haskell

I have spent almost a week to learn how to use this language and finally I've developed the Baccarat in Haskell. Now I think it's really necessary for me to arrange my mind,which is messed up by this language.

First of all, this language is totally differnet with the previous language I've developed with, such as the OOP language: java, c++ and python or the imperative language:c. Actually it belongs to the functional language. In another way, functions in this language is " the first class", such as the variables or the parameters in OOP or imperative language. That is, you can take the function as the parameter or variable and do what the parameter or the variable can do.

Second, this language is called "purely". What purely means is that there is no side effect when you are programming, even if you are doing some  IO operations.

2011年6月2日星期四

zz.Cool Shell如何写出无法维护的代码

程序命名

  • 容易输入的名字。比如:Fred,asdf
  • 单字母的变量名。比如:a,b,c, x,y,z(陈皓注:如果不够用,可以考虑a1,a2,a3,a4,….)
  • 有创意地拼写错误。比如:SetPintleOpening, SetPintalClosing。这样可以让人很难搜索代码。
  • 抽象。比如:ProcessData, DoIt, GetData… 抽象到就跟什么都没说一样。
  • 缩写。比如:WTF,RTFSC …… (陈皓注:使用拼音缩写也同样给力,比如: BT,TMD,TJJTDS)
  • 随机大写字母。比如:gEtnuMbER..
  • 重用命名。在内嵌的语句块中使用相同的变量名有奇效。
  • 使用重音字母。比如:int ínt(注:第二个 ínt不是int)
  • 使用下划线。比如:_, __, ___。
  • 使用不同的语言。比如混用英语,德语,或是中文拼音。
  • 使用字符命名。比如:slash, asterix, comma…
  • 使用无关的单词。比如:god, superman, iloveu….
  • 混淆l和1。字母l和数字1有时候是看不出来的。

伪装欺诈

  • 把注释和代码交织在一起
1
2
3
4
5
6
7
8
9
10
11
for(j=0; j<array_len; j+ =8)<br />
{<br />
total += array[j+0 ];<br />
total += array[j+1 ];<br />
total += array[j+2 ]; /* Main body of<br />
total += array[j+3]; * loop is unrolled<br />
total += array[j+4]; * for greater speed.<br />
total += array[j+5]; */<br />
total += array[j+6 ];<br />
total += array[j+7 ];<br />
}
  • 隐藏宏定义。如:#define a=b a=0-b,当人们看到a=b时,谁也想不到那是一个宏。