frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Scientists Uncover Hidden Structures Beneath the Amazon

https://www.sciencealert.com/completely-transformed-my-understanding-scientists-uncover-hundreds-...
1•thunderbong•39s ago•0 comments

Can you make a Wii U gamepad from a Raspberry Pi? [video]

https://www.youtube.com/watch?v=si-TUEwC5_M
2•mister_mort•3m ago•0 comments

We discovered a new variant of Super Mario Bros

https://nintendowire.com/news/2026/07/29/we-discovered-a-new-super-mario-bros-variant/
1•hn1986•8m ago•0 comments

Art as Compression

https://feed.grantcuster.com/post/2026-07-29-10-20-08-art-as-compression
1•msephton•15m ago•0 comments

Higher Airfares Are Looming on Busy Routes as AI Squeezes Out Bargains

https://www.bloomberg.com/news/articles/2026-07-29/higher-airfares-loom-on-busy-routes-as-ai-sque...
2•petethomas•16m ago•0 comments

xAI sues Minnesota over its law banning 'nudification' technology

https://apnews.com/article/minnesota-artificial-intelligence-nudification-x-elon-musk-deepfake-13...
6•devonnull•20m ago•1 comments

Talk to Your Area (Askaround.me)

1•SahibzadaAM•29m ago•0 comments

Show HN: Legionlinuxtui – Control Lenovo legion laptops in the terminal

https://github.com/nooneknowspeter/legionlinuxtui
3•nooneknowspeter•29m ago•0 comments

The Programming Tourist

https://amrshawky.com/posts/cs-correction/
3•amr_shawky•30m ago•0 comments

Is Mythos good at cyber because it kept hacking Anthropics sandboxes in training

https://www.lesswrong.com/posts/QKDoZe6EKhxnFjLWK/is-mythos-good-at-cyber-because-it-kept-hacking...
3•lukaspetersson•31m ago•0 comments

The Art of Life [video]

https://www.youtube.com/watch?v=7gUh8j5ui0o
2•momentmaker•32m ago•0 comments

Study uncovers lost 'golden age' of languages

https://news.yale.edu/2026/07/23/study-uncovers-lost-golden-age-languages
2•gmays•35m ago•0 comments

What Silicon Valley gets wrong about AI

https://sfstandard.com/2026/07/29/myth-ai-intelligence-medicine-regulation/
2•littlexsparkee•46m ago•2 comments

Encryption in the 1790s

https://hackaday.com/2026/07/23/encryption-in-the-1790s/
5•kristianp•49m ago•0 comments

Show HN: GlobeHoppr – find a route between cities using limited-distance jumps

https://globehoppr.com
3•JohnJohnson123•51m ago•0 comments

Before the theorem prover: verification is older than the alphabet

https://amangoel.ai/blog/before-the-theorem-prover/
3•amangoelumich•53m ago•0 comments

Do newer coding models end up training on the AI slop generated by older models?

4•tbharath•53m ago•3 comments

Google AI Studio "Delete" doesn't delete – server chat persists (3 videos)

https://www.youtube.com/watch?v=LBQfNbPCxQw
4•Bitu79•57m ago•3 comments

A pharmacy chain in Vermont implemented AI for efficiency

https://vtdigger.org/2026/07/29/a-pharmacy-chain-in-vermont-implemented-ai-for-efficiency-its-led...
20•omerhj•58m ago•17 comments

The World Is to Focused on Quarterly Earnings

2•Taikhoom2010•58m ago•0 comments

ACR Stealer: ClickFix, Etherhiding, and Stego, Oh My

https://discourse.ifin.network/t/acr-stealer-clickfix-etherhiding-and-stego-oh-my/694
2•speckx•1h ago•0 comments

Show HN: RunNburn – Run a 295B Moe from a 98GB GGUF on a 64GB RAM Desktop

https://github.com/coderredlab/runNburn
2•coderredlab•1h ago•0 comments

Show HN: A free palm-reading tool that works in the browser

https://wishastro.com/tools/palm-reading
2•rp321•1h ago•0 comments

Why AI Needs a "Genie Coefficient"

https://www.schneier.com/blog/archives/2026/07/why-ai-needs-a-genie-coefficient.html
2•anotherevan•1h ago•0 comments

OpenAI ARR in July topped all of Q2

https://www.cnbc.com/2026/07/29/openai-cfo-sarah-friar-tells-employees-arr-in-july-topped-all-of-...
2•gmays•1h ago•0 comments

Flume Water Monitor 915 MHz Security Is Pretty Good

https://waveformsecurity.com/blog/flume/
15•credibleconure•1h ago•4 comments

Face Recognition Blocking Glasses Tested

https://ipvm.com/reports/face-recognition-blocking-glasses-tested
3•jhonovich•1h ago•1 comments

IronClaw 1.0 – one secure agent on CLI, Slack and Telegram, one memory

https://near.ai/blog/introducing-ironclaw-1-0
2•alejoras•1h ago•0 comments

Three Journeys: Anton Chekhov on the Road (2001)

https://www.newyorker.com/magazine/2001/10/29/three-journeys
3•mitchbob•1h ago•1 comments

Overengineered Calculator: Zig and QBE

https://tomekw.com/overengineered-calculator-zig-qbe/
6•rguiscard•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.