最近Stack Overflow上有一群讨厌perl的人,所以我想我应该把我的“关于你最喜欢的语言你讨厌的五件事”的问题带到Stack Overflow上。拿你最喜欢的语言来说,告诉我你讨厌它的五件事。这些可能只是让你烦恼的事情,承认的设计缺陷,公认的性能问题,或任何其他类别。你只需要讨厌它,它必须是你最喜欢的语言。

不要拿它和其他语言比较,也不要谈论你已经讨厌的语言。不要用你最喜欢的语言谈论你喜欢的事情。我只是想听到你讨厌但能容忍的东西,这样你就可以使用所有其他的东西,我想听到你希望别人使用的语言。

每当有人试图把他们最喜欢的语言强加给我时,我就会问这个问题,有时是面试问题。如果有人找不出他最喜欢的工具的5个缺点,那他对它还不够了解,不能提倡它,也不能利用它赚大钱。他还没有在足够多的不同情况下使用它来充分探索它。他把它作为一种文化或宗教来倡导,这意味着如果我不选择他最喜欢的技术,我就错了。

我不在乎你用什么语言。不想使用特定的语言?那就不要。你通过尽职调查做出了明智的选择,但仍然没有使用它?好吧。有时正确的答案是“你有一个强大的编程团队,有良好的实践和丰富的Bar经验。改成Foo是愚蠢的。”


This is a good question for code reviews too. People who really know a codebase will have all sorts of suggestions for it, and those who don't know it so well have non-specific complaints. I ask things like "If you could start over on this project, what would you do differently?" In this fantasy land, users and programmers get to complain about anything and everything they don't like. "I want a better interface", "I want to separate the model from the view", "I'd use this module instead of this other one", "I'd rename this set of methods", or whatever they really don't like about the current situation. That's how I get a handle on how much a particular developer knows about the codebase. It's also a clue about how much of the programmer's ego is tied up in what he's telling me.

憎恨并不是衡量人们了解多少的唯一尺度,但我发现它是一个相当不错的尺度。他们讨厌的事情也让我知道他们对这个话题的思考有多好。


当前回答

哇,我很惊讶SQL还没有出现在这里。我猜这意味着没有人喜欢它:)

跨实现的语法不一致 细微的代码差异可能会因为看似模糊的原因而产生巨大的性能影响 对文本操作的支持很差 入门成本低,但掌握这门语言的学习曲线陡峭 最大限度地标准化社区的最佳实践,这包括语法风格。

...还有一些额外的讨厌它的理由,不需要额外收费

the WHERE clause goes last, making it easy to prematurely execute an UPDATE or DELETE, destroying the whole table. Instead, the WHERE should go somewhere up front. It's difficult to implement relational division. I can set a value to NULL, but I can't test it for equality with NULL. I can check IS NULL, but that just complicates code -- needlessly so, in my opinion. Why do we need to completely respecify the formula for a GROUPed column, rather than setting an alias on the column and then GROUP BY the alias (or column index as with SORT)?

其他回答

Lua

If you do foo.bar(1,2) then 'self' is nil inside the bar method. You must remember to do foo:bar(1,2) instead. I'd rather have that switched ('self' should be defined by default unless you use the ':' operator, or you call a function that isn't a method). Variables are global by default. I'd rather ditch the 'local' keyword and have a 'global' one instead. Undeclared variables are assigned the nil. I'd rather receive an error message. You can sidestep this by manipulating the global env's metatable, but I'd rather have it implemented by default and be able to deactivate it. Multiple returned values on parameters are not handled very nicely. Say you have a function foo() that returns 1,2,3 (three values) and bar() returns 4,5 (two values). If you do print(foo(),bar()) you will get "1,4,5" ... only the "last" tuple is expanded on calls. The # (table length) operator only works in tables indexed with continuous integers. If your table isn't like that and you want to know how many elements does it have, you need to either parse it with a loop, or update a counter each time you insert/remove an element from it.

C#

5. 空合并运算符

的? ?运算符允许你写:

x = y ?? z;

而不是:

x = (y == null) ? y : z;

我喜欢这个运算符,但我想要另一个:

x = y ??? y.foo() : z.foo();

而不是

x = (y == null) ? y.foo() : z.foo();

我一直在使用这种东西,而且我发现输入== null部分很烦人。


4. 平等应该有更好的支持

我必须启动每个Equals(object obj)方法: MyClass other = obj作为MyClass; If (other == null)返回false;

你只需要写:

public override bool Equals(MyClass other) {...}

语言应该注意提供Equals(object obj)方法。 注意:other必须保证不为空。


3.不能使用不同类型的三元运算符

这不能编译,我认为它应该编译!

string foo = "hello";
int bar = 4;
object baz = foo == null ? foo : bar;

2. 缺少命名空间private

我喜欢内部保护,但我希望有一种保护只允许从同一名称空间内进行访问。这样可以更好地控制大型类库的访问。


1. 没有多重继承

我实际上只对接口的默认实现使用实现(类)继承,但很多时候我想这样做。

C#

我对c#非常满意,但这两个真的让我很恼火:

Constructor-based initialization for immutable classes is less convenient, less intuitive (when you read the code you don't understand what you assign to what), has less IDE backing than inline object initialization. This makes you lean towards mutable classes inevitably. I know this has been mentioned before, but I strictly have problems with initialization syntax for immutable classes. switch is too verbose. Whenever I see a situation where a switch would be proper, I'm really inclined to use an if..else if.. just because it's more terse (~30% less typing). I think there should be no fallthrough for switch, break should be implied, and case should allow comma separated list of values.

Objective-C / Cocoa / Cocoa Touch:

Lack of namespaces Difficulty using primitive values with any of the interesting and powerful techniques of Cocoa, e.g., distributed objects, notifications, KVO Inconsistency with the use of the shortcut dot syntax for accessing properties, often having to use the full length accessors No GC on the iPhone, and generally GC came rather late to an otherwise highly dynamic language Inconsistent library support, at least in Cocoa Touch; some very basic things have only recently gotten high level support, e.g., audio handling. Lack of blocks!

C#

Cannot create a reference (var &t = struct) No local scope destructors (IDispose comes close but its not the same) ToString, i almost dislike that every object has it but it turns out i dislike everything using it like string.format does. I rather have things that accepts a certain type (like ints, floats, text, chars only). So instead of passing in any object i need to pass in something with a implicit typecast or interface. I ended up writing something like this to safely escape text for html which worked great. Cannot use a virtual typecast (blah)obj; does not work if obj does not inherit/has an interface of blah. Simple workaround is to supply an interface with a convert function. Has no local creation. Instead of writing var o = new Item(); i would like to write (something like) Item o() (with an automatic dispose if it has one).