frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

University Approves Nuclear Weapons Data Center, Township Vows to Fight On

https://www.404media.co/ypsilanti-michigan-data-center-vote/
1•cdrnsf•45s ago•0 comments

The Darkest Timeline

https://taoofmac.com/space/blog/2026/11/23/1952
1•rcarmo•1m ago•0 comments

Free eye-tracking exercises for children

https://kuky.app/
1•martinvsly•2m ago•0 comments

The Code Walk: Learning a Codebase You Didn't Write

https://twitter.com/EdwardAtCI/status/2124371398315630974
2•aoakenfo•3m ago•0 comments

Where Dragons Came From: The Fossils Behind the Myths

https://mossandfog.com/where-dragons-came-from/
2•speckx•4m ago•0 comments

Show HN: BetrayalBench – 12 frontier LLMs write for the counterparty, not you

https://hive.com/betrayal
1•johnfurneaux•5m ago•0 comments

Tell HN: Google Earth now has 14 days weather forecast

1•szemy2•6m ago•0 comments

Ukraine's Number One Supporter: Howard Buffett

https://www.forbes.com/sites/forbesinternational/2026/11/21/how-warren-buffetts-son-howard-buffet...
1•Tomte•7m ago•0 comments

How many miles did Jesus walk?

https://jesussavescities.com/how-far-did-jesus-walk/
1•titusblair•7m ago•0 comments

RH proof size – 82.4% of the original code lines left

https://rh-shrink.github.io
1•myth_drannon•7m ago•0 comments

Wirecutter: Keurig and Lavazza 'podless' coffee makers

https://www.nytimes.com/wirecutter/reviews/keurig-lavazza-podless-coffee-makers/
1•altairprime•8m ago•0 comments

UQ researchers send an unblockable message using gravity

https://news.uq.edu.au/2026-11-uq-researchers-send-unblockable-message-using-gravity
1•mempko•8m ago•1 comments

Math in the Age of AI

https://mathematics.jhu.edu/2026/11/20/math-in-the-age-of-ai/
1•artninja1988•9m ago•0 comments

Show HN: BeforeYouMove – sourced reports on a street or neighborhood

https://www.beforeyoumove.homes/
1•christianalmurr•9m ago•1 comments

HTTP/1.1 must die: the desync endgame (2025)

https://portswigger.net/research/http1-must-die
2•colejohnson66•9m ago•0 comments

An updated Clairic and Clairic-flash are now open-weight

https://blog.cloudflare.com/open-clairic/
1•gmays•12m ago•0 comments

Mathematicians astounded by AI and human-written proofs of Riemann Hypothesis

https://www.nature.com/articles/d41586-026-03812-7
1•Anon84•12m ago•0 comments

Ask HN: Harness vs. Feature Factories

1•bironran•13m ago•0 comments

Humanity's Last System: Coding agents building inference systems from scratch

https://hlsbench.com/blog/introducing-hls/
1•matt_d•15m ago•0 comments

The Bottleneck Above Us: Launch capacity is the real constraint in space

https://intrinsiq.substack.com/p/the-bottleneck-above-us
1•liamlue•16m ago•0 comments

Norway links energy firm cyberattacks to critical Azure API Management flaw

https://www.theregister.com/security/2026/11/23/norway-links-energy-firm-cyberattacks-to-critical...
2•gvieri•17m ago•0 comments

A new, faster Emacs package to do image triage

https://lars.ingebrigtsen.no/2026/11/23/a-new-faster-emacs-package-to-do-image-triage/
1•Tomte•20m ago•0 comments

Autonomous Republic of Noobia – The Forge

https://github.com/chu4urdolen/noobia
3•tom_the_noob•23m ago•0 comments

Hearthly

https://jikol1906.github.io/Hearthly/
1•bookofjoe•24m ago•0 comments

Stop the Hemp Ban Before December 11th – U.S. Hemp Roundtable

https://hempsupporter.com/bill/stop-the-hemp-ban-before-december-11th/
2•bilsbie•25m ago•0 comments

FastFrames: Video Generation at Interactive Latency

https://apple-aiml-research.github.io/ml-fastframes/
1•gmays•29m ago•0 comments

Goodbye, World: The End of Programmers

https://www.wired.com/story/goodbye-world-the-end-of-programmers/
3•sssilver•29m ago•2 comments

Ernie-5.5-Flash-Preview forfeited our chess game after 16 moves: no legal move

https://hypeorcode.com/chess/
1•aistripes•30m ago•0 comments

Are newer AI models getting better at self-improvement?

https://twitter.com/Harman26Singh/status/2124911857064640826
1•harman2607•31m ago•0 comments

ATF Boston warns of device that turns handguns into automatic weapons

https://www.wcvb.com/article/it-just-kind-of-goes-wild-atf-boston-warns-of-device-that-turns-hand...
1•mroche•35m 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.