Chinaunix首页 | 论坛 | 博客
  • 博客访问: 338823
  • 博文数量: 105
  • 博客积分: 2730
  • 博客等级: 少校
  • 技术积分: 1110
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-20 12:09
文章分类

全部博文(105)

文章存档

2013年(3)

2012年(2)

2011年(36)

2010年(34)

2009年(6)

2008年(20)

2007年(4)

分类: IT业界

2011-06-15 22:00:25

[[这个网站真不地道, 把换行全搞乱了.]]

摘自stackoverflow.com
发现这样一些总结, 不敢独享, 略作整理放在这里. 唉, 没看完下巴都掉了.
对一些语言因为不懂所以可能解释得不对, 请多指教!


1-- C语言
1)数组与指针
a[10] 很常见吧
10[a] 这个和上面的一个意思!

-- a[10] 就是 *(a+10) ... 所以 10[a] 就是 *(10+a)

--"Hello World"[i] 就是 i["Hello World"]


--"0123456789abcdef"[x & 0xf]  这个还挺有用, 把低四位的值转化成16进制的字符
2)printf
printf("LOL??!");
打出来是"LOL|"

评论:Trigraphs are amazing, because you can be sure nobody will -ever- find out what ??! will mean from Google without knowing the name already.---- 可以使用这样的正确语法: (foo() != ERROR) ??!??! cerr << "Error occurred" << endl; //C++

3)名字空间
typedef int i;
void foo()
 {
   struct i {
   i i;
   } i;
   i: i.i = 3;
 printf( "%i\n", i.i);
 }

2-- JavaScript
1)
'5' + 3 得到 '53''5' - 3 却得到 2
--评论认为弱类型是元凶
2)
因为默认在换行时对前面的语句加了';' 所以这个被认为是语法错误:
return
{
  id : 1234,
  title : 'Tony the Pony'
 };

这个是对的写法:
return {
  id : 1234,
 title : 'Tony the Pony'
};
但是(在chrome上),这个就对:
return /*
*/{
  id : 1234,
  title : 'Tony the Pony'
};
下面这个更骚, 安静地错, 等价于return; 2+2; 后面的加法被无视了.
return
    2 + 2;

3)
下面来看一组js的真值表:
'' == '0' //false
0 == '' //true
0 == '0' //true
false == 'false' //false
 false == '0' //true
false == undefined //false
false == null //false
null == undefined //true
 " \t\r\n" == 0 //true

看到这里....叫语言吗....

3--Java
1)都是封装惹的祸
Integer foo = 1000;
Integer bar = 1000;
foo <= bar; // true
foo >= bar; // true
foo == bar; // false
不过如果值的大小在8位之内, 则情况不一样了:
Integer foo = 42;
 Integer bar = 42;
foo <= bar; // true
foo >= bar; // true
foo == bar; // true

解释:java对整数的封装用到了一个优化机制,对于-128到127之间的数(因为常用吧),
有一个256个元素大小的整数对象cache, 所有范围内的整数都从这个静态的盒子里获得,
所以两个范围内的数实际上获得了相同的对象, 而大的则会真的new一个出来,
所以两个大数就是不同的对象.
C#没有这个问题.

2)finally--又是一个C#不允许的用法

try { return true; }
finally { return false; }
或者
try { throw new AssertionError(); }
finally { return false; }

两个都是返回了false.

3)
int[] numbers() {
  return null;
}

等价于这个:
int numbers() []
{ return null; }

4--APL语言, 这个语言就是上帝创造的(1964)....
给一个链接,我不敢解释.


5--PHP 不喜欢字符串
"01e4" == "10000"
php不喜欢字符创, 所以只要有一个可能,它就把字符串转化为别的东西,
这里也许你仅仅想比较一下字符串, 但是, 不可以......


6--C++
这个库用来"文学性"地计算几何.
注意,这不是 语言扩展, 这是标准C++.
~weegen/eelis/analogliterals.xhtml


assert( ( o-------------o |L \ | L \ | L \ | o-------------o | ! ! ! ! ! o | ! L | ! L | ! L| ! o-------------o ).volume == ( o-------------o | ! ! ! ! ! o-------------o ).area * int(I-------------I) );


7--Perl 这个真是怪物....
  • $# — not a comment!
  • $0, $$, and $? — just like the shell variables by the same name
  • $ˋ, $&, and $' — weird matching variables
  • $" and $, — weird variables for list- and output-field-separators
  • $! — like errno as a number but strerror(errno) as a string
  • $_ — the stealth variable, always used and never seen
  • $#_ — index number of the last subroutine argument... maybe
  • @_ — the (non)names of the current function... maybe
  • $@ — the last-raised exception
  • %:: — the main symbol table, for cryin’ out loud!
  • $:, $^, $~, $-, and $= — something to do with output formats
  • $. and $% — input line number, output page number
  • $/ and $\ — input and output record separators
  • $| — output buffering controller
  • $[ — change your array base from 0-based to 1-based to 42-based: WHEEE!
  • $} — nothing at all, oddly enough!
  • $<, $>, $(, $) — real and effective UIDs and GIDs
  • @ISA — names of current class’s superclasses
  • $^T — script start-up time in epoch seconds
  • $^O — current operating system name
  • $^V — what version of Perl this is
更完整的内容:


后面的好像都不太典型了, 暂就这些了.
阅读(1063) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~