frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Show HN: Realtime, expressive AI personas that you can video call

https://playground.keyframelabs.com/playground/persona-1-live
1•kraddypatties•2m ago•0 comments

Ask HN: GitHub vs. self-hosted forges – What's your first impression?

1•bitbasher•3m ago•0 comments

We're Helping Companies Turn Open Source Contributions into Hiring

https://issuepay.app
1•Mario10•3m ago•1 comments

The Web Install API is ready for testing

https://blogs.windows.com/msedgedev/2025/11/24/the-web-install-api-is-ready-for-testing/
1•syx•8m ago•0 comments

Avian Influenza H5N5 Washington Death

https://www.idse.net/Influenza/Article/12-25/First-Person-Dies-From-H5N5-Bird-Flu/78941
1•howard941•10m ago•0 comments

One of the Greatest Polar-Bear Hunters Confronts a Vanishing World

https://www.newyorker.com/magazine/2025/12/01/one-of-the-greatest-polar-bear-hunters-confronts-a-...
1•bookofjoe•14m ago•1 comments

Launching the Genesis Mission

https://www.whitehouse.gov/presidential-actions/2025/11/launching-the-genesis-mission/
1•oidar•14m ago•0 comments

A P2P Grindr alternative I built in a weekend: no server, no accounts

https://meateor2.netlify.app/
1•guiprav•17m ago•1 comments

Pornhub Is Urging Tech Giants to Enact Device-Based Age Verification

https://www.wired.com/story/pornhub-is-urging-tech-giants-to-enact-device-based-age-verification/
1•toomuchtodo•19m ago•0 comments

Amazon's X-energy gets backing from Jane Street as investors bet big on nuclear

https://www.ft.com/content/59d9b7d5-e34b-4131-b80f-815208a2d4cc
1•perihelions•20m ago•0 comments

US presses Europe on rules for big tech companies

https://www.bbc.com/news/articles/clydjnlm54po
1•reqo•20m ago•0 comments

Safe Chain: Stopping Malicious NPM Packages Before They Wreck Your Project

https://www.aikido.dev/blog/introducing-safe-chain
4•nailer•22m ago•0 comments

Khosla-backed startup can track drones, trucks, and robotaxis, inch by inch

https://techcrunch.com/2025/11/20/this-khosla-based-startup-can-track-drones-trucks-and-robotaxis...
1•iamtech•28m ago•0 comments

Notes from a Pyre, by Amal Singh

https://psychopomp.com/deadlands/issue-23/pyre/
1•thunderbong•29m ago•0 comments

No copays for asthma inhalers in New York under new law

https://gothamist.com/news/breathe-freely-no-copays-for-asthma-inhalers-in-ny-under-new-law-signe...
3•geox•31m ago•1 comments

BREX Syntax Reference

https://www.proxylity.com/docs/destinations/brex-syntax.html
1•mlhpdx•32m ago•0 comments

Show HN: A faster day-count to Y,M,D algorithm – 30-40% speedup

https://www.benjoffe.com/fast-date-64
2•benjoffe•33m ago•0 comments

Enabling cheap LCD HUDs – 0.015px calibration eliminates waveguide optics

1•nighthawkcar•35m ago•1 comments

Development-Cycle in Cargo: 1.92

https://blog.rust-lang.org/inside-rust/2025/11/24/this-development-cycle-in-cargo-1.92/
1•todsacerdoti•40m ago•0 comments

Show HN: X Timeline Cleaner, block tweets by location from your X timeline

https://github.com/jawerty/X-Timeline-Cleaner
2•jawerty•42m ago•0 comments

The Colonists

https://store.steampowered.com/app/677340/The_Colonists/
1•doener•45m ago•1 comments

Fastest LLM Picker

https://metrik-dashboard.vercel.app/
1•mbouassa•46m ago•0 comments

Modern trick-taking games: beyond Whist

https://brainbaking.com/post/2025/09/modern-trick-taking-games-beyond-whist/
1•ekrapivin•50m ago•0 comments

Toyota's "Tip of the Spear" Is Choosing Rust

https://filtra.io/rust/interviews/woven-by-toyota-nov-25
2•steveklabnik•51m ago•0 comments

US Leveraged Loans Under Strain as Buyers Yank Cash from Funds

https://www.bloomberg.com/news/articles/2025-11-24/us-leveraged-loans-under-strain-as-buyers-yank...
1•zerosizedweasle•52m ago•0 comments

NeuroCode – A Structural Neural IR for Codebases

1•gabrielekarra•54m ago•0 comments

I built a micro script to monitor OpenRouter's new models launch

https://github.com/demetrius-edelin/openrouter_monitor
1•edelind•57m ago•1 comments

Unsupervised Hebbian Learning from an Artificial Intelligence Perspectives

https://www.mdpi.com/2504-4990/7/4/143
1•PaulHoule•59m ago•0 comments

SIMD Programming with Highway [video]

https://www.youtube.com/watch?v=R57biOOhnJM
1•creata•1h ago•0 comments

1,700-year-old Roman sarcophagus is unearthed in Budapest

https://apnews.com/article/hungary-roman-sarcophagus-discovery-budapest-77a41fe190bbcc167b43d0514...
3•gmays•1h ago•1 comments
Open in hackernews

Ask HN: Java why put string in a constant?

1•ramsicandra•6mo 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•6mo 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•6mo 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.