osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Lies in education [was Re: The "loop and a half"]


On 11/10/2017 15:36, Chris Angelico wrote:
> On Thu, Oct 12, 2017 at 1:14 AM, bartc <bc at freeuk.com> wrote:
>> Python, maybe. C syntax isn't as painful as C++ but I still have a lot of
>> trouble with it. (Eg. the variable declaration 'char(*(*x[3])())[5]'. The
>> name of the variable can be found lurking in that lot somewhere, but what's
>> the type?) Not so convenient.
> 
> People love showcasing stupid examples like that. But how often do you
> REALLY make declarations that complex? That's not technically
> strawmanning, since C syntax does indeed include that, but you're
> cherry-picking the most extreme example.

Sure. Statistically most declarations are going to be things like 'int' 
or 'char*. But more complicated ones (usually not as bad as the 
example), crop up often enough to be a nuisance.

I may see them more than others because I very often need to interface 
one of my languages with some API defined in C, and I need to exactly 
understand what the types are so that I can create compatible ones.

Anyone else can just include the apposite headers and be done with it 
without needing to see what's inside.

While on the subject of C syntax, here are some fun ambiguities:

f(x);    // call function with arg x, or declare x of type f?

a*b;     // multiply a by b, or declare b of type pointer to a?

(a)*b    // multiply a by b, or cast *b to type a?

I understand that in C++, you also have things like this, but in spades.

-- 
bartc