Hacker News new | past | comments | ask | show | jobs | submit | jnspts's comments login

  C11 added _Generic to language, but turns out metaprogramming by inhumanely abusing the preporcessor is possible even in pure C99: meet Metalang99 library.
I'm actually working on a library doing just that! It's still in very (very) early development, but maybe someone may find it to be interesting. [1]

Link [2] is the implementation of a vector. Link [3] is a test file implementing a vector of strings.

[1]: https://github.com/jenspots/libwheel

[2]: https://github.com/jenspots/libwheel/blob/main/include/wheel...

[3]: https://github.com/jenspots/libwheel/blob/main/tests/impl/st...


The downvotes make me laugh, I did something pretty similar not long after the _Generic keyword came out and remember getting a pretty icy reception even though I was pretty up front about how painful and crufty it is.

https://abissell.com/2014/01/16/c11s-_generic-keyword-macro-...


C++ Metaprogramming is also just a bunch sugarcoated preprocessor macros and it was never someting else.


The fundamental difference is the C preprocessor is actually a language independent of C. They follow their own grammars, syntax, semantics, symbol tables, etc., and do not communicate with each other.


This is plainly not true


It's not an array, but a way of using a variable as a key in an object.

const name = "key"

const example = { [name]: "value" };

This would result in

const example = { key: "value" };


So if we know Symbol.dispose in advance we can simplify the code? Why did they make it so unwieldy especially since it is a new functionality not requiring backwards compatibility hacks?


Symbol.dispose is just a well-known symbol. Symbols are a fundamental part of the language, not a hack.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...


> So if we know Symbol.dispose in advance we can simplify the code?

Symbol.dispose is Symbol.dispose. It's a singleton object and that's the sole reference to it.

> Why did they make it so unwieldy especially since it is a new functionality not requiring backwards compatibility hacks?

1. Bare names in object keys are strings, so there needs to be an "escaping" syntax for non-string keys, that is what the brackets have done since 2015, in order to support the addition of...

2. Non-conflicting keys, which are what symbols are: symbols are guaranteed not to conflict with any string, and even to be unique unless they're created using `Symbol.for` (which accesses and stores into a global registry, this allows adding protocol methods to all objects without the risk of breaking existing any (by triggering new and unexpected behaviour).


> So if we know Symbol.dispose in advance we can simplify the code?

Symbol.dispose is not a string, but a symbol. Its value cannot be written out in the code, only referred to indirectly (that is basically what symbols are for), nor is there special syntax for properties with symbol keys like there is for properties with string keys, because that would be a nonsensical proposition due to the aforementioned fact. Thus, you cannot just write the property name directly, you have to use the computed property name syntax: [Symbol.dispose].


It wouldn't be any different:

    const dispose = Symbol.dispose
    const resource = { [dispose]: () => {...} }


Depending on the model, the camera might be physically disabled when the lid closes. [1]

In general, if you don't trust a device one hundred percent, you shouldn't use it anyway. You have no way of knowing whether or not your company enabled the root user and added some shady, untraceable-to-you software prior to giving you the device. Also, Apple MDM software is zero-configuration, so they wouldn't even have to open the box. [2]

Why not just ask your employer what kind of tracking they do, though? I would totally understand them tracking the location of the device for insurance reasons, as long as they are transparant about it. It's still company property. "Listening" to the microphone seems a major breach of privacy whether you're at work or at home, and I'm sure your local laws prevent you against that kind of corporate behavior. Also, who would want to work for a company that does that, anyway?

I'd just use my personal device for personal stuff.

[1]: https://support.apple.com/en-gb/guide/security/secbbd20b00b/... [2]: https://www.apple.com/business/docs/site/Mac_Deployment_Over...


Interesting for sure. But it’s not FOSS, which really is a shame. Can’t know for sure that it’s not phoning home unless you’re sniffing packets 24/7.


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

Search: