frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Mojo 1.0 vs. Jac, a Roadmap

https://github.com/jaseci-labs/jac/issues/8361
1•marsninja•33s ago•1 comments

Framework Laptop 12, now with Core Series 3

https://frame.work/gb/en/blog/framework-laptop-12-now-with-core-series-3
1•vin047•1m ago•0 comments

Putting Ideas into Words (2022)

https://paulgraham.com/words.html
1•rzk•2m ago•0 comments

Unemployment Benefits Boost Growth

https://www.nominalnews.com/p/how-unemployment-benefits-boost-growth
1•NomNew•3m ago•0 comments

Find Chicago Parking Cops

https://www.secondcitycitation.com
1•zayfai•3m ago•0 comments

The three pillars of observability were never designed

https://greptime.com/blogs/2026-08-11-observability-three-pillars-history
1•xzhuang1984•3m ago•0 comments

Snow-eater heat waves of the western United States

https://www.science.org/doi/10.1126/sciadv.aeb3361
2•littlexsparkee•7m ago•0 comments

Combinatorics-Framework released for QA testers/students

1•yb-combi•7m ago•0 comments

Medieval Medicine Fueled the Belief That Vampires Are Real

https://www.fangoria.com/real-life-vampire-lore-and-medieval-medicine-the-blood-of-dawnwalker/
1•wertyk•10m ago•0 comments

Comcast turns your Xfinity WiFi into a home motion detector

https://www.bleepingcomputer.com/news/security/comcast-turns-your-xfinity-wifi-into-a-home-motion...
1•nazgulsenpai•10m ago•0 comments

China Is Building a Blue Granary

https://www.palladiummag.com/2026/08/04/china-is-building-a-blue-granary/
1•sorenKaram•12m ago•0 comments

Unicode Consortium

https://en.wikipedia.org/wiki/Unicode_Consortium
1•toomuchtodo•13m ago•1 comments

What If America Went Dark?

https://www.nytimes.com/2026/08/18/magazine/national-blackout-power-electricity-outage.html
1•danso•13m ago•1 comments

DeckSpace – presentations that are web pages, not slide files

https://deckspace.org/
1•lijifly•16m ago•0 comments

LabCraft Blog: What does the hash in a Nix store path name?

https://www.labcraft.dev/blog/nix-store-paths
1•anandsuresh•19m ago•0 comments

Agents for Robot Builders

https://foxglove.dev/blog/foxglove-goes-agentic
1•intrepidsoldier•19m ago•0 comments

Npx passproof install: agent can't say tests passed unless the runner printed

https://github.com/AziizBg/passproof
1•AziizBg•20m ago•0 comments

Claude Code 2.1.234 continues your session automatically once usage limit resets

https://code.claude.com/docs/en/changelog
2•janpeuker•21m ago•1 comments

Ask HN: Delete My Account

3•LAC-Tech•24m ago•1 comments

Mythic's analog compute-in-memory architecture

https://www.mythic.ai
1•janandonly•24m ago•0 comments

Caveman Saves Tokens by Doing Less, Not Just Saying Less

https://stuckinalocalminima.com/blog/2026/caveman/
1•barufa•25m ago•0 comments

Starship arrives at Christmas Island after 24-day ocean ordeal

https://www.space.com/space-exploration/launches-spacecraft/starship-lives-spacex-craft-arrives-a...
2•T-A•27m ago•0 comments

Department of War Orders Research Security Audits at 30 Academic Institutions

https://twitter.com/DoWCTO/status/2089356910705184889
2•porridgeraisin•28m ago•0 comments

Gift Economy Background of the Minecraft End Poem

https://theeggandtherock.com/p/i-wrote-a-story-for-a-friend
1•bobson381•28m ago•1 comments

The safety robot that comes with instructions on how to kill it

https://dangerousminds.net/pop-culture/safety-robot-that-comes-instructions-how-to-kill-it/
2•CharlesW•29m ago•0 comments

Show HN: ChatOSS – A Codex alternative for Open Source AI built on Ollama

https://chatoss.ai
3•thetjmccarty•29m ago•2 comments

Show HN: BallGuessr – Football player guessing game

https://ballguessr.eu/
1•yaman071•29m ago•0 comments

Vim wants you to control, VSCode wants you to consume

https://buttondown.com/hillelwayne/archive/vim-wants-you-to-control-vscode-wants-you-to/
2•speckx•33m ago•0 comments

Comcast adds motion sensing to its newer routers with a privacy catc

https://techcrunch.com/2026/08/18/comcast-adds-motion-sensing-to-millions-of-its-newer-routers-wi...
1•_____k•33m ago•0 comments

Are xPal Total and Remote Wipeout, Terminate Mode Meaningful for Privacy?

1•Brandon-Coll•35m 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.