最近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.

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


当前回答

Lua

我喜欢这门语言,但是有一些事情困扰了我很多年!

No (built-in) support of binary operations (as of 5.1, it might come with 5.2). Should have a built-in binary buffer implementation, allowing for example in place long string concatenation. I know it doesn't fit well in the syntax, but sometime I miss longVariableName++ or verboseVariableName += 5. Reference assumes knowledge of C (I have it but it is a minus for newcomers) and defers some help to C reference! And sometime it is too terse. It is starting to have a good deal of libraries, but you have to get them from various places. On the other hand, the download is very small! ;-)

其他回答

C#

我的大部分抱怨都与假设c++约定自动成为c#的最佳选择有关

Class接口中不允许静态。这仍然是课程的一部分。为什么它不能成为界面的一部分?我不得不想出这么愚蠢的变通办法。 区分大小写。我知道在这一点上它会破坏遗留的应用程序,但为什么不区分大小写不是一开始的规则

对于。net的好处之一(不是c#特有的)

编译器不够聪明。在。net 3中。X,编译器可以找出“var”在编译时,为什么不其他常见的优化?我们都知道string和StringBuilder / immutable和mutable的区别。为什么编译器不为你转换它在很多情况下,显然StringBuilder比多个connect .s更好?我相信在默认情况下,编译器可以为我们做大量的其他优化(带有否决选项),并为我们节省大量的时间。

按最讨厌到最不讨厌的顺序排列。

1.) Backwards compatibility police. Yes backcompat is a strength but Perl 5 takes it too far. Now we don't really even get new features in our language without having to enable them explicitly. I'm much prefer the inverse, if a new feature causes a problem let me disable it or enforce old behavior. e.g. perl 5.10 added say I'd rather have no feature 'say' if I have my own say implemented than have to put use feature 'say'; or use 5.010; also if 5.8 worked but 5.10 didn't. I'd rather have use 5.008; to restrict my code to only use features available up to and including 5.8 if no use version; was defined then it should be defaulted to whatever version you're running, and a recommended practice of not to restrict it unless you have to.

2)。过度的样板。

#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use autodie;
use English '-no_match_vars';
use 5.010;
package Package::Name;

BEGIN {
    Package::Name::VERSION = 0.1;
}

sub somesub {
    my $self = shift;
    my ( $param1, $param2 ) = @_;
}
1;

现在你可以开始编码了。这不会因为第一条而改变。当然也有一些捷径,比如使用common::sense;或者使用modern::perl;这将缩短上面的内容,你可能需要一些稍微不同的模块或pragma。但因为第一条,我们永远无法把它降低到。

#!/usr/bin/perl
package Package::Name 0.01;

sub somesub ( $param1, $param2 ) {
}

一些模块正在帮助这一点,在5.0.12中有新的包版本,它完全允许这种语法,尽管我认为它需要使用5.012;首先,和Method::签名,但它永远不会完全解决,(在语言)。

3)。糟糕的变量选择

吸吸文件

#!/usr/bin/perl
use strict;
use warnings;
open my $fh, "< foo" or die $!;
local $/; # enable localized slurp mode
my $content = <$fh>;
close $fh;

WTF是$!和美元/ ?重写为易读。

#!/usr/bin/perl
use strict;
use warnings;
use English '-no_match_vars';
open my $fh, "< foo" or die $ERRNO;
local $INPUT_RECORD_SEPARATOR; # enable localized slurp mode
my $content = <$fh>;
close $fh;

不要忘记,如果您不想受到性能影响,'-no_match_vars'必须存在。

不直接创建匿名标量怎么样?

#!/usr/bin/perl
my $scalar_ref = \do{ my $anon_scalar };

他们就不能想出点什么办法吗?

#!/usr/bin/perl
my $scalar_ref = <>;

哦,perl是线程不友好的,因为所有的变量(包括特殊的变量)默认是全局的。至少现在你可以使用我的$_;对其词法作用域,并对其他词使用local。

4.)非常难看的语法

MooseX::Declare是一个更好的语法。我也希望->被替换为。(个人喜好不太重要)

5)。太多的TIMTOWTDI或太多的最佳实践似乎你必须读3-5本书才能弄清楚你应该如何做事情。

6)。以前的(不再适用)。Un-sane版本。5.10.0有新功能5.10.1的新功能没有设定时间,直到下一个版本。现在是每年一次的特性发布,每季度更新一次。

7)。象牙塔视角。社区问题,似乎是许多开发者想要设置更高的准入门槛,并认为可以不尊重n00b(或任何不同意他们的人)。

8)。疯狂的版本号/字符串Perl有浮点版本号,它们很难看。开发人员不知道并不是所有的下游处理版本比较的方式都是一样的。不是语言问题

0.012 # simple
5.012001 # semantic 
4.101900 # time based + version (for multiple versions in a day)
0.035_002 # prerelease

所有有效版本的perl..我们就不能用…

0.12 # simple
5.12.1 # semantic
20100713 # time based (just use the date and be careful not to need to release more than 1 a day)
0.35-beta2 # prerelease

除了

9)。升级后没有明显的方法重新安装所有XS模块

Scala是我最喜欢的语言。五件讨厌的事?容易:

Takes a long time to learn properly. I know you can write Scala as a 'better java'. That is what we used to say about C++ and C too. I agree this is an inevitable consequence of the deep ideas in the language. But still ... Methods vs. Functions: def f(x: Int) = x*x defines a method f, not a function f. Methods are not functions despite a lot of early Scala tutorial material blurring the distinction. The language tries to blur it too because if you supply a method in some places where a function is expected it is accepted. Do we have to have both methods and functions? Yes it is fundamental. But it was initially confusing to me. Composing classes or objects from mixins in the 'cake' pattern is prone to NPE's. e.g. trait X { val host: String; val url = "http://" + host } is a mixin that will NPE on instantiation, or not, depending on its position in the class declaration. The compiler could tell you if it will fail but doesn't. (In 2.7 anyway.) It is hard to diagnose the problem in complex inheritance graphs. Arrays in 2.8 rely on implicits to mesh with the main scala collection types. But implicits are not applied everywhere. An Array can be supplied where a Seq is expected. But an Option[Array] cannot be supplied where an Option[Seq] is expected. I know there are no completely 'right' ways to handle java Arrays. Type erasure. Enough said.

Lua:

The built-in error system is absolutely horrendous You can implement a try-catch system by modifying the Lua interpreter; but it has no compatibility with the errors that are thrown by the built in functions. The fact they have __newindex instead of __setindex as the setter ... and __newindex is only fired when the key doesn't already exist. If it does, no metamethod is called at all. No good type comparison system. There's the type() function but it only handles the basic types (all tables are tables). It really needs to have a metamethod for type comparisons. I've implemented this before with an 'is' operator and a __type metamethod and it works really nicely. It's a bitch to define new keywords. You can do it, but the code inside Lua isn't well documented so it's kind of trial and error to find out how to get the result you want. This is a major issue when you want to implement the things I mentioned above yourself (not so much __setindex though, that's an easy modification). I can't use it in a web browser. Yeah not really a problem with the language itself, but damn, would I love to be able to use Lua instead of Javascript... :)

C#.

我最讨厌的是:

No multiple inheritance - imagine you could provide whatever GUI framework base class (Control, Window, whatever) with MVC - related stuff, etc... framework / base class agnostic! No "friend" keyword... I know, the RAD - victims would abuse it for all kinds of stinky code and for hilarious malpractices, but it would be nice for the OOD - guys to enforce the law of demeter No language integrated DBC features, there are the Contracts, but I would rather have that Spec# - style with a general purpose "!" - postfix operator No AOP (I don't get it... this language has attributes, it would have been SO EASY to add interception code in the compiler!) No weak event delegates - the observer pattern becomes nothing but a memory leak bait as it is now... :-(