frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Could Beowulf See Blue?

https://www.deadlanguagesociety.com/p/history-english-colour-words
1•gherkinnn•1m ago•0 comments

Built a free Irish sport TV listings site

https://sportontvireland.ie/about
1•cf100clunk•2m ago•1 comments

Show HN: A blockchain that proves instead of storing

https://github.com/ignotusnemo/parano1d
1•ignotusnemo•2m ago•0 comments

[pre-RFC] Alloy formalization of LLVM IR's concurrent memory model

https://discourse.llvm.org/t/pre-rfc-alloy-formalization-of-llvm-irs-concurrent-memory-model/91590
1•matt_d•2m ago•0 comments

Paramount Wants $1.88B Bond from States, Writers Challenging Warner Deal

https://www.wsj.com/business/media/paramount-wants-states-writers-challenging-warner-deal-to-post...
1•mudil•4m ago•0 comments

Anthropic tells investors annualized revenue run rate climbed to $65B in July

https://www.cnbc.com/2026/08/17/anthropic-says-annualized-revenue-climbed-to-65-billion-in-july.html
2•victor106•5m ago•0 comments

Where the Compiler Stops

https://blog.bencope.land/where-the-compiler-stops/
1•mooreds•6m ago•0 comments

Instagram Fuente: Instagram HTTPS://share.google/ERvOAXdq1l73mASFG

1•emilialopesfern•6m ago•0 comments

Token-in-token-out RL training with any agent harness, via a proxy gateway

https://castform.com/blog/harbor/
2•kumama•7m ago•0 comments

Show HN: Encrypted Git Remote Server

https://ghostfork.io
1•neerajmurarka•13m ago•0 comments

Archive of Archives

https://archiveofarchives.com/
2•rdmuser•16m ago•1 comments

Why 4K Blu-ray always beats 4K streaming for picture quality

https://www.engadget.com/2237552/why-4k-blu-ray-better-quality-than-streaming/
3•bookofjoe•18m ago•2 comments

Talk – a public live text stream with no message history

https://talk.sekura.world
2•atakz•18m ago•1 comments

Why I still hand write my commit messages

https://www.jvt.me/posts/2026/08/17/hand-write-commits/
2•ingve•20m ago•0 comments

Oracles Safra Catz brags about "profoundly scary technology" deployed in Gaza

https://www.facebook.com/reel/2050714172471863/
2•DinoPing•20m ago•0 comments

I'll Never Get Y'all to Read the Bible, Will I?

https://www.sympatheticopposition.com/p/ill-never-get-yall-to-read-the-bible
2•goekjclo•22m ago•1 comments

AI systems out-persuade expert humans

https://arxiv.org/abs/2606.16475
1•goekjclo•24m ago•0 comments

The future is robotics (data)

https://www.giete.ma/blog/robotics
3•gietema•25m ago•0 comments

The Law of Stretched [Cognitive] Systems (2022)

https://ferd.ca/the-law-of-stretched-cognitive-systems.html
2•mooreds•26m ago•0 comments

How do functions like alloca allocate memory from the stack?

https://devblogs.microsoft.com/oldnewthing/20260817-40/?p=112617
1•ingve•27m ago•0 comments

Show HN: Solo – portable Linux binaries, solved

https://github.com/pg83/solo
2•pshirshov•28m ago•0 comments

Book the Train, Not the Delay

https://delaybahn.com/
1•pppone•28m ago•0 comments

Show HN: Personal AI tutor that builds and probes your understanding

https://github.com/grandimam/suki
1•grandimam•28m ago•0 comments

GPT-5.6 Sol Pricing Cut by 50%

https://openrouter.ai/openai/gpt-5.6-sol
1•Topfi•30m ago•0 comments

Alternatives to Open Source Software Tainted by AI

https://codeberg.org/ethical-foss/open-slopware
3•colesantiago•30m ago•1 comments

Show HN: Provenance, a daily game about art theft

https://provenance.avibagla.com/
1•avibagla1•30m ago•0 comments

Understanding a Law Firm Through Study

https://engram.com/blog/legal-agents-with-memory
1•jxmorris12•31m ago•0 comments

Police Report 911 Service Number Is Non Operational

https://www.hawaiipolice.gov/police-report-911-service-number-is-non-operational/
1•pudgywalsh•32m ago•0 comments

Show HN: Klar, a simple and opinionated programming language

https://github.com/ProCode-Software/klar
1•ProCodeSoftware•33m ago•0 comments

Evaluating AI Agents as Products

https://www.marble.onl/posts/evaluating_ai_product_quality.html
1•amarble•35m 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.