如何掌握多门语言

要解决的问题:
通常随着工作的时间变长,我们会发现我们懂得越多,需要记忆的东西也越多。 就拿语言来讲,通常我用的比较多的语言基本上有4种: C++, Java, Python, Javascript.
每一种语言都是用一阵子,然后回到另一种语言就会缓口气,要是遇到别人问你一些基本的问题的话,无法快速检索,给出答案。

理出的思路:
我们学习的语言虽然多,但是基本上做出一门语言要解决的问题基本上有相同性,我们大致可以分为8个步奏来完成一门语言的快速检索。

Part 1:回想语言的基本语法格式与数据类型
1.1 程序的入口在那里?
C++: int main() or int main(int argc, char *argv[]); 单一Main函数。
Java: public static void main(string[] args);(结合manifest或指定Class运行Main)
Python: if __name__==__main__: 解释器入口。
JavaScript: 取决于Load Js文件。

1.2 基本语句的写法
C++ : int a; const int* const mConstConstP; 等等(命名规则)
Java: int a; 类似。
JavaScript:var a;
Python: 即写急用 a=12; name_rules="Hellow"

1.3: 类似基本变量的取值范围是什么?暂多少位宽,对内存的使用优化。
1.3.1 范围的计算:
Integer rage: - 2E31~ 2E31-1
........ , ........ , ........ , ........ 其中‘.’可以取值(0,1)
理解:如上点表示位数,共32位,除去符号(次方减1),除去0,(正范围的值在减一)。因为计算得到 Int的取值范围如下//- 2E(32位-1)~ 2E(32位-1)-1

1.3.2 占用的位宽:

Java:
byte,boolean 1 byte.
int, float 4 bytes
short,char 2 bytes
long,double 8 bytes
C++:
bool,char,unsigned char,signed char, 1 byte
short,unsigned short, 2 bytes.
int, unsined, unsigned long,signed long, float, 4 bytes.
double, 8 bytes.
long double 10 bytes
Python: Don't care
Javascript: Don't care
Part 2:集运的符号运算,数组,字符串与集合的使用(一样)
 2.1 左移运算的概念: 所有位全部左移,左边超出部分丢弃,尾部补0  安装2进制到10进制转换,移动的位置是2进制值(0,1)*2E‘N’(N代表位位置),相当于讲数字本身乘以2的N次方
你写个(0,1)这算怎么回事?我只想说,你把0移动几位他的值是多少?
int i = 2;
System.out.println(i<< 2);//2*2*2或者说2* 2E

2.2 右移移运算的概念:
所有位全部向又移动,右边超出部分丢弃,原来最左边是0补0,是1补1。(保持符号位不变)
 int j = -8;
 std::cout <<(j >> 2)<<std::endl;//相当于8/2/2 或者说-8/2E2 (取整)
 std::cout <<(j >>> 2)<<std::end;// 无符号为右移,表示无论如何最边都补0 (即无符号位位移)	
顺便提下 逻辑运算 与 位运算 &&,||,! VS &,|,^(异或),~(补码)
解释:补码表示0变1,1变0
2.3数组的声明与初始化,记得正确的申明与初始化的方式
Java
int[] a1 = {1, 2,3}; int[] a2 = new int[10]; int[] a3 = new int[]{1,2,3};
C++
char a[5] = {'1','2','3','4'};
char a[] = {'1','2','3','4','5'};
2.3 String 使用: 考虑 String 的内存使用与字符串操作。
#TODO
2.4 集合的使用与集成关系
  
Java:

C++:
C++ 在STL中使用Template + ‘迭代器’ 的方式定了各种容器的使用,并且提供算法<algorithm>. C++ 没有使用继承的方式实现容器。
通常我们使用<algorithm>,<容器头文件>来使用容器包括:<list><queue><map><set><stack><dequeue>等

Python:
python 容器基本上为 list, set, dict
JavaScript: 基本上使用array 和 dict{}


Part 3:流程控制,if..else; swich. while. for(基本一样)

Part 4:面向对象的特性与泛型:封装、继承、多肽。
Java:

C++:
不用直接比较自动被装箱的两个对象相等(Not useful)
Integer ii = 200;
Integer jj = 200;
System.out.println("ii == jj? =>" + (ii == jj? "Yes,Equal":"No,unqual").toString());
Integer ii2 = 100;
Integer jj2 = 100;
System.out.println("ii2 == jj2? =>" + (ii2 == jj2? "Yes,Equal":"No,unqual").toString());
因为-128~127 这种数字是在内存中被缓存了。(这是100与200的差异)
Part 5:网络编程

Part 6:多线程与锁:


Part 7:异常处理与单元测试

Part 8:特别之处
Java:
1) The difference between Class.this.filed_name and this.filed_name. Class.this.field_name: A reference to a class instance's filed name

this.field_name : A reference to the instance filed name.
Generally, There is no difference to simple class. E.G., In person class, Person.this.name is equal to this.name.
But this syntax is very useful to visit a parent Class in non-static nest class. For example:\
Class Person(){
Person(String name){
this.name = name;
}

Class GreenMan(){
GreenMan(Color color){
this.color = color;
}
public myColor(){
Sysout.print(Person.this.name + " said:" +" I'm " + this.color.toString();
}
}
其他3rd Feature:
 

<未完待续>

posted @ 2015-08-12 00:53  velly.zhou  阅读(537)  评论(0编辑  收藏  举报