Worst ideas/features in programming languages?

jfondren julian.fondren at gmail.com
Mon Oct 11 17:14:39 UTC 2021


On Monday, 11 October 2021 at 15:59:10 UTC, Atila Neves wrote:
> I'm brainstorming about what I'll talk about at DConf, and 
> during a conversation with Walter I thought it might be cool to 
> talk about:
>
> * Worst features implemented in a non-toy language

Indirect method notation in Perl: 
https://stackoverflow.com/questions/11695110/why-is-this-program-valid-i-was-trying-to-create-a-syntax-error/11695310#11695310

wantarray in Perl, where e.g. reverse() either reverses its list 
of arguments (a list of one argument $a in the following 
program--a noop) or it reverses the joined string of its list of 
arguments (the single string $a in the following the program) , 
depending on what the caller wants:

```perl
sub foo {
     my ($a) = @_;
     reverse $a;
}

print foo("unchanged"), "\n";  # output: unchanged
my $changed = foo("changed");
print $changed, "\n";          # output: degnahc
```

Aliasing subroutine parameters in Perl:  `sub foo { my $arg = 
shift; }` is not the same thing as `sub foo { my ($arg) = @_; }` 
and I can no longer remember why it's super critically important 
that you use the second form by default.

Autovivification in Perl - usually desirable, and D has it to an 
extent in AAs. But then there's this:

```perl
sub add {
     my ($table, $key) = @_;
     $table->{$key} = 1;
}

my $table;           # undef
add($table, "one");  # undef autovivifies into a hashref ... only 
within add()
die "that silently did nothing" if exists $table{one};
$table = {};         # an empty hashref
add($table, "two");  # empty hashref is mutated by add()
print $table{two};
```

Overriding 'built in' functions. Does `stat()` return the list of 
fields enumerated in 'perldoc -f stat' or does it return an 
object? Better check and see if the program you're maintaining 
used File::stat or not.

$_ as the default argument in Perl. Literally once a month I 
write this code:

```perl
open my $f, '<', 'open some file to read'
     or die "Tried to open 'some file to read' and failed : $!";
while (defined(my $line = <$f>)) {
     next unless /oh goddamnit this regex is applying to $_ and 
not $line/;
     do_stuff;
}
```

Perl has a lot of "wow, that was a horrible idea! Let's fix it by 
adding a new syntax, encouraging people to use that instead, and 
then leaving this horrible idea in the language forever." 
misfeatures. The separate '<' in the previous example is some new 
syntax for opening files. The old syntax lets you write tools 
that will truncate /etc/passwd or spawn arbitrary subprocesses if 
given a malicious filename. At least those dangerous tools never 
stopped working due to the language updating and breaking them, 
right?

> * Worst features (in your opinion) in D
> * Features you'd like to see in D

Maybe it's not surprising by this point of this post, but I'm 
pretty happy with D.

I would like some easy way to make sure I haven't accidentally 
used 80-bit floats in a D program.


More information about the Digitalmars-d mailing list