在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在C或c++中,sizeof…参数的圆括号是可选的。假设参数不是类型:
void foo() {
int int_inst;
// usual style - brackets ...
size_t a = sizeof(int);
size_t b = sizeof(int_inst);
size_t c = sizeof(99);
// but ...
size_t d = sizeof int_inst; // this is ok
// size_t e = sizeof int; // this is NOT ok
size_t f = sizeof 99; // this is also ok
}
我一直不明白这是为什么!
其他回答
Commodore BASIC的命令快捷方式。基本上大多数命令都有一个缩写形式,通常是第一个字母+ (shift+第二个字母)。但是因为C64上的字符集默认都是大写的,这些命令看起来就像奇怪的符号。下面是一个hello world的简短例子:
也许有人有更好的例子,更有实质内容,但对于长程序来说,这看起来完全是荒谬的。
以下是缩略语列表:http://www.c64-wiki.com/index.php/BASIC_keyword_abbreviation
Powerbasic (www.powerbasic.com)包含编译器指令:
# BLOAT {bloatsize}
这将使编译后的可执行文件的大小增加<bloatsize>字节。这是放在编译器中,以防创建可执行文件的人不喜欢生成的可执行文件的小尺寸。它使EXE看起来更大,以与臃肿的编程语言竞争:)
腮腺炎。WTF有很多特性,我选了一个if语句。(请注意,我在下面使用了一种相当冗长的编码风格,以适应那些不懂这门语言的人;真正的腮腺炎代码通常对外行来说更难以理解。)
if x>10 do myTag(x) ; in MUMPS "tag" means procedure/function
else do otherTag(x)
这类似于Java中的说法:
if (x > 10) {
myMethod(x);
} else {
otherMethod(x);
}
除了在MUMPS中,else语句在语法上不是if块的一部分,它是一个单独的语句,通过检查内置变量$TEST来工作。每次执行if语句时,它都会将$TEST设置为if语句的结果。else语句实际上意味着“如果$TEST为假,则执行该行剩余部分,否则跳转到下一行”。
这意味着如果x大于10,因此第一行叫做myTag,并且myTag包含if语句,那么else的行为不取决于它上面一行的if,而是取决于myTag内部的最后一个if !由于这个“特征”,MUMPS编码员通常被教导像这样编写以上代码以确保安全:
if x>10 do myTag(x) if 1
else do otherTag(x)
第一行末尾的if 1确保在控制进行到下一行之前正确地设置了$TEST。(顺便说一下,这里的间距必须是这样的,在else后面有两个空格,在所有其他地方都有一个空格。间距是奇怪的,但至少一旦你理解了模式,它是非常正交的。)
Haskell's use of Maybe and Just. Maybe a is a type constructor that returns a type of Just a, but Maybe Int won't accept just an Int, it requires it to be a Just Int or Nothing. So in essence in haskell parlance Just Int is about as much of an Int as an apple is an orange. The only connection is that Just 5 returns a type of Maybe Interger, which can be constructed with the function Just and an Integer argument. This makes sense but is about as hard to explain as it can theoretically be, which is the purpose of haskell right? So is Just really JustKindaLikeButNotAtAll yea sorta, and is Maybe really a KindaLooksLikeOrIsNothing, yea sorta again.
-- Create a function that returns a Maybe Int, and return a 5, which know is definitly Int'able
> let x :: Maybe Int; x = 5;
<interactive>:1:24:
No instance for (Num (Maybe Int))
arising from the literal `5' at <interactive>:1:24
Possible fix: add an instance declaration for (Num (Maybe Int))
In the expression: 5
In the definition of `x': x = 5
> Just 5
Just 5
it :: Maybe Integer
-- Create a function x which takes an Int
> let x :: Int -> Int; x _ = 0;
x :: Int -> Int
-- Try to give it a Just Int
> x $ Just 5
<interactive>:1:4:
Couldn't match expected type `Int' against inferred type `Maybe t'
In the second argument of `($)', namely `Just 5'
In the expression: x $ Just 5
In the definition of `it': it = x $ Just 5
祝你好运读到这篇文章,我希望它是正确的。
在c#中,这至少应该生成一个编译器警告,但它没有:
public int Something
{
get { return Something; }
set { Something = value; }
}
当被调用时,它会导致你的应用程序崩溃,你不会得到一个好的堆栈跟踪,因为它是一个StackOverflowException。