Worst ideas/features in programming languages?

bachmeier no at spam.net
Mon Oct 11 19:15:51 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

C's pointer notation is too stupid for words. (I understand how 
it works. I've been using it for decades. Please no explanations.)

Writing functions like this is horrible:

```
int timesTwo(int *x) {
	return 2 * *x;
}
```

When you learn C, you ask what the `*x` is. It's an int. That 
makes sense. That's why it's `int *x`. Okay, let's call that 
function:

```
int main() {
	printf("%d\n", timesTwo(4));
	return 0;
}
```

`expected ‘int *’ but argument is of type ‘int’`

Okay, let's try this:

```
int main() {
	int z = 4;
	printf("%d\n", timesTwo(&z));
	return 0;
}
```

`8`

So `*x` is an int, but you have to pass `&z`, which is not an 
int, as the argument. The only way this can't be confusing to 
someone learning it for the first time is if they're memorizing 
syntax.


More information about the Digitalmars-d mailing list