frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

A barbarian tribe's mythic origin story is true, ancient DNA reveals

https://www.science.org/content/article/barbarian-tribe-s-mythic-origin-story-true-ancient-dna-re...
1•benbreen•7m ago•0 comments

Code Matters: Reflections on Rust in the LLM Age – Bryan Cantrill – Rust NYC [video]

https://www.youtube.com/watch?v=5D7QPOIZ7gY
2•vismit2000•7m ago•0 comments

Show HN: Help me pick a logo animation for my in-browser AI creature game

https://id-le.com/review/intro-logo-animation
1•nico•8m ago•0 comments

We Engineer Safer Agents

https://www.perplexity.ai/hub/blog/how-we-engineer-safer-agents
1•gmays•9m ago•0 comments

Quantum Computers Are Poised to Crack Encryption. AI Could Beat Them to It

https://www.wsj.com/tech/ai/ai-math-online-encryption-quantum-computers-57926bb2
1•fortran77•22m ago•0 comments

Exploring Janet and the HTTPF web framework

https://nick.gs/blog/2026-11/exploring-janet-and-the-httpf-web-framework/
1•veqq•23m ago•0 comments

F2FS: A New File System for Flash Storage (2015) [pdf]

https://www.usenix.org/system/files/conference/fast15/fast15-paper-lee.pdf
1•vismit2000•26m ago•0 comments

Show HN: We tested our prompt injection filter in public

https://hodor.gatebolt.com/blog/secret-leak-test
1•junayedmizan5•29m ago•0 comments

MCP-server-AutoCAD-Lisp-helper

https://github.com/radwanalmsora/mcp-server-autocad-lisp-helper
1•radwanAlmsora•30m ago•0 comments

The AI Business Model Just Collapsed

https://www.honest-broker.com/p/the-ai-business-model-just-collapsed
3•paulpauper•31m ago•1 comments

Why do people see colours differently? Sometimes, it's the display's fault

https://physicsworld.com/a/why-do-people-see-colours-differently-sometimes-its-the-displays-fault/
1•EA-3167•32m ago•1 comments

GLP-1 Prescriptions for People with No Medical Need Are Climbing

https://www.nytimes.com/2026/09/22/well/ozempic-glp1-medical-reason.html
2•paulpauper•35m ago•1 comments

The Pangram Backlash Unfolding on College Campuses

https://www.theatlantic.com/technology/2026/09/college-professors-ai-detectors-pangram/688727/
2•paulpauper•37m ago•0 comments

US believes Nvidia's Huang had romantic relationship with alleged Chinese spy

https://www.ft.com/content/a55a2a22-4479-4f93-a445-6147a5c6d790
5•robbiet480•38m ago•0 comments

Adding proper security to your vibecoded Linux GUI apps

https://akitaonrails.com/en/2026/11/06/adding-proper-security-to-your-vibecoded-linux-gui-apps/
1•ayanb9440•39m ago•0 comments

HomeMinerProxy: home dashboard and Stratum proxy for Bitcoin lottery mining

https://github.com/Modanez/HomeMinerProxy
1•modanez•47m ago•0 comments

What do workers want in a leader? New study challenges stereotypes

https://newsroom.haas.berkeley.edu/research/what-do-workers-really-want-in-a-leader-new-study-cha...
3•rohanm93•47m ago•0 comments

SpaceX's $2T Bet Has a Physics Problem [video]

https://www.youtube.com/watch?v=S1umCJfbJ0w
1•mkesper•48m ago•0 comments

Show HN: S3mail – Serverless personal email on AWS with JMAP

https://github.com/zero11-0203/s3mail
1•zero11-0203•50m ago•0 comments

Killer App, the thrilling story about the rise of Telegram

https://www.faber.co.uk/journal/faber-set-to-publish-killer-app-the-thrilling-story-about-the-ris...
1•elies•50m ago•0 comments

Geometry, Kinematics, Statics, and DYNAMICS(2018) [pdf]

http://ruina.tam.cornell.edu/Courses/ME4730%20Fall%202018/books/Dynamics_Book_Bernstein__Goel__An...
1•pillars•52m ago•0 comments

Show HN: Promptcheckup – pass/fail check for prompt changes, with 95% intervals

https://github.com/gael55x/promptcheckup
1•gael55x•1h ago•0 comments

Show HN: Did prediction markets do any predicting this midterms?

https://app.artifactbin.dev/@vivek/AQTt2H-did-prediction-markets-predict-the-midterms
10•nuwandavek•1h ago•2 comments

Vapes, pouches and now tablets: The tobacco industry's newest nicotine product

https://www.theexamination.org/articles/zyn-melts-nicotine-tablets-kids
2•paimapi•1h ago•0 comments

Lighting the Skies

https://computer.rip/2026-10-25-searchlights.html
9•dverlaeckt80•1h ago•1 comments

Show HN: Backwords – Let AI teach you how to speak in reverse

https://backwords.greg.technology/
9•gregsadetsky•1h ago•2 comments

YC Backed Bron AI Accused of Using LeBron's Name and Likeness

https://frontofficesports.com/article/lebron-james-demands-ai-betting-app-stop-using-his-likeness/
5•sicgods•1h ago•1 comments

Meta introduces Spaces: custom app views built by your Muse agent

https://about.fb.com/news/2026/11/introducing-spaces-customize-muse-app/
1•willmarch•1h ago•1 comments

Show HN: Roomzine – turn a photo of your room into a redesign magazine

https://roomzine.com/
1•ayarmots•1h ago•0 comments

Magnets and Rare Earths

https://robodienst.com/learning-paths/magnets-and-rare-earths
1•Bluestein•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.