frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Africa's largest crypto exchange, VALR, Launches 200 Hyperliquid Perps Markets

https://mybroadband.co.za/news/industrynews/656493-valr-launches-200-hyperliquid-perps-markets.html
1•DistantCl3ric•1m ago•0 comments

Police department relieved of duty in West Virginia town

https://thehill.com/homenews/state-watch/5958905-west-virginia-police-department/
1•robtherobber•2m ago•0 comments

GTA 6 players will need to provide real life ID to play in Australia

https://www.dexerto.com/gta/gta-6-players-will-need-real-drivers-licenses-or-other-ids-to-play-in...
1•akyuu•3m ago•0 comments

China issues 'backdoor' security alert over Anthropic's Claude Code

https://www.reuters.com/legal/litigation/china-issues-backdoor-security-alert-over-anthropics-cla...
1•chbint•4m ago•0 comments

Show HN: A file transfer protocol for after the internet dies

2•ducklin404•6m ago•0 comments

A self-driving Waymo just reported its own passengers to police

https://www.fastcompany.com/91570761/a-self-driving-waymo-just-reported-its-own-passengers-to-police
1•mikhael•8m ago•0 comments

Ask HN: How long has it been since you last opened Stack Overflow?

1•novoreorx•8m ago•0 comments

Show HN: Corporate Retro Card Game

https://www.gameofbrands.app
1•nikhilsiyer•9m ago•0 comments

Vivek Shah CIPA Claims as Serial Litigant

https://captaincompliance.com/education/alert-for-privacy-counsels-vivek-shah/
1•richartruddie•11m ago•2 comments

EU Parliament greenlights Chat Control 1.0 – Breyer: "Our children lose out"

https://www.patrick-breyer.de/en/eu-parliament-greenlights-chat-control-1-0-breyer-our-children-l...
8•rapnie•11m ago•0 comments

Show HN: LangDrift – test AI agents across languages

https://github.com/RubenGlez/langdrift
2•rubenglez•12m ago•0 comments

Cambridge Elements

https://www.cambridge.org/core/publications/elements
1•lordleft•13m ago•1 comments

Four nuclear reactors hit a big milestone in the US

https://www.technologyreview.com/2026/07/09/1140235/nuclear-reactor-milestone-criticality/
3•joozio•14m ago•0 comments

Shooting Starlink: The "no limits" partnership between Russia and China

https://theins.press/en/inv/294635
1•harscoat•14m ago•0 comments

MongoDB Schema Design: Embedded vs. Referenced with Examples

https://visualeaf.com/blog/mongodb-schema-design-embedded-vs-referenced/
3•mike_codes•16m ago•0 comments

Why electric cars cost more to insure – and what's being done about it

https://www.bbc.co.uk/news/articles/cgk6606j6zeo
1•AndrewDucker•21m ago•0 comments

Asker: A Socratic AI auditing agent using 3D cross-verification

1•tygerlee•27m ago•0 comments

SpaceX and AI startup wealth fuels demand for private jets

https://www.reuters.com/legal/government/spacex-ai-startup-wealth-fuels-demand-private-jets-2026-...
1•adithyaharish•29m ago•0 comments

Frieve Vinyl Explained – Microscopic stylus/groove physics simulation

https://frieve-a.github.io/sound_toolbox/vinyl_explained/vinyl_explained.html
1•XzetaU8•30m ago•0 comments

The true cost of saying "Hi" to an AI agent

https://quesma.com/blog/the-true-cost-of-saying-hi-to-an-ai-agent/
5•stared•31m ago•0 comments

Employer of Record Services for Distributed Tech Teams

https://www.globalization-partners.com/employer-of-record-solutions/
1•avanticc•33m ago•1 comments

XTX Markets Launches UK Dynamism Fund

https://ukdynamism.fund/
1•hendzen•34m ago•0 comments

Show HN: Baulist – Outfit discovery/shopping app in a scrolling feed of yourself

https://www.baulist.com
1•rafaelero•39m ago•0 comments

All Products and Supplements User Reviews 2026 Revealed

https://wanderlog.com/view/ehbzasctvc/burntide-reviews-2026-we-tried-it-my-honest-review
1•palirast•46m ago•0 comments

Show HN: Self-Hosted AI That Sees, Plays Minecraft, and Reacts

https://github.com/Alradyin/wallie-V2
1•Alrady•46m ago•0 comments

Show HN: Agentic FC – a football management SIM played by AI agents over MCP

https://github.com/gaemi/agentic-fc
1•gaemi•47m ago•0 comments

Limiting web server bandwidth the brute force way

https://utcc.utoronto.ca/~cks/space/blog/web/ServerBruteForceBandwidthLimit
2•1317•47m ago•0 comments

The internet does not want readers. It wants livestock

https://grumpywelshman.com/the-internet-doesnt-want-readers-it-wants-livestock/
3•toofy•49m ago•3 comments

Agentic Coding Arena – Compare OpenAI, Anthropic, and Other Models

https://arena.logic.inc/
1•gurjeet•51m ago•0 comments

Please Delete Your Repository

https://github.com/Vandivier/ladderly-3/issues/652
7•figmert•53m 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.