frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

China's Weakening Economy Is Creating a Lost Generation

https://www.wsj.com/world/china-economy-gen-z-f9058941
1•kaycebasques•2m ago•0 comments

I used an AI QA agent to test Hacker News

https://hitest.ai/blog/demo-hacker-news
1•easilyjs•4m ago•0 comments

Show HN: Planning software for startup teams

https://weeklywe.com
1•aminaghakazemi•7m ago•0 comments

Ask HN: Now that AI makes the execution easy, do ideas matter more?

1•amichail•7m ago•0 comments

Is AI the End of Math as We Know It?

https://www.quantamagazine.org/is-ai-the-end-of-math-as-we-know-it-20261005/
1•maxall4•11m ago•0 comments

Leading Chinese mathematicians unite behind use of AI in research

https://www.scmp.com/news/china/science/article/3370492/leading-chinese-mathematicians-unite-behi...
2•E-Reverance•14m ago•0 comments

A.I. Music Fraudster Who Drew Millions in Royalties Is Sentenced to 18 Months

https://www.nytimes.com/2026/10/07/arts/music/ai-music-fraud-royalties-sentence.html
1•lxm•21m ago•0 comments

Normal Bad Work

https://terrytao.wordpress.com/2026/10/12/this-is-normal-bad-work/
2•smilelamp•21m ago•1 comments

In 5 years, 95% of tokens used by AI agents will be for tasks humans never did

https://twitter.com/levie/status/1986620885592113218
4•andsoitis•23m ago•0 comments

Available now: 0.5 MW of colo capacity for B300s

https://ardus.ai/
1•nasim_nosiroff•23m ago•0 comments

Ontology SDK

https://www.palantir.com/docs/foundry/ontology-sdk/overview
2•enjoyyourlife•28m ago•0 comments

Learn LEAN 4 Theorem Proving in an easy game

https://adam.math.hhu.de/#/g/leanprover-community/NNG4
2•samagra14•31m ago•0 comments

When to Use Vulnerability Assessments, Pentesting, Red Teams, and Bug Bounties

https://danielmiessler.com/blog/when-vulnerability-assessments-pentesting-red-team-bug-bounties
2•tknisley•33m ago•0 comments

The Most Overlooked Taste in the World [video]

https://www.youtube.com/watch?v=zC1v19wfoTA
1•pinkmuffinere•35m ago•0 comments

Multiplayer Pong over SSH

https://antics.gg/ssh
3•thatslast•38m ago•0 comments

No More Camera Glasses – Even Realities

https://www.evenrealities.com/blogs/stories/no-more-camera-glasses-by-will-wang-founder-ceo-even-...
2•tash_2s•41m ago•0 comments

NAZA: Netanyahu orders identification and prosecution of film's interviewees

https://www.theguardian.com/film/2026/oct/12/naza-netanyahu-orders-identification-prosecution-int...
21•hebelehubele•44m ago•1 comments

OpenAI algorithm for the FFT is less a breakthrough and more a malicious exploit

https://www.argmin.net/p/faster-fourier-transforms
10•mochomocha•49m ago•1 comments

Climate Finder

https://weather.theojaffee.net/
3•bonefishgrill•49m ago•0 comments

Why does checking for software updates often take so long?

5•nick_•50m ago•1 comments

Lüften, or 'home burping,' yields sweet smell of success for your home

https://www.cpr.org/2026/06/24/home-burping-brings-outdoor-air-inside/
2•andsoitis•51m ago•0 comments

Leaving Tech

https://ryanbigg.com/2026/10/leaving-tech
107•jonahx•56m ago•80 comments

Kioxia, SanDisk show off the tiny chip which could go in first 1 PB SSD

https://www.techradar.com/pro/kioxia-sandisk-show-off-the-tiny-chip-which-could-go-in-worlds-firs...
6•peter_d_sherman•1h ago•0 comments

Woman who rescued injured crow keeps getting 'thank-you gifts' from birds [video]

https://www.youtube.com/watch?v=sjNpfz4UzqU
3•johnnyApplePRNG•1h ago•0 comments

Show HN: BellRun. Gamified Stock Trading

https://bellrun.com/office
3•twism•1h ago•0 comments

IsEven API

https://isevenapi.xyz/
5•basilikum•1h ago•3 comments

Army turning to AI in its fight against biological threats

https://defensescoop.com/2026/10/12/army-turning-to-ai-in-its-fight-against-biological-threats/
4•snarky-comments•1h ago•0 comments

Asus Hyper M.2 x16 Gen5 PCIe Card – up to four NVMe M.2 SSD's at up to 512 Gbps

https://www.asus.com/us/motherboards-components/motherboards/accessories/hyper-m-2-x16-gen5-card/
9•peter_d_sherman•1h ago•0 comments

Astrocytic Clock Controls Circadian PNN Remodeling, Synapse Strength, Learning

https://onlinelibrary.wiley.com/doi/10.1002/glia.70213
3•randomImmigrant•1h ago•1 comments

China Overtakes U.S. For First Time as Top Spender on R&D in 2024

https://japannews.yomiuri.co.jp/science-nature/science/20260908-347742/
48•mushstory•1h ago•20 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.