frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Thundermail Email Hosting

https://tb.pro/en-US/
1•sp8•5m ago•0 comments

A free gross-to-net salary calculator for Italy (RAL to netto)

https://calcolonettostipendio.com/
1•addamsrock•6m ago•0 comments

Rumor: P equals NP and OpenAI was the lab that solved it

https://twitter.com/imjustnewatai/status/2124999308298567840
1•aleph_minus_one•6m ago•0 comments

Show HN: Redact personal data in documents with consistent labels

https://github.com/francescor/oscura-atti
1•oriettaxx•6m ago•0 comments

Put note names on PDF/image sheet music

https://scoretagger.com/
1•nspen•7m ago•1 comments

Qualiaphobic Artificial Neural Networks

https://bicamerallabs.org/qualiaphobia/
1•gmays•11m ago•0 comments

P vs. NP: First blood [video]

https://www.youtube.com/watch?v=RPGa7u-Syo0
2•amichail•12m ago•0 comments

A shallow dive into open-source chip design

https://vitalik.eth.limo/general/2026/11/26/a_shallow_dive_into_open-source_chip_design.html
1•fbrusch•13m ago•0 comments

The Navy Waves Goodbye to the Peacoat

https://www.nytimes.com/2026/11/24/style/us-navy-pea-coat-retired.html
2•osnium123•17m ago•2 comments

Show HN: A CLI that measures whether AI answers cite your site

https://github.com/routeflags/ai-citation-monitor
1•smapira•18m ago•0 comments

Multimodal decision models and expensive piles of PDFs

https://antfly.io/team/rowan/lab/multimodal-decision-models-and-very-expensive-piles-of-pdfs
1•dovin•19m ago•0 comments

First time AI employee presents PPTX on call [video]

https://www.youtube.com/watch?v=Ch5qycwmjUE
1•phegler•25m ago•0 comments

Show HN: I built an anonymous real time status generator for anything?

https://statusmeter.web.app/
2•sturza•27m ago•0 comments

Literal Hacker News: Hackers breach Pentagon

https://www.theguardian.com/technology/2026/nov/27/hackers-breach-us-air-force-cloud-computing
4•illidan1000•29m ago•1 comments

CTronik Synapse Gateway– Open-source agentic gateway and secure MFT protocol.)

https://github.com/ctronikstudio-74/SynapseGateway
1•ivanrovano•30m ago•0 comments

'Everybody Is Going to Be Made Obsolete'

https://www.chronicle.com/article/everybody-is-going-to-be-made-obsolete
3•cainxinth•34m ago•0 comments

It's not The Incentives–it's you

https://talyarkoni.org/blog/2018/10/02/no-its-not-the-incentives-its-you/
1•laurenth•34m ago•0 comments

America needs to slash red tape and build

https://economist.com/leaders/2026/11/26/america-needs-to-slash-red-tape-and-build
1•andsoitis•34m ago•0 comments

Fontra Hive: hosting, history, branches and review for type designers

https://fontrahive.com/
1•zahrevsky•35m ago•0 comments

China could use robot dogs to guard its lunar bases, study suggests

https://www.independent.co.uk/space/china-robot-dogs-moon-lunar-base-b3030293.html
1•nephihaha•37m ago•1 comments

What If We Told You She's a Mastermind? A Tale of Pop Stardom

https://www.vanityfair.com/story/the-mastermind
1•ravenical•37m ago•0 comments

Source Control from Hell

https://frantic.im/git/
12•emschwartz•40m ago•3 comments

Ask HN: Do posts with a big amount of comments crash for you too?

3•Lithuanian•41m ago•0 comments

My Approach to Alt Text (2024)

http://adrianroselli.com/2024/05/my-approach-to-alt-text.html
2•todsacerdoti•42m ago•0 comments

Show HN: I ran an LLM written in F# on a Commodore 64 [video]

https://www.youtube.com/watch?v=2zufRUcZeuc
2•reverseblade2•43m ago•0 comments

Show HN: Create Immersive Audiobooks

https://warblize.com/
2•bloodmoon•45m ago•0 comments

We are all Product Engineers now

https://seldo.com/posts/we-are-all-product-engineers-now/
1•fagnerbrack•46m ago•0 comments

Colorado Would Like You to Know Your Credit Card Is Fine

https://www.xeebot.com/article.php?a=colorado-would-like-you-to-know-your-credit-card-is-fine
1•DASD•46m ago•0 comments

Future of INN / Stepping back from its maintenance

https://lists.isc.org/pipermail/inn-workers/2026-November/019564.html
1•gslin•48m ago•0 comments

EU leaders fail to break $1.7T budget deadlock

https://www.cnbc.com/2026/11/27/eu-budget-2028-2034-deadlock.html
1•Betelbuddy•50m 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.