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

> They are pure pure pure evil.

They are to be used with caution. If your execution environment is simple enough they can be quite useful and effective. Engineering shouldn't be a religion.

> I can not count how many times I have been pulled in to debug some gnarly crash and the result was, inevitably, a mutable global variable.

I've never once had that happen. What types of code are you working on that this occurs so frequently?





> If your execution environment is simple enough they can be quite useful and effective

Saud by many an engineer whose code was running in systems that were in fact not that simple!

What is irksome is that globals are actually just kinda straight worse. Like the code that doesn't use a singleton and simply passes a god damn pointer turns out to be the simpler and easier thing to do.

> What types of code are you working on that this occurs so frequently?

Assorted C++ projects.

It is particularly irksome when libraries have globals. No. Just no never. Libraries should always have functions for "CreateContext" and "DestroyContext". And the public API should take a context handle.

Design your library right from the start. Because you don't know what execution environments will run in. And it's a hell of a lot easier to do it right from the start than to try and undo your evilness down the road.

All I want in life is a pure C API. It is simple and elegant and delightful and you can wrap it to run in any programming environment in existence.


> All I want in life is a pure C API. It is simple and elegant and delightful and you can wrap it to run in any programming environment in existence.

Sure thing boss, here's that header file populated exclusively by preprocessor macros that you asked for.


Super weird reply.



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

Search: