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

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


当前回答

C

It's so flexible and powerful that it's really easy to write really awful, or downright dangerous code (or, if you prefer, "with great power comes great responsibility"). '=' for assignment, and '==' for equality; easy to confuse in 'if' statements. The implementation of a number of fundamental parts of the language are compiler-dependent; e.g. the size of the basic types, order of bits in bitfields, padding and byte order in unions. Bitfields aren't parameterisable (i.e. you can array of ints, but you can't have an array of bits). String handling could be improved.

其他回答

c# / .net:

Classes should be sealed by default There should be no lock statement - instead, you should have specific locking objects, and there should be methods such as Acquire which return disposable lock tokens. Corollary: there shouldn't be a monitor for every object. GetHashCode() and Equals() shouldn't be in System.Object - not everything's suitable for hashing. Instead, have an IdentityComparer which does the same thing, and keep the IComparer<T>, IComparable<T>, IEqualityComparer<T> and IEquatable<T> interfaces for custom comparisons. Poor support for immutability Poor way of discovering extension methods - it should be a much more conscious decision than just the fact that I'm using a namespace.

这些都是我想出来的,明天问我,我会想出一个不同的5个:)

以下是我不喜欢Java的一些地方(它不是我最喜欢的语言):

Generics type erasure (i.e. no reified generics) Inability to catch multiple exceptions (of different types) in a single catch block Lack of destructors (finalize() is a very poor substitute) No support for closures or treating functions as data (anonymous inner classes are a very verbose substitute) Checked exceptions in general, or more specifically, making unrecoverable exceptions checked (e.g. SQLException) No language-level support for literal collections No type-inference when constructors of generic classes are called, i.e. the type parameter(s) must be repeated on both sides of the '='

Perl

Mixed use of sigils my @array = ( 1, 2, 3 ); my $array = [ 4, 5, 6 ]; my $one = $array[0]; # not @array[0], you would get the length instead my $four = $array->[0]; # definitely not $array[0] my( $two, $three ) = @array[1,2]; my( $five, $six ) = @$array[1,2]; # coerce to array first my $length_a = @array; my $length_s = @$array; my $ref_a = \@array; my $ref_s = $array; For example none of these are the same: $array[0] # First element of @array @array[0] # Slice of only the First element of @array %array[0] # Syntax error $array->[0] # First element of an array referenced by $array @array->[0] # Deprecated first element of @array %array->[0] # Invalid reference $array{0} # Element of %array referenced by string '0' @array{0} # Slice of only one element of %array referenced by string '0' %array{0} # Syntax error $array->{0} # Element of a hash referenced by $array @array->{0} # Invalid reference %array->{0} # Deprecated Element of %array referenced by string '0' In Perl6 it is written: my @array = ( 1, 2, 3 ); my $array = [ 4, 5, 6 ]; my $one = @array[0]; my $four = $array[0]; # $array.[0] my( $two, $three ) = @array[1,2]; my( $five, $six ) = $array[1,2]; my $length_a = @array.length; my $length_s = $array.length; my $ref_a = @array; my $ref_s = $array; Lack of true OO package my_object; # fake constructor sub new{ bless {}, $_[0] } # fake properties/attributes sub var_a{ my $self = shift @_; $self->{'var_a'} = $_[0] if @_; $self->{'var_a'} } In Perl6 it is written: class Dog is Mammal { has $.name = "fido"; has $.tail is rw; has @.legs; has $!brain; method doit ($a, $b, $c) { ... } ... } Poorly designed regex features /(?=regexp)/; # look ahead /(?<=fixed-regexp)/; # look behind /(?!regexp)/; # negative look ahead /(?<!fixed-regexp)/; # negative look behind /(?>regexp)/; # independent sub expression /(capture)/; # simple capture /(?:don't capture)/; # non-capturing group /(?<name>regexp)/; # named capture /[A-Z]/; # character class /[^A-Z]/; # inverted character class # '-' would have to be the first or last element in # the character class to include it in the match # without escaping it /(?(condition)yes-regexp)/; /(?(condition)yes-regexp|no-regexp)/; /\b\s*\b/; # almost matches Perl6's <ws> /(?{ print "hi\n" })/; # run perl code In Perl6 it is written: / <?before pattern> /; # lookahead / <?after pattern> /; # lookbehind / regexp :: pattern /; # backtracking control / ( capture ) /; # simple capture / $<name>=[ regexp ] /; # named capture / [ don't capture ] /; # non-capturing group / <[A..Z]> /; # character class / <-[A..Z]> /; # inverted character class # you don't generally use '.' in a character class anyway / <ws> /; # Smart whitespace match / { say 'hi' } /; # run perl code Lack of multiple dispatch sub f( int $i ){ ... } # err sub f( float $i ){ ... } # err sub f($){ ... } # occasionally useful In Perl6 it is written: multi sub f( int $i ){ ... } multi sub f( num $i ){ ... } multi sub f( $i where $i == 0 ){ ... } multi sub f( $i ){ ... } # everything else Poor Operator overloading package my_object; use overload '+' => \&add, ... ; In Perl6 it is written: multi sub infix:<+> (Us $us, Them $them) | (Them $them, Us $us) { ... }

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

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模块

C#

c#最让人讨厌的是:

(1)事件具有对所有侦听器的强引用,从而防止了侦听事件的任何东西的垃圾收集。如果你想看到这造成的问题,只需在网上搜索所有试图通过创建某种“弱引用事件处理程序”来解决问题的人。

(2)在调用一个事件之前,需要检查它是否等于null,这似乎应该由语言来处理。

(3) XML序列化器无法读取/写入XML文件中的注释。在手工修改XML文件和用c#编写的工具修改XML文件的环境中,情况并不好。可以通过使用原始的XmlDocument来解决,但如果能够将其抽象到一个类中会更好。

(4)构建过程不允许您直接访问xsd文件之类的东西,相反,您需要一个中间步骤,即创建一个c#部分类。这也会导致XAML文件出现问题,有时需要重新构建两次才能使更改正确地通过。

(5)不支持CPU intrinsic,如MMX和SSE 1,2,3,4,因此这些有价值的CPU特性在运行c#应用程序时无法使用。

其他没有进入我的前5名:

(6)不能将字段标记为属性,所有属性必须从一开始就显式地实现:

目前有:

public class MyClass {
    private int someInt;

    public int SomeInt {
        get {
                return someInt;
        }
        set {
                someInt = value;
        }
    }
}

public class MyClass {
    [IsProperty(public, get, set)]
    private int someInt;
}

(7)不支持多个返回值,例如:

public int, string, double MyFunction()
{
    ....
    return x,y,z;
}


public void TestMyFunction()
{
    int x, string y, double z = MyFunction();
}

(8)不支持协变返回类型

我对泛型实现有一些不满,但我就此打住。我认为c#是一种很棒的语言,可以完成所有的GUI、网络和配置管道,并且是我的首选语言,可以以一种可以长期支持的方式快速启动和运行。