frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

EthicalAds

https://www.ethicalads.io/
1•gone35•48s ago•0 comments

Hypercomplex Fractals

http://www.bugman123.com/Hypercomplex/
1•datavorous_•1m ago•0 comments

Interactive user productivity (1981) [pdf]

https://www.bitsavers.org/pdf/ibm/IBM_Systems_Journal/204/ibmsj2004E.pdf
1•tosh•2m ago•0 comments

Graphical way to manage Docker, Docker Compose and system services

https://github.com/shakg/g-systemctl
1•shakg•4m ago•0 comments

AI Nelo Image

https://neloimage.com
1•LeoRay•6m ago•0 comments

Yonkers Rises

https://simonwillison.net/2026/Nov/10/yonkers-rises/
1•jimauthors•7m ago•0 comments

Jellyfin for Android TV 0.20 – Jellyfin

https://jellyfin.org/posts/androidtv-v0.20.0/
1•xbmcuser•11m ago•0 comments

Amazon's Ring retries $250 home security drone and $1k patrol robot

https://www.geekwire.com/2026/amazons-ring-tries-again-with-a-250-flying-home-security-drone-and-...
2•GloVin•12m ago•0 comments

The library rejected all 36M valid Hungarian tax numbers

https://hrabovskyi.online/writing/attest/
1•nimus•13m ago•0 comments

Panorea, a chiptune note player working on Pascal and aplay

https://github.com/SuDuSuDoUsNe/Panorea
1•SuDuSuDoUsNe•19m ago•0 comments

Convert all Google photos to AVIF

https://github.com/gregjotau/google-photos-cli
1•convertalltoavi•20m ago•0 comments

Reprogramming Dormant Neurons to Backdoor AI Agents

https://www.microsoft.com/en-us/research/blog/lazare-veni-foras-reprogramming-dormant-neurons-to-...
1•sshah03•21m ago•0 comments

Kora

https://kora.fun/
1•privacyishuman•22m ago•1 comments

Notes on Making a Canonical Anthology: The Oxford Book of American Poetry

https://hudsonreview.com/2026/10/notes-on-making-a-canonical-anthology-the-oxford-book-of-america...
1•lermontov•23m ago•1 comments

Compress any LLM 3x in one click, near-lossless, in under 50 MB RAM

https://github.com/NeuraCryption/SPECTRA
3•NeuraCryption•23m ago•0 comments

Show HN: Overdeck 0.74 – MCP tools for coding agents, plus phone apps

https://github.com/eltmon/overdeck/releases/tag/v0.74.0
1•Eltmon•28m ago•0 comments

Show HN: Screen time monitor and self control app Tabstinence

https://tabstinence.com
1•mythormedicine•29m ago•0 comments

Stabl: Societal transformation and AI bottlenecks lab

https://stabl.ai/
1•thoughtpeddler•29m ago•0 comments

Singapore Airlines unveils 'largest double bed in the sky'

https://www.cnn.com/travel/singapore-airlines-double-bed-cabin-revamp
1•rawgabbit•34m ago•1 comments

The Tragedy of the Oxide Root of Trust

https://danielmangum.com/posts/tragedy-oxide-rot/
2•hasheddan•35m ago•0 comments

Fossil CEO says turnaround is ahead of plan as sales return to growth

https://www.cnbc.com/2026/11/10/fossil-fosl-q3-2026-earnings.html
1•madihaa•35m ago•0 comments

Which Apple Silicon builds iOS apps fastest?

https://benchmarks.bitrise.io/
1•theanonymousone•37m ago•0 comments

Grok Build coding agent leaks confidential info, some belonging to SpaceXSI

https://arstechnica.com/security/2026/11/grok-build-coding-agent-leaks-oodles-of-confidential-inf...
2•Palmik•38m ago•0 comments

Show HN: GraphFlow – system design diagrams that run in the browser

https://graph-flow-virid.vercel.app/
2•hanubaki•38m ago•0 comments

Understanding and Engineering Consciousness

https://astera.org/understanding-and-engineering-consciousness/
1•ersinesen•38m ago•1 comments

Fake accounts defended Jensen Huang and attacked lawmakers

https://www.modelrepublic.org/articles/nvidia-koios-campaign-sockpuppet-accounts
2•DeepLogin•41m ago•1 comments

We're still so small but I'm loving the team we've got at Superlogical

https://twitter.com/mitchellh/status/2120221244478083249
1•tosh•43m ago•0 comments

AI and Original Intentionality

https://johnoestmannmusic.com/ai-and-original-intentionality/
1•soundworlds•45m ago•0 comments

VirtualTryOn – AI try-on for clothes, glasses, rings, and hairstyles

https://virtualtryon.pro/
1•TinyMomentum•49m ago•0 comments

Firefox 160.0 Release Notes

https://www.firefox.com/en-US/firefox/160.0/releasenotes/
6•thunderbong•51m 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.