Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I remember a 2 hours debugging session when I started learning Objective-C.

I don't remember what I did wrong but I somehow tripped over Objective-C's boolean which isn't a proper type but just a macro of an int value like it is now in C. I did probably something stupid like "if (b != TRUE) {}".

What made this so much more infuriating was that if I knew it was just a leaky abstraction over C I wouldn't have made that mistake. But I thought it was on the same level as languages from the Pascal family or Java or any other modern programming language.



> but just a macro of an int value like it is now in C.

That's not the case for the last couple of decades (I think since C99?). The underlying type of bool which is defined in stdbool.h is _Bool, which is a "proper" builtin boolean type. The type wrapping in a header is just there to not break existing code which had its own 'bool' typedef. AFAIK in C23, bool is a regular keyword now though.


The proper support is still very limited.

You can still do "bool b = 10" or "int i = true". C being C ("everything is an int") this will be coerced to 1.


> What made this so much more infuriating was that if I knew it was just a leaky abstraction over C I wouldn't have made that mistake. But I thought it was on the same level as languages from the Pascal family or Java or any other modern programming language.

Post-rationalization can always blame the tools instead of one owning its own's mistakes. You can blame tools or documentation that omit crucial surprising information or explicitly lies to you. Everything else is assomption you'd better check, or just humbly accept that they will bite you, by definition, in the most unexpected ways.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: