Feed aggregator

What about a "preferred" keyword in TypeScript?

Hacker News - 15 hours 25 min ago

95% of the time these days, when I'm trying to figure out how to make some imported piece of code do what I need it to do, I'm relying on the IDE to jump my way through interfaces and types until I find what I need.

Wouldn't it be cool if instead of just public, protected and private, there was also a "preferred" keyword that told IDEs that this is a public method or attribute that was ALSO meant for people to use?

The concept of "public/private" is great for class inheritance. But not so great for building an API. So we resort to naming conventions: An API might have its own internally public methods, but name certain ones certain ways and block calls that try to access them. Wouldn't it be nice if you could say this method is "public" but not "open" to certain calls, or not "preferred" for someone hooking the API? A sprite might have an .x and an ._x, and we assume we should probably assign things to the .x or something weird might happen. But lots of codebases still make ._x public, for various reasons. I'm thinking here of Pixijs's Container.pivot._x. While the underscore is clearly a warning of some kind not to do things this way, there's nothing about public ._x that makes it stand out from public .set(x,y), besides that underscore. Wouldn't it be nice if the suggested methods were somehow, like, suggested by the IDE when you try to use another method to set something like that?

This could be as simple as adding a `preferred` keyword to a public method, and then sticking `prefer [method]` into the comments of another public method that refers to it. Your little light bulb in VSCode would say "You should prefer pivot.set() to directly assigning pivot._x". Or something like that.

Stray thought. Obviously, this is just a sugar concept, doesn't affect code relationships at all, but I feel like it would really help as a way to document code as you go along, especially when some methods do need to be exposed to internal code but really shouldn't be used externally.

Comments URL: https://news.ycombinator.com/item?id=43651911

Points: 2

# Comments: 2

Categories: Hacker News

Show HN: An app that applies the concept of Git to todos

Hacker News - 15 hours 28 min ago

Innovative Todo List with Git Concepts

Comments URL: https://news.ycombinator.com/item?id=43651886

Points: 2

# Comments: 0

Categories: Hacker News

How can we help America?

Hacker News - 15 hours 30 min ago
Categories: Hacker News

BYDFi's Innovative Trading Approach

Hacker News - 15 hours 34 min ago

Article URL: https://www.bydfi.com/en

Comments URL: https://news.ycombinator.com/item?id=43651847

Points: 1

# Comments: 1

Categories: Hacker News

The Met Police is set deploy permanent live facial recognition cameras on street furniture in Croydon from summer 2025, but local councillors say the decision – which has taken place with no community input – will further contribute the over-policing...

Computer Weekly Feed - 15 hours 52 min ago
The Met Police is set deploy permanent live facial recognition cameras on street furniture in Croydon from summer 2025, but local councillors say the decision – which has taken place with no community input – will further contribute the over-policing of Black communities
Categories: Computer Weekly

Pages