frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Too Many Books?

https://www.nytimes.com/2026/07/09/style/too-many-books-new-york-city-apartment-scholar-landlord....
2•simplegeek•2m ago•0 comments

Why Shadow AI Detection Can Not Wait

https://konghq.com/blog/enterprise/shadow-ai-detection-enterprise-governance
1•axandriamier•2m ago•0 comments

Neon Handles Database Branching

https://bytesizedbets.com/p/how-neon-handles-database-branching
1•TheAnkurTyagi•3m ago•0 comments

A 2-in-1 OSINT suite for deep email and username metadata extraction

https://github.com/kaifcodec/user-scanner
1•json-hunter07•3m ago•0 comments

Show HN: I built source-verified SAT score profiles for hiring

https://showmyscore.com/
1•stony-builds•4m ago•0 comments

Show HN: Simulator for a custom 8-bit discreet logic computer

https://msap2.mehran.dk
1•mehrant•4m ago•0 comments

Spotify now has an AI assistant you can talk to

https://www.neowin.net/news/spotify-now-has-an-ai-assistant-you-can-talk-to/
1•jenic_•7m ago•1 comments

Allthevaccines.org

https://allthevaccines.org/
1•Gooblebrai•9m ago•0 comments

Too many words about DIDs

https://steveklabnik.com/writing/too-many-words-about-dids/
2•steveklabnik•11m ago•0 comments

Show HN: An IELTS grader that names the one thing blocking Band 7

https://examinerly.com/
1•shraey96•13m ago•0 comments

Why Huge Pages Matter for Postgres?

https://clickhouse.com/blog/huge-pages-clickhouse-managed-postgres
1•saisrirampur•14m ago•0 comments

Show HN: Dspack Studio – An agent builds UI, the design system gates what ships

https://studio.aesthetic-function.com
1•ryandmonk•14m ago•0 comments

Show HN: A lightweight model monitor for scikit-learn and Keras

https://aitor1717.github.io/canary-ml/
1•aitor1717•15m ago•0 comments

The first sunlight reflecting space mirror has been cleared for launch

https://www.theverge.com/science/965263/reflect-orbital-space-mirror-launch-fcc-clearance
1•Brajeshwar•16m ago•1 comments

Show HN: I built a free app that turns your fridge into recipes (solo dev)

https://souva.app
1•RyanJensen•16m ago•0 comments

Vivario – a browser terrarium that generates its own world and sound

https://vi-vario.com/
1•mtsyfy•16m ago•0 comments

Why Pogačar Rides on a Car Tire Brand

https://www.renehersecycles.com/why-pogacar-rides-on-a-car-tire-brand/
1•bobchadwick•17m ago•0 comments

Maybe Men's Problem Is That They Like Being Lonely

https://www.conorfitzgerald.com/p/maybe-mens-problem-is-that-they-like
3•casca•17m ago•0 comments

A ChatGPT automation just found –$45K in erroneous invoices across 3 years

https://twitter.com/mitchellh/status/2077053324835389497
2•tosh•18m ago•0 comments

Designing Math Ft. Grant Sanderson (3Blue1Brown) I Config 2026

https://www.youtube.com/watch?v=bLSLN96Gn-w
1•root-parent•20m ago•0 comments

Iran exploited mobile flaws to locate U.S. troops in the Middle East

https://techcrunch.com/2026/07/14/iran-abused-mobile-networks-vulnerabilities-to-locate-u-s-milit...
3•speckx•20m ago•0 comments

IBM warns AI boom is squeezing software budgets; shares sink in sector rout

https://finance.yahoo.com/markets/stocks/articles/ibm-expects-second-quarter-revenue-111029599.html
3•wslh•21m ago•0 comments

Dupes (product clones) took over the world

https://www.vox.com/podcasts/493930/dupe-culture-fender-ugg-quince-tiktok-amazon-online-shopping
3•gumby•21m ago•0 comments

Show HN: Skills as a Service via MCP –> Coding Agent Skill Library

https://github.com/mmccalla/coding-agent-skill-library
1•get-analyst-01•23m ago•0 comments

Linux Transparent Proxy Internals

https://allhailthetopology.substack.com/p/linux-transparent-proxy-internals
1•ldelossa•24m ago•1 comments

Google probed by Swiss regulator over Android default search feature

https://www.reuters.com/legal/litigation/google-probed-by-swiss-regulator-over-android-default-se...
1•1vuio0pswjnm7•25m ago•0 comments

Why design matters for a web framework: a 7-year evolution

https://wasp.sh/blog/2026/07/13/why-design-matters-for-a-web-framework
2•matijash•25m ago•0 comments

Show HN: Megaphone – On-device macOS dictation built on Apple's SpeechAnalyzer

https://github.com/Kuberwastaken/megaphone
1•kuberwastaken•26m ago•0 comments

Show HN: Orbital PAI a personal AI assistant

https://github.com/Dream-Mosaic/orbital-pai
1•kalcode•26m ago•0 comments

K (1993)

https://web.archive.org/web/20160330020952/http://archive.vector.org.uk/art10010830
1•tosh•26m 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.