frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Show HN: An easy-to-play, hard-to-complete card battler

https://cnaize.com/fawe-arena/en/
1•cnaize•37s ago•0 comments

Anthropic hacked to deliver remote access trojan to Claude developer laptops

https://doublepulsar.com/anthropic-hacked-to-deliver-remote-access-trojan-to-claude-developer-lap...
1•vrganj•1m ago•0 comments

Robert Caro – The master biographer reflects at 91

https://www.dwarkesh.com/p/robert-caro
1•swolpers•1m ago•0 comments

4 Real? Tracking exploitation and patching of eMudhra's weak keys

https://blog.cloudflare.com/emudhra-patching/
1•pure-orange•2m ago•0 comments

Muse wins a small claims case

https://twitter.com/philwinkle/status/2116180121447014434
1•CGMthrowaway•3m ago•0 comments

Alphabet Sheds Half a Trillion in Market Value in Stock's Worst Day

https://www.wsj.com/tech/ai/alphabet-sheds-half-a-trillion-in-market-value-in-stocks-worst-day-ev...
2•teachrdan•4m ago•1 comments

Libriak-C – A C11 Client for Riak KV with HTTP and Protocol Buffers

https://github.com/arthurtumanyan/libriak-c
1•arthurtumanyan•5m ago•0 comments

I miss the part of programming where I figure it out myself

https://medium.com/@behind-the-stack/ai-has-made-coding-boring-adb1826134b0
1•birdculture•5m ago•0 comments

ACM Article: from code scarcity to verification scarcity by Ahmed El-Deeb

https://dl.acm.org/doi/10.1145/3844691.3844693
1•qaprof•6m ago•0 comments

Anthropic is renaming their Max plans

https://claude.com/pricing
2•pretext•8m ago•0 comments

Prism (OpenAI) shutting down January 1, 2027

https://prism.openai.com/
1•armcat•9m ago•0 comments

Pop the AI Bubble

https://aibubble.bighea.com
1•cbg0•9m ago•0 comments

The 'Pain in the Ass' Math That Could Save Vibe Coding from Itself

https://www.wired.com/story/software-verification-is-the-hot-new-answer-to-the-ai-safety-crisis/
1•thm•10m ago•0 comments

US Army practices digging temporary battlefield graves

https://www.armytimes.com/news/your-army/2026/10/26/army-practices-digging-temporary-battlefield-...
5•Jimmc414•15m ago•0 comments

DoorDash said it's only received 'several hundred' orders from AI agents

https://techcrunch.com/2026/10/30/doordash-said-its-only-received-several-hundred-orders-from-ai-...
1•nlpnerd•16m ago•1 comments

Show HN: A Modern Basketball Play Designer

https://elitehoopsapp.com/play-designer
1•jordanmorgan10•16m ago•0 comments

Project Suncatcher: TPU on the Orbit

https://twitter.com/sundarpichai/status/2116214866444943853
2•pretext•17m ago•0 comments

Anthropic may not secure investment-grade rating after IPO, Blackstone says

https://www.ft.com/content/59383c7f-8d82-493f-bf01-d2e862a1018f
5•petethomas•17m ago•0 comments

Chasing the Karpathy Peak (and Falling Off Slop Cliff)

https://thomasjiralerspong.substack.com/p/chasing-the-karpathy-peak
2•flail•19m ago•1 comments

My favourite PowerMac is a Nintendo Wii

https://virtuallyfun.com/2026/10/29/my-favourite-powermac-is-a-nintendo-wii/
2•DHowett•19m ago•0 comments

Proton's CEO Cancels AI 'Re-Interviews'

https://www.404media.co/protons-ceo-cancels-ai-re-interviews/
6•cdrnsf•20m ago•0 comments

The trouble with small nuclear reactors

https://www.ft.com/content/da1af660-c1d0-4c8b-8f94-e84052344448
3•JumpCrisscross•20m ago•0 comments

Show HN: Chess960v2 – Over 800 Rounds Played

https://chess960v2.com/en
2•lavren1974•21m ago•0 comments

Reddit CEO admits Google's AI Mode is choking off its search traffic

https://twitter.com/kouhxp/status/2116218737237840261
2•mrkn1•22m ago•2 comments

The Faster Way to Be Done

https://iamstelios.com/blog/clean-the-kitchen/
2•i8s•24m ago•0 comments

"Wrong" Email

3•rbmm•25m ago•0 comments

Open Rock – An open-source AI chat interface

https://github.com/maelswarm/openrock
2•openrocky•26m ago•0 comments

One Screen at a Time – a swipe feed of small "aha" moments, and how to build it

https://onescreenatatime.netlify.app/
2•stacherski•26m ago•0 comments

You Should Get to Own Your Media, Not Rent it Forever

https://www.currentaffairs.org/news/you-should-get-to-own-your-media-not-rent-it-forever
2•robtherobber•26m ago•0 comments

Ask HN: Are you putting off hardware upgrades because of AI coding tools?

2•winrid•27m 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.