frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

DevElif – Discover Websites and Grow Your Online Presence

https://develif.com
1•DevElif•2m ago•0 comments

Warren Buffett, legendary investo, dies at age 96

https://www.cbsnews.com/news/warren-buffett-berkshire-hathaway-dies-age-96/
1•riffraff•2m ago•0 comments

Ask HN: Which model do you use for writing?

1•reddmachine•11m ago•0 comments

Show HN: OpenRSI Physics:AI Starting to Beat the Record on Open Physics Problems

https://openrsi.foundation/openrsi-physics/#home
1•gdoptimizer•14m ago•0 comments

Got Scammed

1•srajendiran3•17m ago•0 comments

Trading Desk – Fail-closed paper trading and risk workbench (Python, SQLite)

https://github.com/hkedia08/trading-desk
1•harshkedia600•21m ago•0 comments

Warren Buffett Has Died

https://finance.yahoo.com/markets/live/warren-buffett-dies-tributes-and-reactions-mourning-the-or...
2•FinnLobsien•22m ago•0 comments

Show HN: BenchPoll–Set weights for AI benchmarks

https://benchpoll.com/
1•twotokens•23m ago•0 comments

Software as a Medium

https://ryo.lu/journal/software-as-a-medium
1•meetpateltech•27m ago•1 comments

New AI breakthrough changes everything (Plato's Key) [video]

https://www.youtube.com/watch?v=aeN8TrR-kdw
1•peter_d_sherman•29m ago•0 comments

The cyber security risk in modern cars

https://www.bbc.com/news/articles/cm98x37pn9z2o
2•1659447091•35m ago•0 comments

The slow armoured train that took Kim Jong Un to Beijing

https://www.abc.net.au/news/2026-12-02/inside-kim-jong-un-armoured-bulletproof-green-train/107451650
2•Gaishan•44m ago•0 comments

Show HN: An Advent calendar that your friends fill for you

https://fillmyadventcalendar.org/
1•bobleeIn•44m ago•1 comments

You have to be disagreeable to use AI well

https://www.seangoedecke.com/you-have-to-be-disagreeable-to-use-ai-well/
3•vismit2000•45m ago•0 comments

Show HN: Ways of Working = tips for teamwork in global groups and cultures

2•jph•46m ago•1 comments

AWS presents a new way to rein in rogue agents

https://www.theregister.com/ai-and-ml/2026/12/01/aws-presents-a-new-way-to-rein-in-rogue-agents/5...
2•Bender•47m ago•0 comments

HPE gives private AI agents tighter reins and a spending limit

https://www.theregister.com/on-prem/2026/12/01/hpe-gives-private-ai-agents-tighter-reins-and-a-sp...
2•Bender•48m ago•0 comments

Voice models recognize danger but rarely intervene in time

https://mundoai.world/research/ahem/
1•garrethlee•49m ago•0 comments

Xerox printers' QR codes send UK users to Chinese porn

https://arstechnica.com/gadgets/2026/12/xerox-printers-qr-codes-send-uk-users-to-chinese-porn/
3•Bender•50m ago•0 comments

ZFC cannot know BB(184) if "Quine's New Foundations + Cantorian" is consistent

https://wiki.bbchallenge.org/wiki/Logical_independence
1•ogogmad•50m ago•0 comments

Warren Buffett was the anti-Jensen Huang

https://www.cnn.com/2026/12/01/business/warren-buffett-was-the-anti-jensen-huang
3•1659447091•55m ago•0 comments

Guardrails Between Agents: Enforcing Rules in a Simulated Society of AI Agents

https://arxiv.org/abs/2611.35642
2•dhyland-wood•55m ago•1 comments

The Paleobiology Database

https://paleobiodb.org/
2•Eridanus2•56m ago•0 comments

Human slop is as bad as AI slop, if not worse

https://jamescosullivan.substack.com/p/human-slop-ai-slop
3•theanonymousone•1h ago•3 comments

Show HN: Spire Survivors – Slay the Spire × Vampire Survivors in HTML5 Canvas

https://spire-survivors.slay-spire-survivo.workers.dev/
3•sunzhousz•1h ago•0 comments

QuickManga AI Manga Translator

https://quickmanga.app
2•MasterMusicGo•1h ago•0 comments

Show HN: Twelve harness experiments on a 4B laptop model, eleven were null

https://github.com/narko4u/wright-harness
1•EddieWade•1h ago•0 comments

The Way of Unforce

https://melonusk.substack.com/p/the-way-of-unforce
1•MelonUsk•1h ago•1 comments

Warren Buffett's company website looks like a relic from the 1990s (2024)

https://www.businessinsider.com/warren-buffett-berkshire-hathaway-website-homepage-culture-values...
2•hentrep•1h ago•0 comments

Warren Buffett, America's legendary investor, dies at 96

https://www.ft.com/content/5463b4f8-8a7b-4c5f-88b4-59954944b0a9
2•quick_brown_fox•1h 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.