frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Why American data centers can't plug in

https://worksinprogress.co/issue/why-american-data-centers-cant-plug-in/
1•paulpauper•2m ago•0 comments

The Metaculus Democracy Threat Index

https://www.astralcodexten.com/p/the-metaculus-threat-to-democracy
1•paulpauper•2m ago•0 comments

What if ideas aren't getting harder to find, after all?

https://www.ft.com/content/72b96cb4-15f3-4bfc-a0b7-dabc31bbe1fa
1•paulpauper•2m ago•0 comments

Astryx Design System

https://astryx.atmeta.com/
2•tilt•4m ago•0 comments

Give GitHub Copilot CLI real code intelligence with language servers

https://github.blog/ai-and-ml/github-copilot/give-github-copilot-cli-real-code-intelligence-with-...
2•mariuz•7m ago•0 comments

ExtSteamGame: Explainable Steam Recommendations from Game Reviews

https://nextsteamgame.com
1•apeczon•7m ago•0 comments

A History of Tug-of-War Fatalities

https://priceonomics.com/a-history-of-tug-of-war-fatalities/
1•EndXA•8m ago•0 comments

Lufthansa Asked for My Credit Card

https://yashgarg.dev/posts/lufthansa-credit-card/
2•speckx•9m ago•0 comments

<LoginWithChatGPT /> – Unofficial login to personal ChatGPT subscription

https://twitter.com/saviomartin7/status/2070531441415602469
1•saviomartin•10m ago•0 comments

Reckoning with the Political Economy of AI

https://arxiv.org/abs/2604.16106
1•andyjohnson0•12m ago•1 comments

NYT slams Microsoft for building copyright-infringing supercomputer for OpenAI

https://arstechnica.com/tech-policy/2026/06/microsoft-built-supercomputer-to-help-openai-infringe...
1•01-_-•12m ago•0 comments

'Edited' human embryos reveal secrets of our development–and fuel ethical debate

https://www.nature.com/articles/d41586-026-02027-0
2•bookofjoe•14m ago•1 comments

Full duration single-engine static fire test of Starship 40

https://twitter.com/spacex/status/2070482358369763674
1•ivewonyoung•15m ago•0 comments

How to Design Search for a Database

https://bonsai.io/blog/how-to-design-search-for-a-database/
1•binarymax•15m ago•0 comments

Show HN: Statey – the database your AI shares across every chat, over MCP

https://www.statey.ai
2•scottwillman•16m ago•0 comments

Perplexity's Brain Is a Context Graph. That's the Point

https://hydradb.com/blog/perplexity-brain-context-graph
1•manveerc•17m ago•0 comments

Open Letter to Compassionate, Left-Leaning, AI-Hating, Animal-Loving Meat Eaters

https://brennan.day/an-open-letter-to-compassionate-left-leaning-ai-hating-animal-loving-meat-eat...
1•speckx•17m ago•0 comments

Posthog's marketing budget in 2026 (with actual $ figures)

https://posthog.com/founders/actual-marketing-budget-2026
1•herbertl•20m ago•0 comments

MirrorCode: What's the largest software project AI can complete on its own?

https://epoch.ai/MirrorCode
2•tadamcz•20m ago•1 comments

Reed-Solomon for OCR: error correction for messy printed codes

https://github.com/chasangchual/reed-solomon-for-ocr
1•chasangchual•22m ago•0 comments

Aircraft crashes into Beijing's tallest skyscraper, triggering evacuations

https://www.dailymail.com/news/article-15932611/Aircraft-crashes-Beijings-tallest-skyscraper-trig...
2•Bender•24m ago•0 comments

DuckDuckGo, Unable to Resist AI's Pull, Mistakenly Claims Trump Died of Rabies

https://gizmodo.com/duckduckgo-unable-to-resist-the-pull-of-ai-mistakenly-claims-trump-died-of-ra...
1•gnabgib•25m ago•0 comments

