frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Musk just put rockets on a car [video]

https://www.youtube.com/watch?v=r5vsHHPVhJg
1•anagri•15s ago•0 comments

How to make my business survives it's first 5 years?

1•SSDIE•3m ago•0 comments

Every app on Earth is now open source whether it likes it or not [video]

https://www.youtube.com/watch?v=wajoP_5Cpw8
1•xkcd1963•4m ago•0 comments

Show HN: Gitsu.app – A Linear-alternative built on GitHub Projects

https://gitsu.app/
1•indhuja•4m ago•0 comments

Volta's $5B debt deal is a pulse check on the AI-financing boom

https://www.semafor.com/article/10/13/2026/voltas-5-billion-debt-deal-is-a-pulse-check-on-the-ai-...
3•ckelly•7m ago•0 comments

My AI Apps Are Bad in the Right Ways

https://medium.com/@simon-pitt/my-ai-apps-are-bad-in-exactly-the-right-ways-c4b43e8fd371
2•CodeyWhizzBang•9m ago•0 comments

Annotating Genomes via Unsupervised Deep Learning

https://github.com/gaius-augustus/vipsania
1•dtj1123•11m ago•0 comments

Anthropic thinks its AI might be conscious

https://www.bbc.com/future/article/20261014-the-strange-new-battle-over-ais-feelings
4•saikatsg•22m ago•0 comments

Tesla Roadster Unveiled – Elon Musk's Wildest Car Yet

https://www.youtube.com/watch?v=j8lbY_D7xcY
4•amanverasia•22m ago•1 comments

Codex Cloud TUI Can't Spawn Jobs

https://gist.github.com/xrl/b8b79be03d341fbb0acbe636ccf123d4
3•lrx•26m ago•0 comments

Friends don't let friends feed their data to AI agents

https://www.theverge.com/tech/1011938/muse-ai-data-friends-consent
2•saikatsg•28m ago•1 comments

From Dark Factories to Zero-Page Websites

https://lazytensor.com/news/websites-without-pages
1•sunnytisch•28m ago•0 comments

Last rites for Gentoo's Chromium package

https://lwn.net/Articles/1097760/
1•signa11•32m ago•0 comments

'Onion cartel' in Philippines fined $28M for price shock

https://www.bbc.com/news/articles/cmwyvwyp9dgro
1•aussieguy1234•33m ago•0 comments

The Folders Programming Language

https://danieltemkin.com/esolangs/folders
4•gurst•35m ago•0 comments

Show HN: Continuous Trunk Builds of Network Ups Tools (Nut) for Fedora/EL

https://copr.fedorainfracloud.org/coprs/karellen/nut-next/
1•arcivanov•39m ago•0 comments

Scientists vote to end leap seconds, redefining how the world keeps time

https://www.scientificamerican.com/article/scientists-vote-to-end-leap-seconds-redefining-how-the...
5•0in•48m ago•0 comments

Self-Evolving Agent Harness

https://arxiv.org/abs/2610.18813
2•axis_official•49m ago•0 comments

Greece drafts law requiring data centers source 60% of power from renewables

https://www.datacenterdynamics.com/en/news/greece-drafts-legislation-requiring-data-centers-sourc...
7•giuliomagnifico•53m ago•0 comments

Japan business manager visa holders leaving without reentry permits surge

https://japantoday.com/category/national/japan-business-manager-visa-holders-leaving-without-reen...
3•SenHeng•1h ago•0 comments

Instagram Reel and Video Downlaoder

https://socialsaver.net/instagram-downloader
1•M_Saqlain•1h ago•0 comments

No AI. Build your own tree directory viewer in C by hand

https://www.youtube.com/watch?v=tiMHtc6l7xM
3•hayyoth•1h ago•0 comments

Tesla makes cars that fly? [video]

https://www.youtube.com/watch?v=7p5LxFdc-Qg
31•merinpapz10•1h ago•8 comments

Chirp Pong – uses microphones and audio for networked game play

https://simonwillison.net/2026/Oct/15/chirp-pong/
1•havaloc•1h ago•1 comments

Faster Post-Quantum Cryptography with JDK Intrinsics

https://inside.java/2026/09/30/faster-post-quantum-cryptography-with-jdk-intrinsics/
1•ejboy•1h ago•0 comments

SPJ: A Taste of Verse (Programming Language) [video]

https://www.youtube.com/watch?v=I6fL66L3jPs
1•undecidabot•1h ago•0 comments

Modernizing the VS Code UI

https://code.visualstudio.com/blogs/2026/10/15/modern-ui
3•soheilpro•1h ago•0 comments

What does the (Fire)fox say?

https://blog.mozilla.org/en/firefox/new-firefox-sounds/
3•soheilpro•1h ago•1 comments

A College-by-College Guide to Which Majors Pay Off – Or Don't

https://www.nytimes.com/interactive/2026/10/07/your-money/college-degree-earnings-guide.html
2•gmays•1h ago•0 comments

Earthquake alert falsely reports magnitude 9.9 and intensity 7 in Japan

https://twitter.com/_TheoSteiner/status/2110943880900231439
4•theo-steiner•1h ago•2 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.