frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Show HN: AI Room Design – Preview interior design styles before you renovate

https://airoommaker.com/
1•linnoe•3m ago•0 comments

How to Make AI Game Music for Any Level: Prompts and Looping

https://www.musegen.ai/blog/ai-game-level-music
1•musegenai01•5m ago•0 comments

Your AI Agent Doesn't Need More Prompts. It Needs Skills

https://medium.com/@faizan711/your-ai-agent-doesnt-need-more-prompts-it-needs-skills-a5e681b8a020
1•Faizan711•8m ago•0 comments

A Record-Breaking Copper Catalyst Converts CO2 into Liquid Fuels (2023)

https://newscenter.lbl.gov/2023/02/16/copper-catalyst-converts-co2-into-liquid-fuels/
1•peter_d_sherman•13m ago•0 comments

Category Theory for Programmers(2017) [pdf]

https://static.latexstudio.net/wp-content/uploads/2017/12/category-theory-for-programmers.pdf
2•o4c•15m ago•0 comments

53k Fukushima nuclear plant workers receive high radiation doses

https://www.japantimes.co.jp/news/2026/08/24/japan/tepco-fukushima-radiation-exposure/
3•toomuchtodo•16m ago•0 comments

Common Lisp: A Gentle Introduction to Symbolic Computation() [pdf]

https://www.cs.cmu.edu/~dst/LispBook/book.pdf
1•o4c•17m ago•0 comments

Sam Altman on Building OpenAI to a Billion Users [video]

https://www.youtube.com/watch?v=kG8AoExkX40
3•tvvocold•18m ago•0 comments

Why is Anthropic's public writing style so unlike Claude's?

https://cmart.blog/claude-writing/
1•zdw•19m ago•0 comments

Newsom makes last-minute push to help California utilities facing wildfire bills

https://calmatters.org/politics/2026/08/newsom-wildfire-utility-liability-package/
1•newsomix9xl•19m ago•1 comments

State paying $625K to settle lawsuit over Braun firing utility commission member

https://indianacapitalchronicle.com/2026/08/22/state-paying-625k-to-settle-lawsuit-over-braun-fir...
1•newsomix9xl•22m ago•1 comments

I run a pizzeria out of my Smart car in NYC [video]

https://www.cnbc.com/2026/08/22/bradley-alvelo-runs-pizza-pod-mobile-pizzeria-smart-car-new-york-...
2•jdnier•26m ago•0 comments

Programming from the Ground Up(2003) [pdf]

https://www.cs.princeton.edu/courses/archive/spr08/cos217/reading/ProgrammingGroundUp-1-0-letters...
1•o4c•27m ago•0 comments

Vim's UserGettingBored Autocmd

https://evanhahn.com/usergettingbored-vim/
1•zdw•29m ago•0 comments

So Long Relayd, and Thanks for All the Fish

https://btxx.org/posts/so-long-relayd/
1•zdw•29m ago•0 comments

You Cannot Grow a Pumpkin

https://taylor.town/pumpkin
3•Curiositry•29m ago•2 comments

Polymarket wallets may have traded on military secrets

https://www.reuters.com/business/finance/more-than-150-polymarket-wallets-may-have-traded-militar...
4•Gaishan•33m ago•1 comments

Fixing an EMachines EL1200 Bios Bug with Claude

https://www.downtowndougbrown.com/2026/08/fixing-an-emachines-el1200-bios-bug-with-claude/
1•zdw•34m ago•0 comments

Shark MX Gameboy Modem

https://forums.nesdev.org/viewtopic.php?t=9520
1•rickcarlino•34m ago•0 comments

A new Task Manager by the old Task Manager guy

http://tmog.org
2•davepl•38m ago•2 comments

'Knees over toes' exercises can help strengthen your knees. Experts explain

https://theconversation.com/influencers-claim-knees-over-toes-exercises-can-help-bullet-proof-you...
2•defrost•43m ago•0 comments

Building trades unions come out in strong support of data-center build-out

https://apnews.com/article/artificial-intelligence-technology-labor-unions-data-centers-64b10b2f9...
3•andsoitis•50m ago•1 comments

Press Conference After Day 1, People of the State of California et al. v. Meta

https://www.youtube.com/watch?v=KWppdXmS9Us
4•1vuio0pswjnm7•54m ago•0 comments

AI one-shots tiny games 'cause it's memorized them. Try one it hasn't seen

4•Marvin_RunAI•1h ago•0 comments

Adding 4 More 2.5GbE Interfaces to the GMKtec Intel N150 NucBox G9

https://catskull.net/adding-4-more-25gbe-interfaces-to-the-gmktec-nucbox-g9.html
1•walterbell•1h ago•0 comments

PFTE Ingestion as Way to Increase Food Volume, Satiety w/o Increasing Calories

https://pmc.ncbi.nlm.nih.gov/articles/PMC4928218/
4•CGMthrowaway•1h ago•3 comments

Why Comfortable People Don't Revolt: Propaganda, Debt, and Control

https://internationalman.com/articles/why-comfortable-people-dont-revolt-propaganda-debt-and-cont...
5•CGMthrowaway•1h ago•0 comments

2012 National Reconnaissance Office space telescope donation to NASA

https://en.wikipedia.org/wiki/2012_National_Reconnaissance_Office_space_telescope_donation_to_NASA
3•toomuchtodo•1h ago•1 comments

Tech leads should have the largest AI exhaust

https://schipper.ai/posts/technical-leaders-should-have-the-largest-ai-exhaust/
2•oliculipolicula•1h ago•2 comments

Neanderthal gene variant may increase muscle mass in people living today today

https://news.ki.se/neanderthal-gene-variant-may-increase-muscle-mass-in-people-living-today-today
3•gmays•1h ago•1 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.