PHP and TypeScript Types Comparison

https://gitlab.com/-/snippets/6005114
1•DPDmancul•25m ago•0 comments

Smart lock maker Level has been gutted and its founders are out

https://www.theverge.com/tech/957802/level-lock-layoffs-assa-abloy-kwikset-smart-lock-cloud
2•teepo•25m ago•0 comments

Chronic Pain: The Science of Unlearning Pain

https://www.zeit.de/gesundheit/2025-11/chronic-pain-causes-treatments-pain-perception-english
3•Tomte•26m ago•1 comments

PlayStation Is Deleting 551 Movies from Customers' Accounts

https://kotaku.com/playstation-store-movies-digital-studio-canal-terminator-2000711013
2•ortusdux•27m ago•0 comments

US auto regulators want to kill robotaxi brake pedals

https://www.theregister.com/offbeat/2026/06/26/us-auto-regulators-want-to-kill-robotaxi-brake-ped...
2•Bender•28m ago•0 comments

Yen's decline makes perfect sense to some analysts

https://www.japantimes.co.jp/business/2026/06/26/markets/sticky-weak-yen-june/
3•mikhael•29m ago•0 comments

Microsoft extends Windows 10 security updates to 2027

https://arstechnica.com/gadgets/2026/06/microsoft-adds-another-year-to-windows-10-extended-update...
1•Lihh27•29m ago•0 comments

The Atari Lynx Story [video]

https://www.youtube.com/watch?v=RcjbMCRErz4
2•thm•29m ago•0 comments
Open in hackernews

Ask HN: Java why put string in a constant?

1•ramsicandra•1y ago
I'm relatively new to Java. I often notice a pattern where there is a list of constant which value are equal to the name.

  class Constant {
    public static final String ALBUM = "album";
    public static final String NAME = "_name";
    public static final String DISPLAY_NAME = "display-name";
    public static final String SERVICE_NAME_METRIC_NAME_PREFIX = "service_name.metric_name";
  }

Here is a public example of this practice I could find: https://developer.android.com/reference/android/provider/MediaStore.MediaColumns

I could understand that this might help in 2 ways refactoring and typo. This reduces chance of typo because you'll get compile error instead of run-time error if you typo a constant. This might also help in refactoring if you ever wants to change the value. but if may use this android public API example, I don't think it's wise to change a field name ever. If it's decommissioned, it's good to keep it so we don't re-use the field. If it's a new better field available, I think it should have a different name. I maybe making a straw man argument here. Let me know. If it's an internal API where such refactoring might make sense -- I still kind of think internal API should also be backward compatible, replacing a string are not a complicated operation in my opinion.

I see that this practice has a cost. One being that in every class that use this API. You need to add an import. It's also often the const is only used once from my experience.

  import static com.example.MediaFields.NAME;
  import static com.example.MediaFields.DISPLAY_NAME;

  String value = json.getString(NAME);
  String value2 = json.getString(DISPLAY_NAME);
vs

  String value = json.getString("name");
  String value2 = json.getString("display_name");
You write 1 line for declaration plus 2 lines for each class using this API. This is not a big deal in terms of LoC and I'm not an LoC police. However, my sense is the cost outweigh the benefit.

What do you think?

Comments

lanna•1y ago
You just made TWO typos: "display-name" vs "display_name" and "_name" vs "name", automatically counter-argumenting your point.

It is also for documentation. With the declared constants, we know all possible values. With plain strings, how am I supposed to know which values to use?

The benefits far outweigh the marginal cost.

ramsicandra•1y ago
The -, _, and leading _ are just variations of white space / separator I have encountered. I think it's possible to document all the allowable values in the Javadoc section of the function that takes in string as their argument.

In the specific android example, I would put it here. Under projection params where it takes in all the Images.Media.* string consts.

https://developer.android.com/reference/android/content/Cont...

Though, if it's a practice of Java Engineer to document allowable enum like string as a constant, then I can say that's a valid argument.