frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Ask HN: Due to spam on GitHub, what platforms can I move my projects?

2•ciwolex•2m ago•0 comments

BountyClaimer – A platform to post tasks and claim bounties

https://www.bountyclaimer.com/
2•Kevan12•3m ago•0 comments

Termination shock: trust our expert warnings on geoengineering's planetary risks

https://www.theguardian.com/commentisfree/2026/jun/19/solar-geoengineering-risk-to-planet-earth
3•thrance•9m ago•1 comments

How Lume Works: The Retrieval Primitives

https://deepbluedynamics.com/blog/lume-retrieval-primitives
1•kordlessagain•9m ago•0 comments

Efficient Data Logger Design

https://blog.atimin.dev/efficient-data-logger-design/
2•flipback•10m ago•0 comments

Bill Gates on Steve Jobs

https://twitter.com/TechEmails/status/2067975210884882820
2•ksec•12m ago•0 comments

Quantum Fisher Information in a Strange Metal

https://www.nature.com/articles/s41567-026-03298-0
2•bookofjoe•15m ago•0 comments

Magnitude: A coding agent that runs on open models

https://magnitude.dev
2•ksec•19m ago•0 comments

Revised Rules of Engineering Leadership

https://lethain.com/revised-rules-of-engineering-leadership/
2•zdw•20m ago•0 comments

Exosomes in nanomedicine: A cell-free therapeutic intervention in burn wounds

https://pmc.ncbi.nlm.nih.gov/articles/PMC11462792/
3•CharlesW•22m ago•0 comments

Mark Rober demonstrate relay attacks by "stealing a car" [video]

https://www.youtube.com/watch?v=h0EGCnBjTVk
3•kidbomb•23m ago•2 comments

The ability to regrow body parts is dormant in mammals, not lost

https://www.sciencedaily.com/releases/2026/06/260617032207.htm
5•nryoo•27m ago•0 comments

Was lucky to have tested fable 5 on chess-bench

https://www.chess-bench.com
2•hardikvora•29m ago•0 comments

Claude Guillemot, co-founder of Ubisoft, dies in plane crash

https://www.cbsnews.com/news/claude-guillemot-dies-age-69-ubisoft-assassins-creed/
1•iugtmkbdfil834•32m ago•0 comments

Floppy Disk Piracy: How Software Was Shared Before the Internet

https://comuniq.xyz/post?t=1280
2•01-_-•32m ago•1 comments

I improved my old project "ScoreCast" after 3 years

https://github.com/Costasgk/ScoreCast
1•costas_8•32m ago•1 comments

Dialog

https://dialog.org/
1•paulpauper•33m ago•0 comments

Are You in the Weights?

https://intheweights.com/p/peterboettke
1•paulpauper•34m ago•0 comments

Refik Anadol's Dataland, the first AI art museum

https://www.theartnewspaper.com/2026/06/18/refik-anadol-dataland-opens-los-angeles
2•paulpauper•34m ago•0 comments

AIPropel, AI-powered proposal generation for freelancers and agencies

https://www.aipropel.app/
1•omardakelbab1•35m ago•0 comments

Tangled: Knot-Stored Cob Proposal

https://leaflet.pub/p/did:plc:xasnlahkri4ewmbuzly2rlc5/3mmex6biynk2g
1•jeremyjh•35m ago•0 comments

That which is unique, breaks (2020)

https://map.simonsarris.com/p/that-which-is-unique-breaks
1•mmphosis•36m ago•0 comments

Shard your locks: benchmarking 6 Go cache designs

https://strebkov.dev/posts/shard-your-locks/
1•kluyg•37m ago•0 comments

You probably don't need event-driven architecture

https://openacme.org/blog/you-dont-need-event-driven
1•theanonymousone•37m ago•0 comments

I Stopped Trusting SSH Key Files

https://igorstechnoclub.com/why-i-stopped-trusting-ssh-key-files/
2•Tomte•41m ago•1 comments

How to Attract Bats to Your Backyard

https://www.batcon.org/bat-house-tips-tricks/
2•andsoitis•41m ago•1 comments

We built an internal data analytics agent

https://github.blog/ai-and-ml/github-copilot/how-we-built-an-internal-data-analytics-agent/
1•Brajeshwar•49m ago•0 comments

UHF X11: X11 Built for VisionOS and Apple Vision Pro

https://www.lispm.net/apps/uhf-x11/
18•zdw•50m ago•4 comments

Bun has an open PR adding shared-memory threads to JavaScriptCore

https://github.com/oven-sh/WebKit/pull/249
3•gr4vityWall•51m ago•0 comments

Lena Walks

https://www.nomadicmatt.com/
2•docscannerss•52m 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.