frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Show HN: TUI for SVN

https://lazysvn.sawirstudio.com/
1•sawirricardo•3m ago•0 comments

Agentic Risks

https://cloudberry.engineering/article/agentic-risks/
1•gbrindisi•4m ago•0 comments

Ask HN: Why does a black line appear on HN sometimes?

1•bheadmaster•10m ago•0 comments

Ask HN: How do you find joy in a world full of depressing news?

2•Razengan•12m ago•1 comments

Gpsjam GPS/GNSS Interference Map

https://gpsjam.org/
1•jonbaer•16m ago•0 comments

The Quantum Curtain

https://www.defenseone.com/ideas/2026/03/quantum-curtain/411967/
2•jonbaer•19m ago•0 comments

Stacksort

https://gkoberger.github.io/stacksort/
1•mihau•20m ago•0 comments

Mesh – remote mobile forensics and network monitoring

https://github.com/BARGHEST-ngo/MESH
1•0x0v1•20m ago•1 comments

MacBook Neo Review: Better Than You Think

https://www.youtube.com/watch?v=iGeXGdYE7UE
1•keepamovin•21m ago•0 comments

Encode/httpx: Closing off access

https://github.com/encode/httpx/discussions/3784
2•luismedel•22m ago•0 comments

A Kubernetes operator that orchestrates AI coding agents

https://medium.com/@bobbydeveaux/we-built-an-ai-that-plans-codes-reviews-and-ships-and-then-we-us...
2•bobbydeveaux•23m ago•1 comments

AI Agent Hacks McKinsey

https://codewall.ai/blog/how-we-hacked-mckinseys-ai-platform
1•mycroft_4221•24m ago•0 comments

Movies I Highly Recommend

https://github.com/ojhaugen15/12_movies
1•programmexxx•26m ago•0 comments

Richard Feynman's story illustrating the problem of p-hacking

https://twitter.com/SwipeWright/status/2031604331510690112
4•MrBuddyCasino•34m ago•0 comments

Glanceway – Collect RSS and custom plugin data in your macOS menu bar

https://glanceway.app
1•codytseng•35m ago•1 comments

Unbash: Fast 0-deps bash parser written in TypeScript

https://github.com/webpro-nl/unbash
1•mariuz•36m ago•0 comments

Ask HN: Is there a market for a security-audited Claude Code skills newsletter?

1•camicortazar•36m ago•0 comments

The Anthropic Institute

https://www.anthropic.com/news/the-anthropic-institute
4•meetpateltech•36m ago•1 comments

Gemini 2 Is the Top Model for Embeddings

https://agentset.ai/blog/gemini-2-embedding
2•tifa2up•41m ago•0 comments

Tutorials in Optomechanics

https://wp.optics.arizona.edu/optomech/tutorials-in-optomechanics/
1•o4c•43m ago•0 comments

A.I. Incites a New Wave of Grieving Parents Fighting for Online Safety

https://www.nytimes.com/2026/03/10/technology/ai-social-media-child-safety-parents.html
3•1vuio0pswjnm7•47m ago•1 comments

The Ig Nobel Prize Ceremony Is Moving to Europe (After 35 Years in the USA)

https://improbable.com/2026/03/10/the-ig-nobel-prize-ceremony-is-moving-to-europe-after-35-years-...
3•layer8•50m ago•0 comments

Some Arabic Words Transliterated

https://docs.google.com/document/d/1RMxjUr2Rki6TLNTNd00BNtBUwB0DJXiE4Dd_YppUi1I/edit
1•programmexxx•51m ago•0 comments

Google to Provide Pentagon with AI Agents

https://www.bloomberg.com/news/articles/2026-03-10/google-to-provide-pentagon-with-ai-agents-for-...
12•1vuio0pswjnm7•52m ago•3 comments

Europe tops global arms imports, SIPRI reports

https://www.dw.com/en/sipri-europe-arms-imports-global-weapons-trade-defense-spending/a-76261906
1•breve•57m ago•0 comments

AI-powered apps struggle with long-term retention, new report shows

https://techcrunch.com/2026/03/10/ai-powered-apps-struggle-with-long-term-retention-new-report-sh...
2•pseudolus•1h ago•0 comments

My app got 3k users in 48 hours and then monetization almost killed it

https://getcalendarly.com
1•DimKat•1h ago•1 comments

PEP 827 – Type Manipulation

https://peps.python.org/pep-0827/
2•EvgeniyZh•1h ago•0 comments

NASA's Van Allen Probe A to re-enter atmosphere

https://phys.org/news/2026-03-nasa-van-allen-probe-atmosphere.html
7•bookmtn•1h ago•0 comments

How age standardization make health metrics comparable

https://ourworldindata.org/age-standardization
1•sohkamyung•1h ago•0 comments
Open in hackernews

Ask HN: Java why put string in a constant?

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