frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Horizontal Volume Control in Apple Music – But Why?

https://iamvishnu.com/posts/horizontal-volume-control-apple-music
1•vishnuharidas•47s ago•0 comments

Show HN: Revolut for International Calls at cheap rates

https://callpronto.app
1•daolm•2m ago•0 comments

The Song of the Western Men

https://www.trelawnysarmy.org/ta/tawestmn.html
1•dash2•3m ago•0 comments

Why some memories last a lifetime while others fade fast

https://www.sciencedaily.com/releases/2025/11/251130050712.htm
1•saikatsg•3m ago•0 comments

New 3D scan reveals a hidden network of moai carvers on Easter Island

https://www.sciencedaily.com/releases/2025/11/251130050717.htm
1•saikatsg•4m ago•0 comments

Türkiye's Kızılelma writes history as it proves air-to-air capability

https://www.dailysabah.com/business/defense/turkiyes-kizilelma-writes-history-as-it-proves-air-to...
1•sahin•6m ago•0 comments

Africa's forests are now emitting more CO2 than they absorb

https://www.newscientist.com/article/2506287-africas-forests-are-now-emitting-more-co2-than-they-...
1•measurablefunc•10m ago•0 comments

It's time to lock in and let your winter arc begin

https://www.bbc.com/news/articles/cm2w79447vvo
3•jethronethro•15m ago•0 comments

Show HN: A fun password strength meter I made for my teenage kids and friends

https://passwordcat.top
2•wstaeblein•17m ago•0 comments

Ultimate Bug Scanner

https://github.com/Dicklesworthstone/ultimate_bug_scanner
1•latchkey•19m ago•0 comments

Norway may break up with Europe's power grid over soaring energy prices

https://www.euractiv.com/news/norway-may-break-up-with-europes-power-grid-over-soaring-energy-pri...
2•toomuchtodo•23m ago•1 comments

Self-Hosting Slides from Sli.dev

https://dev.shetty.me/blog/self-hosting-slides-from-slidev
2•deveesh_shetty•25m ago•0 comments

Ask HN: Are 98% of HN Readers Using AdBlock?

1•7777777phil•25m ago•2 comments

A Global Drive to Curb Social Media for Kids Begins in Australia

https://www.bloomberg.com/news/articles/2025-11-30/australia-s-world-first-social-media-ban-for-u...
2•toomuchtodo•25m ago•1 comments

Revideo: Create Videos with Code

https://github.com/redotvideo/revideo
1•walterbell•28m ago•0 comments

Documentation for Prompts

https://folio.benguzovsky.com/prompt-docs
2•BenGuz•31m ago•0 comments

Yore – Deterministic document indexer for large, agent-driven codebases

http://github.com/rahulrajaram/yore
1•progfan234•31m ago•1 comments

Can You Live a Normal Life in Cyberpunk 2077? [video]

https://www.youtube.com/watch?v=iu5Yfv7fZHk
1•DamnInteresting•35m ago•0 comments

Will Ireland's new alcohol warning labels turn people away from drinking?

https://www.bbc.com/news/articles/c2465lndrnno
3•linhns•37m ago•3 comments

Awesome-distributed-ML – A curated list for distributed [faster] LLM training

https://github.com/Shenggan/awesome-distributed-ml
2•peter_d_sherman•37m ago•0 comments

SRI and Arc: The Dawn of the Information Age

https://www.abortretry.fail/p/sri-and-arc
2•BirAdam•37m ago•0 comments

Should kidfluencers be banned? That's the plan in the EU

https://www.cbc.ca/news/business/eu-kidfluencer-ban-9.6994957
2•saubeidl•39m ago•0 comments

Show HN: We got 30 teens to build a hand made arcade in Tokyo

https://youtu.be/kkbf092Los0
2•devenj•43m ago•0 comments

LumeBiome

https://lumebiome.com/#aff=rayoggg
1•richieg•44m ago•0 comments

Show HN: Turn Any Website into Clean Markdown for LLMs/RAG with SiteOne Crawler

https://github.com/janreges/siteone-crawler
1•janreges•44m ago•0 comments

Stal/IX: declarative statically linked Linux distribution

https://stal-ix.github.io/
1•pshirshov•46m ago•1 comments

Build a Golang App in 10 Seconds Using BuildKit

https://runos.com/blog/build-golang-app-buildkit.html
1•tylerreed•46m ago•1 comments

Tech Resource

https://github.com/deyaa1251/Awesome-tech-resource
1•omenn•46m ago•0 comments

Sundials: SUite of Nonlinear and DIfferential/Algebraic Equation Solver

https://computing.llnl.gov/projects/sundials
1•swydydct•47m ago•0 comments

You Want Microservices, but Do You Need Them?

https://www.docker.com/blog/do-you-really-need-microservices/
11•tsenturk•48m ago•4 comments
Open in hackernews

Ask HN: Java why put string in a constant?

1•ramsicandra•6mo 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•6mo 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•6mo 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.