frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Bun rewrite and FLT formalization had nearly identical resource usage

2•Zsfe510asG•1m ago•1 comments

Show HN: Raw Screen Recordings into Cinematic Apple-Style Product Demos

https://isolate.video/
3•vignesh_warar•1m ago•0 comments

YC Demo Day This Thursday

https://www.neweconomies.co/p/y-combinator-summer-26-batch
1•ollieforsyth•3m ago•0 comments

Russia opens first road bridge with North Korea

https://www.dw.com/en/russia-opens-first-road-bridge-with-north-korea/a-79142595
1•everybodyknows•4m ago•0 comments

Can the U.S. afford a major war? Not with this deficit

https://www.washingtonpost.com/opinions/interactive/2026/09/07/deficit-is-biggest-threat-us-natio...
1•moat•5m ago•1 comments

Show HN: Isle – managed application environments for computer-use agents

https://www.tryisle.com
3•sxhivs•7m ago•1 comments

Show HN: Security and JSON tools that run in the browser

https://sentrint.com/tools
3•xEcho•7m ago•0 comments

The Download: the hunt for underground hydrogen and more rogue OpenAI agents

https://www.technologyreview.com/2026/09/07/1143592/the-download-underground-hydrogen-search-rogu...
2•joozio•8m ago•0 comments

Root cause analysis of the Liquid network split and 3,998.67 BTC peg-out theft

https://gist.github.com/1440000bytes/211ac92dd4433bb1a2e674bf0ff7db2e
2•binyu•9m ago•0 comments

Can AI Replace a Nevada Brothel Sex Worker?

https://brothelnevada.com/2026/09/05/ai-replace-sex-workers/
1•Teever•10m ago•0 comments

PostgreSQL 19 Interactive Tour

https://victoriametrics.com/blog/postgres-19/index.html
3•valyala•10m ago•0 comments

Bitcoin sidechain Liquid hacked for ~4k BTC

https://nehanarula.org/2026/09/07/liquid-hack.html
4•nehan•11m ago•1 comments

$70 Open Source Brain-Computer Interface Octopus 16 by PiEEG

https://www.indiegogo.com/en/projects/pieeg/pieeg_octopus
1•Christiangmer•12m ago•0 comments

Show HN: Mystra – a monitor that signs up and reaches checkout on your app

https://mystra.run
1•danik7x•13m ago•0 comments

Show HN: Gote – a CLI note-taking management tool for plain Markdown

3•banorton•13m ago•0 comments

LHC magnets run at 1.9 K, below the superfluid helium lambda point

https://scienceshot.com/post/lhc-colder-than-outer-space
1•major_stef•15m ago•0 comments

Ask HN: Which is better for backend? JavaScript or Python?

2•skwasimin•17m ago•1 comments

Is HTTP Basic Auth Broken in Chromium?

4•majorchord•19m ago•0 comments

"Bruh", "Cooked", etc. make it easier for ads to track you

2•DidYouKnowThat•20m ago•0 comments

Sen. Kennedy rails against AI developers as 'high IQ stupid people'

https://www.politico.com/news/2026/09/06/kennedy-ai-developers-high-iq-stupid-people-01066756
2•1vuio0pswjnm7•22m ago•0 comments

Risks Digest – April 2026, the final issue

https://catless.ncl.ac.uk/risks/34/91
1•everybodyknows•24m ago•1 comments

Show HN: Hound Media Server – Media Server Alternative to Plex+Stremio

https://github.com/Hound-Media-Server/hound
1•nearbyyak•24m ago•0 comments

Why India Baffles China

https://economist.com/asia/2026/09/06/why-india-baffles-china
4•andsoitis•24m ago•0 comments

Show HN: Wg-admin – web UI for an existing WireGuard host

https://github.com/logimaxx/wg-admin
4•vsergione•25m ago•2 comments

Beautiful Messaging at Scale

https://www.vestaboard.com/note-array
1•andsoitis•27m ago•0 comments

Show HN: Try real Omarchy Linux in your browser, on Cloudflare Containers

https://tryomarchy.dev/
4•emirb•28m ago•1 comments

Tell HN: OpenAI brings back 5 hour limit for plus and business standard users

13•spwa4•28m ago•3 comments

Why front ends fail when you approach them like a back end

https://marijkeluttekes.dev/blog/articles/2026/03/16/why-frontends-fail-when-you-approach-them-li...
1•birdculture•29m ago•0 comments

Show HN: A DIY pure sine-wave solar inverter I built from scratch

https://www.mch170.com/projects/mcinv
4•MCH170•29m ago•0 comments

Rttx – a tiling terminal for GNOME first stable release

https://github.com/IllyaYalovyy/rttx
1•zero-ground-445•29m 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.