frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Situation Monitor

https://hipcityreg.github.io/situation-monitor/
1•mellosouls•3m ago•0 comments

DOJ sues California cities over natural gas bans

https://www.justice.gov/opa/pr/justice-department-sues-california-cities-over-natural-gas-bans
2•737min•4m ago•0 comments

Show HN: Ma'at – Court-defensible jury analysis platform (open source)

https://github.com/Jennaleighwilder/MA-AT
1•jennaleighwest•7m ago•0 comments

Show HN: I built Sonars in 3 weeks to see if AI coding is useful for my company

https://sonars.dev
1•JasperBekkers•9m ago•0 comments

I Built a 1 Petabyte Server from Scratch [video]

https://www.youtube.com/watch?v=vVI7atoAeoo
1•guiambros•12m ago•0 comments

Local Food for the Hudson Valley

https://www.communityfoodworks.org
1•mooreds•16m ago•0 comments

True Scale of Solar System

2•Sarakuzoi•19m ago•0 comments

Asahi Linux – Porting Linux to Apple Silicon [video]

https://media.ccc.de/v/39c3-asahi-linux-porting-linux-to-apple-silicon
1•tensegrist•21m ago•1 comments

An open spec for cryptographic API authentication

https://github.com/atf-open-standard/atf-specification
1•nagabandaru•24m ago•1 comments

Remote Code Execution in OpenCode, update now

https://cy.md/opencode-rce/
4•CyberShadow•29m ago•1 comments

Google introduces personalised shopping ads to AI tools

https://www.ft.com/content/957c7438-b2e0-4605-a276-caa8a7ec363c
1•sebastian_z•32m ago•0 comments

Show HN: Turntiles, an NYT style game I made for my parents

https://wheybags.com/turntiles/
1•wheybags•42m ago•0 comments

I'd tell you a UDP joke…

https://www.codepuns.com/post/805294580859879424/i-would-tell-you-a-udp-joke-but-you-might-not-get
27•redmattred•42m ago•8 comments

Great Chinese Famine

https://en.wikipedia.org/wiki/Great_Chinese_Famine
3•simonebrunozzi•45m ago•2 comments

This game is a single 13 KiB file that runs on Windows, Linux and in the Browser

https://iczelia.net/posts/snake-polyglot/
24•snoofydude•48m ago•10 comments

The Models Resource – Archive of 3D models in video games

https://models.spriters-resource.com/
2•1bpp•53m ago•0 comments

Show HN: Coi – A compiled-reactive language for high-performance WASM apps

1•io_eric•58m ago•0 comments

Show HN: Blockframe v1.0.3 Released

https://github.com/crushr3sist/blockframe-rs/releases/tag/v1.0.3
1•DeusCodex•1h ago•1 comments

The Next Two Years of Software Engineering

https://addyosmani.com/blog/next-two-years/
14•napolux•1h ago•3 comments

iMessage-kit is an iMessage SDK for macOS

https://github.com/photon-hq/imessage-kit
3•rsync•1h ago•1 comments

How I'm Doing at the End of 2025

https://rmondello.com/2025/12/30/how-im-doing-at-the-end-of-2025/
2•gpi•1h ago•0 comments

Show HN: Engineering Schizophrenia: Trusting Yourself Through Byzantine Faults

17•rescrv•1h ago•4 comments

Show HN: Should I Buy It – Paste a link. Answer questions. Get a recommendation

https://shouldibuyit.net
1•samebaker22•1h ago•0 comments

The Cauldron in the Spectrogram Or: What Happens When You Think with Your Tools

https://mcauldronism.substack.com/p/the-cauldron-in-the-spectrogram
2•mcauldronism•1h ago•2 comments

Axioms of Polity

https://colinsteele.org/blog/axioms_of_polity/
1•cvillecsteele•1h ago•0 comments

Show HN: I Built a Mobile Coding App. What I Use It for Surprised Me

https://kibbler.dev/blog/beyond-coding-unexpected-uses-for-kibbler
1•kewun•1h ago•0 comments

Read Sundar Pichai's Remarks at the 2026 National Retail Federation

https://blog.google/company-news/inside-google/message-ceo/nrf-2026-remarks/
2•gmays•1h ago•0 comments

Colorado is looking for range riders to help reduce conflict with wolves

https://www.aspentimes.com/news/colorado-parks-wildlife-range-riding-program/
2•mooreds•1h ago•0 comments

Military Grade

https://en.wikipedia.org/wiki/Military_grade
4•simonebrunozzi•1h ago•2 comments

Influencers and OnlyFans models are dominating O-1 visa requests

https://www.theguardian.com/us-news/2026/jan/11/onlyfans-influencers-us-o-1-visa
7•Teever•1h ago•3 comments
Open in hackernews

Ask HN: Java why put string in a constant?

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